add:物料仓库映射,部装半成品需求单
This commit is contained in:
@@ -18,6 +18,8 @@ import org.nl.wms.ext_manage.service.dto.*;
|
||||
import org.nl.wms.pm_manage.demand.service.IPlatingDemandService;
|
||||
import org.nl.wms.pm_manage.demand.service.IPmDemandPlatingService;
|
||||
import org.nl.wms.pm_manage.demand.service.IPmDemandService;
|
||||
import org.nl.wms.pm_manage.demand.service.IPartDemandService;
|
||||
import org.nl.wms.pm_manage.demand.service.IMaterialWarehouseMappingService;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.PmDemandParam;
|
||||
import org.nl.wms.pm_manage.pmreturn.service.IPmReturnService;
|
||||
import org.nl.wms.pm_manage.pmreturn.service.dao.PmReturn;
|
||||
@@ -61,6 +63,10 @@ public class MesToWmsController {
|
||||
@Autowired
|
||||
private IPmDemandPlatingService iPmDemandPlatingService;
|
||||
@Autowired
|
||||
private IPartDemandService partDemandService;
|
||||
@Autowired
|
||||
private IMaterialWarehouseMappingService materialWarehouseMappingService;
|
||||
@Autowired
|
||||
private IPlatingDemandService platingDemandService;
|
||||
|
||||
@Autowired
|
||||
@@ -161,15 +167,22 @@ public class MesToWmsController {
|
||||
public ResponseEntity mesRequisitionSync(@RequestBody List<PmDemandParam> params) {
|
||||
ArrayList<PmDemandParam> pmDemandParams = new ArrayList<>();
|
||||
ArrayList<PmDemandParam> pmDemandPlatingParams = new ArrayList<>();
|
||||
ArrayList<PmDemandParam> partDemandParams = new ArrayList<>();
|
||||
Map<String, String> warehouseByMaterial = materialWarehouseMappingService.getWarehouseByMaterialCodes(
|
||||
params.stream().map(PmDemandParam::getSkuCode).collect(Collectors.toSet()));
|
||||
for (PmDemandParam param : params) {
|
||||
if (Boolean.TRUE.equals(param.getIsSprayPart())){
|
||||
String warehouseCode = warehouseByMaterial.get(param.getSkuCode());
|
||||
if ("6.005".equals(warehouseCode)) {
|
||||
pmDemandPlatingParams.add(param);
|
||||
}else {
|
||||
} else if ("6.006".equals(warehouseCode)) {
|
||||
partDemandParams.add(param);
|
||||
} else {
|
||||
pmDemandParams.add(param);
|
||||
}
|
||||
}
|
||||
iPmDemandService.batchCreate(pmDemandParams);
|
||||
iPmDemandPlatingService.batchCreate(pmDemandPlatingParams);
|
||||
partDemandService.batchCreate(partDemandParams);
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.nl.wms.pm_manage.demand.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.base.ResponseData;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.wms.pm_manage.demand.service.IMaterialWarehouseMappingService;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.MaterialWarehouseMapping;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/materialWarehouseMapping")
|
||||
public class MaterialWarehouseMappingController {
|
||||
@Resource
|
||||
private IMaterialWarehouseMappingService mappingService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> query(String materialCode, String warehouseCode, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<MaterialWarehouseMapping> wrapper = new LambdaQueryWrapper<MaterialWarehouseMapping>()
|
||||
.like(StringUtils.isNotBlank(materialCode), MaterialWarehouseMapping::getMaterialCode, materialCode)
|
||||
.like(StringUtils.isNotBlank(warehouseCode), MaterialWarehouseMapping::getWarehouseCode, warehouseCode)
|
||||
.orderByDesc(MaterialWarehouseMapping::getUpdateTime);
|
||||
Page<MaterialWarehouseMapping> page = mappingService.page(new Page<>(pageQuery.getPage() + 1, pageQuery.getSize()), wrapper);
|
||||
return ResponseData.build(page);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("保存物料仓库映射")
|
||||
public ResponseEntity<Object> save(@RequestBody MaterialWarehouseMapping mapping) {
|
||||
mappingService.saveOrUpdateMapping(mapping);
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@PostMapping("/loadInventory")
|
||||
@Log("从库存加载物料仓库映射")
|
||||
public ResponseEntity<Object> loadInventory() {
|
||||
return ResponseData.build(java.util.Collections.singletonMap("count", mappingService.loadFromInventory()));
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Log("删除物料仓库映射")
|
||||
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
|
||||
mappingService.removeByIds(Arrays.asList(ids));
|
||||
return ResponseData.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package org.nl.wms.pm_manage.demand.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import org.nl.common.base.ResponseData;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.wms.pm_manage.demand.service.IPartDemandService;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.*;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/partDemand")
|
||||
@SaIgnore
|
||||
public class PartDemandController {
|
||||
|
||||
@Resource
|
||||
private IPartDemandService pmDemandService;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询需求单")
|
||||
public ResponseEntity<Object> queryAll(PmDemandQuery query, PageQuery page) {
|
||||
return ResponseData.build(pmDemandService.queryPage(query, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增需求单")
|
||||
public ResponseEntity<Object> create(@Valid @RequestBody PmDemandParam param) {
|
||||
pmDemandService.create(param);
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改需求单")
|
||||
public ResponseEntity<Object> update(@Valid @RequestBody PmDemandDto param) {
|
||||
pmDemandService.update(param);
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Log("删除需求单")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<Object> delete(@RequestBody String[] ids) {
|
||||
List<String> idList = Arrays.asList(ids);
|
||||
pmDemandService.deleteByIds(idList);
|
||||
return ResponseData.build();
|
||||
}
|
||||
@GetMapping("/queryInventory")
|
||||
@Log("根据需求单查询所有库存信息")
|
||||
public ResponseEntity<List<DemandInventryDto>> queryInventory(String skuCode) {
|
||||
return ResponseData.build(pmDemandService.queryInventory(skuCode), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/allocate")
|
||||
@Log("库存分配")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<Object> allocateInventory(@RequestBody PmDemandDto demand) {
|
||||
pmDemandService.allocateInventory(demand.getId(), demand.getInventoryDis());
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@PostMapping("/batchAllocate")
|
||||
@Log("批量分配仓库")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<Object> batchAllocate(@RequestBody BatchAllocateParam param) {
|
||||
pmDemandService.batchAllocateInventory(param.getIds(), param.getInventoryDis());
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@PostMapping("/push")
|
||||
@Log("需求单下发")
|
||||
public ResponseEntity<Object> push(@RequestBody List<PmDemandDto> pmDemandDtos) {
|
||||
pmDemandService.pushDemand(pmDemandDtos);
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@PutMapping("/issueReturnBill")
|
||||
@Log("强制回传EAS")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<Object> issueReturnBill(@RequestBody Set<String> ids) {
|
||||
pmDemandService.issueReturnBill(ids);
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@PostMapping("/autoAllcation")
|
||||
@Log("自动分配需求单")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<Object> autoAllcation(@RequestBody Set<String> ids) {
|
||||
pmDemandService.autoAllcation(ids);
|
||||
return ResponseData.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.nl.wms.pm_manage.demand.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.MaterialWarehouseMapping;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IMaterialWarehouseMappingService extends IService<MaterialWarehouseMapping> {
|
||||
void saveOrUpdateMapping(MaterialWarehouseMapping mapping);
|
||||
int loadFromInventory();
|
||||
Map<String, String> getWarehouseByMaterialCodes(Collection<String> materialCodes);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.nl.wms.pm_manage.demand.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.PartDemand;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.DemandInventryDto;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.PmDemandDto;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.PmDemandParam;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.PmDemandQuery;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface IPartDemandService extends IService<PartDemand> {
|
||||
|
||||
Page<PmDemandDto> queryPage(PmDemandQuery query, PageQuery pageQuery);
|
||||
|
||||
void create(PmDemandParam param);
|
||||
void batchCreate(List<PmDemandParam> param);
|
||||
|
||||
void update(PmDemandDto param);
|
||||
|
||||
void deleteByIds(List<String> ids);
|
||||
|
||||
/**
|
||||
* 根据需求单查询库存信息
|
||||
* @param skuCode
|
||||
* @return
|
||||
*/
|
||||
List<DemandInventryDto> queryInventory(String skuCode);
|
||||
|
||||
/**
|
||||
* 库存分配
|
||||
* @param id
|
||||
* @param inventoryDis
|
||||
*/
|
||||
void allocateInventory(String id, String inventoryDis);
|
||||
|
||||
/**
|
||||
* 批量分配仓库
|
||||
* @param ids 需求单ID列表
|
||||
* @param inventoryDis 分配仓库JSON
|
||||
*/
|
||||
void batchAllocateInventory(List<String> ids, String inventoryDis);
|
||||
|
||||
/**
|
||||
* 推送需求单
|
||||
* 1.需求单分配出库仓库
|
||||
* 2。如果分配给中鼎则直接将需求单推送给中鼎WMS,如果有这边出库则在WMS上生成出库单,有操作人点击自动分配,分配库存
|
||||
* 3。一个物料可能存在多个仓库,如果是平库则不生成AGV任务,如果是高架库则分配完自动生成AGV任务
|
||||
* 4。当前
|
||||
* @param pmDemandDto
|
||||
*/
|
||||
void pushDemand(List<PmDemandDto> pmDemandDto);
|
||||
void issueReturnBill(Set<String> ids);
|
||||
void autoAllcation(Set<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.nl.wms.pm_manage.demand.service.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("pm_material_warehouse_mapping")
|
||||
public class MaterialWarehouseMapping {
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("material_code")
|
||||
private String materialCode;
|
||||
|
||||
@TableField("warehouse_code")
|
||||
private String warehouseCode;
|
||||
|
||||
@TableField("create_time")
|
||||
private String createTime;
|
||||
|
||||
@TableField("update_time")
|
||||
private String updateTime;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.nl.wms.pm_manage.demand.service.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("pm_part_demand")
|
||||
public class PartDemand extends Model<PartDemand> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.INPUT)
|
||||
private String id;
|
||||
|
||||
private String creator;
|
||||
|
||||
@TableField("create_time")
|
||||
private String create_time;
|
||||
|
||||
private Integer priority;
|
||||
|
||||
private String status;
|
||||
private String seq_no;
|
||||
|
||||
@TableField("work_order")
|
||||
private String work_order;
|
||||
|
||||
@TableField("work_order_code")
|
||||
private String work_order_code;
|
||||
|
||||
@TableField("sku_code")
|
||||
private String sku_code;
|
||||
|
||||
@TableField("sku_name")
|
||||
private String sku_name;
|
||||
|
||||
private BigDecimal qty;
|
||||
private BigDecimal assign_qty;
|
||||
|
||||
private String unit;
|
||||
|
||||
@TableField("target_area")
|
||||
private String target_area;
|
||||
|
||||
@TableField("target_house_code")
|
||||
private String target_house_code;
|
||||
|
||||
@TableField("carrier_type")
|
||||
private String carrier_type;
|
||||
|
||||
@TableField("production_line")
|
||||
private String production_line;
|
||||
|
||||
@TableField("is_deleted")
|
||||
private Integer is_deleted;
|
||||
|
||||
private String sn;
|
||||
|
||||
@TableField("create_at")
|
||||
private String create_at;
|
||||
|
||||
@TableField("inventory_dis")
|
||||
private String inventory_dis;
|
||||
|
||||
private String lk_container;
|
||||
private String max_load;
|
||||
private String warehouse_code;
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.nl.wms.pm_manage.demand.service.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.MaterialWarehouseMapping;
|
||||
|
||||
@Mapper
|
||||
public interface MaterialWarehouseMappingMapper extends BaseMapper<MaterialWarehouseMapping> {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.nl.wms.pm_manage.demand.service.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.PartDemand;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.PmDemandDto;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.PmDemandQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PartDemandMapper extends BaseMapper<PartDemand> {
|
||||
|
||||
List<PmDemandDto> queryPage(@Param("query") PmDemandQuery query);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.wms.pm_manage.demand.service.dao.mapper.PartDemandMapper">
|
||||
|
||||
<resultMap id="DemandDtoMap" type="org.nl.wms.pm_manage.demand.service.dto.PmDemandDto">
|
||||
<result property="id" column="id"/>
|
||||
<result property="creator" column="creator"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="priority" column="priority"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="seqNo" column="seq_no"/>
|
||||
<result property="workOrder" column="work_order"/>
|
||||
<result property="skuCode" column="sku_code"/>
|
||||
<result property="skuName" column="sku_name"/>
|
||||
<result property="qty" column="qty"/>
|
||||
<result property="assignQty" column="assign_qty"/>
|
||||
<result property="unit" column="unit"/>
|
||||
<result property="targetArea" column="target_area"/>
|
||||
<result property="targetHouseCode" column="target_house_code"/>
|
||||
<result property="carrierType" column="carrier_type"/>
|
||||
<result property="isDeleted" column="is_deleted"/>
|
||||
<result property="productionLine" column="production_line"/>
|
||||
<result property="sn" column="sn"/>
|
||||
<result property="createAt" column="create_at"/>
|
||||
<result property="inventoryDis" column="inventory_dis"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="queryPage" resultMap="DemandDtoMap">
|
||||
select d.*,g.qty pkInv
|
||||
from pm_part_demand d
|
||||
left join md_pb_groupplate g on d.sku_code = g.material_code and g.storagevehicle_code = 'VTP0006'
|
||||
where 1 = 1
|
||||
<if test="query.status == 90">
|
||||
and is_deleted = 1
|
||||
</if>
|
||||
<if test="query.status != 90">
|
||||
and is_deleted = 0
|
||||
</if>
|
||||
<if test="query.id != null and query.id != ''">
|
||||
and d.id = #{query.id}
|
||||
</if>
|
||||
<if test="query.creator != null and query.creator != ''">
|
||||
and d.creator like concat('%', #{query.creator}, '%')
|
||||
</if>
|
||||
<if test="query.status != null">
|
||||
and d.status = #{query.status}
|
||||
</if>
|
||||
<if test="query.workOrder != null and query.workOrder != ''">
|
||||
and d.work_order like concat('%', #{query.workOrder}, '%')
|
||||
</if>
|
||||
<if test="query.skuCode != null and query.skuCode != ''">
|
||||
and (d.sku_code like concat('%', #{query.skuCode}, '%') or d.sku_name like concat('%', #{query.skuCode}, '%'))
|
||||
</if>
|
||||
<if test="query.productionLine != null and query.productionLine != ''">
|
||||
and d.production_line like concat('%', #{query.productionLine}, '%')
|
||||
</if>
|
||||
<if test="query.targetArea != null and query.targetArea != ''">
|
||||
and d.target_area like concat('%', #{query.targetArea}, '%')
|
||||
</if>
|
||||
<if test="query.startTime != null and query.startTime != ''">
|
||||
and d.create_time >= #{query.startTime}
|
||||
</if>
|
||||
<if test="query.endTime != null and query.endTime != ''">
|
||||
and d.create_time <= #{query.endTime}
|
||||
</if>
|
||||
order by d.create_time desc,d.work_order,d.priority desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,101 @@
|
||||
package org.nl.wms.pm_manage.demand.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.wms.pm_manage.demand.service.IMaterialWarehouseMappingService;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.MaterialWarehouseMapping;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.mapper.MaterialWarehouseMappingMapper;
|
||||
import org.nl.wms.warehouse_manage.inventory.IStInventoryService;
|
||||
import org.nl.wms.warehouse_manage.inventory.dto.StInventoryDto;
|
||||
import org.nl.wms.warehouse_manage.inventory.dto.StInventoryQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MaterialWarehouseMappingServiceImpl extends ServiceImpl<MaterialWarehouseMappingMapper, MaterialWarehouseMapping>
|
||||
implements IMaterialWarehouseMappingService {
|
||||
|
||||
@Resource
|
||||
private IStInventoryService stInventoryService;
|
||||
|
||||
@Override
|
||||
public void saveOrUpdateMapping(MaterialWarehouseMapping mapping) {
|
||||
String materialCode = StringUtils.trimToNull(mapping.getMaterialCode());
|
||||
String warehouseCode = StringUtils.trimToNull(mapping.getWarehouseCode());
|
||||
if (materialCode == null || warehouseCode == null) {
|
||||
throw new BadRequestException("物料编码和仓库编码不能为空");
|
||||
}
|
||||
MaterialWarehouseMapping existing = getOne(new LambdaQueryWrapper<MaterialWarehouseMapping>()
|
||||
.eq(MaterialWarehouseMapping::getMaterialCode, materialCode));
|
||||
String now = DateUtil.now();
|
||||
if (existing == null) {
|
||||
mapping.setId(null);
|
||||
mapping.setMaterialCode(materialCode);
|
||||
mapping.setWarehouseCode(warehouseCode);
|
||||
mapping.setCreateTime(now);
|
||||
mapping.setUpdateTime(now);
|
||||
save(mapping);
|
||||
return;
|
||||
}
|
||||
existing.setWarehouseCode(warehouseCode);
|
||||
existing.setUpdateTime(now);
|
||||
updateById(existing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int loadFromInventory() {
|
||||
List<StInventoryDto> inventories = stInventoryService.queryInventory(new StInventoryQuery());
|
||||
if (CollectionUtils.isEmpty(inventories)) {
|
||||
return 0;
|
||||
}
|
||||
Set<String> materialCodes = inventories.stream().map(StInventoryDto::getMaterialCode)
|
||||
.filter(StringUtils::isNotBlank).collect(Collectors.toSet());
|
||||
Set<String> exists = materialCodes.isEmpty() ? new HashSet<>() : list(new LambdaQueryWrapper<MaterialWarehouseMapping>()
|
||||
.in(MaterialWarehouseMapping::getMaterialCode, materialCodes)).stream()
|
||||
.map(MaterialWarehouseMapping::getMaterialCode).collect(Collectors.toSet());
|
||||
Map<String, String> firstWarehouseByMaterial = new HashMap<>();
|
||||
for (StInventoryDto inventory : inventories) {
|
||||
String materialCode = StringUtils.trimToNull(inventory.getMaterialCode());
|
||||
// 库存查询页面和需求单分配均使用 storCode 作为仓库编码。
|
||||
String warehouseCode = StringUtils.trimToNull(inventory.getStorCode());
|
||||
if (materialCode != null && warehouseCode != null && !exists.contains(materialCode)) {
|
||||
firstWarehouseByMaterial.putIfAbsent(materialCode, warehouseCode);
|
||||
}
|
||||
}
|
||||
String now = DateUtil.now();
|
||||
List<MaterialWarehouseMapping> mappings = firstWarehouseByMaterial.entrySet().stream().map(item -> {
|
||||
MaterialWarehouseMapping mapping = new MaterialWarehouseMapping();
|
||||
mapping.setMaterialCode(item.getKey());
|
||||
mapping.setWarehouseCode(item.getValue());
|
||||
mapping.setCreateTime(now);
|
||||
mapping.setUpdateTime(now);
|
||||
return mapping;
|
||||
}).collect(Collectors.toList());
|
||||
if (!mappings.isEmpty()) {
|
||||
saveBatch(mappings);
|
||||
}
|
||||
return mappings.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getWarehouseByMaterialCodes(Collection<String> materialCodes) {
|
||||
if (CollectionUtils.isEmpty(materialCodes)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return list(new LambdaQueryWrapper<MaterialWarehouseMapping>().in(MaterialWarehouseMapping::getMaterialCode, materialCodes))
|
||||
.stream().collect(Collectors.toMap(MaterialWarehouseMapping::getMaterialCode, MaterialWarehouseMapping::getWarehouseCode));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,513 @@
|
||||
package org.nl.wms.pm_manage.demand.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
||||
import org.nl.wms.basedata_manage.service.IStructattrService;
|
||||
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||
import org.nl.wms.basedata_manage.service.dao.Structattr;
|
||||
import org.nl.wms.ext_manage.api.MesApi;
|
||||
import org.nl.wms.ext_manage.enums.EXTConstant;
|
||||
import org.nl.wms.ext_manage.service.WmsToZDWmdService;
|
||||
import org.nl.wms.ext_manage.service.dto.ZDInventory;
|
||||
import org.nl.wms.pm_manage.demand.service.IPartDemandService;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.PartDemand;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.mapper.PartDemandMapper;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.DemandInventryDto;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.PmDemandDto;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.PmDemandParam;
|
||||
import org.nl.wms.pm_manage.demand.service.dto.PmDemandQuery;
|
||||
import org.nl.wms.pm_manage.demand.service.enums.DemandStatus;
|
||||
import org.nl.wms.sch_manage.service.ISchBaseRegionService;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBaseRegion;
|
||||
import org.nl.wms.system_manage.service.param.ISysParamService;
|
||||
import org.nl.wms.system_manage.service.param.dao.Param;
|
||||
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.IOutBillService;
|
||||
import org.nl.wms.warehouse_manage.inventory.IStInventoryService;
|
||||
import org.nl.wms.warehouse_manage.inventory.core.enums.InventoryChangeType;
|
||||
import org.nl.wms.warehouse_manage.inventory.core.param.impl.AddInvParam;
|
||||
import org.nl.wms.warehouse_manage.inventory.core.param.impl.InFinishParam;
|
||||
import org.nl.wms.warehouse_manage.inventory.dto.StInventoryDto;
|
||||
import org.nl.wms.warehouse_manage.inventory.dto.StInventoryQuery;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.IPmStockReturnService;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.dao.PmStockReturn;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.enums.StockReturnStatusEnum;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.nl.common.domain.query.PageQuery.trimStringFields;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PartDemandServiceImpl extends ServiceImpl<PartDemandMapper, PartDemand> implements IPartDemandService {
|
||||
@Autowired
|
||||
private IStInventoryService iStInventoryService;
|
||||
@Autowired
|
||||
private WmsToZDWmdService wmsToZDWmdService;
|
||||
@Autowired
|
||||
private IOutBillService iOutBillService;
|
||||
@Autowired
|
||||
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
|
||||
@Autowired
|
||||
private ISysParamService iSysParamService;
|
||||
@Autowired
|
||||
private ISchBaseRegionService iSchBaseRegionService;
|
||||
|
||||
@Autowired
|
||||
private IStructattrService iStructattrService;
|
||||
|
||||
@Autowired
|
||||
private IPmStockReturnService iPmStockReturnService;
|
||||
@Autowired
|
||||
private MesApi mesApi;
|
||||
|
||||
@Override
|
||||
public Page<PmDemandDto> queryPage(PmDemandQuery query, PageQuery pageQuery) {
|
||||
trimStringFields(query);
|
||||
long total = baseMapper.selectCount(new LambdaQueryWrapper<PartDemand>()
|
||||
.eq(query.getStatus() == null || query.getStatus() != 90, PartDemand::getIs_deleted, 0)
|
||||
.eq(query.getStatus() != null && query.getStatus() == 90, PartDemand::getIs_deleted, 1)
|
||||
.like(!StringUtils.isEmpty(query.getProductionLine()), PartDemand::getProduction_line, query.getProductionLine())
|
||||
.like(!StringUtils.isEmpty(query.getTargetArea()), PartDemand::getTarget_area, query.getTargetArea())
|
||||
.le(!StringUtils.isEmpty(query.getEndTime()),PartDemand::getCreate_time, query.getEndTime())
|
||||
.ge(!StringUtils.isEmpty(query.getStartTime()),PartDemand::getCreate_time, query.getStartTime())
|
||||
.eq(Objects.nonNull(query.getStatus()), PartDemand::getStatus, query.getStatus())
|
||||
.like(Objects.nonNull(query.getSkuCode()), PartDemand::getSku_code, query.getSkuCode())
|
||||
.like(Objects.nonNull(query.getWorkOrder()), PartDemand::getWork_order, query.getWorkOrder())
|
||||
);
|
||||
com.github.pagehelper.Page<Object> page = PageHelper.startPage(pageQuery.getPage() + 1, pageQuery.getSize(),false);
|
||||
List<PmDemandDto> records = this.baseMapper.queryPage(query);
|
||||
Page<PmDemandDto> dtoPage = new Page<>(page.getPageNum(), page.getPageSize(), total);
|
||||
dtoPage.setRecords(records);
|
||||
return dtoPage;
|
||||
}
|
||||
@Override
|
||||
public void create(PmDemandParam param) {
|
||||
PartDemand demand = new PartDemand();
|
||||
demand.setId(param.getId());
|
||||
demand.setCreator(param.getCreator());
|
||||
demand.setCreate_time(param.getCreateTime());
|
||||
demand.setPriority(param.getPriority());
|
||||
demand.setStatus(param.getStatus());
|
||||
demand.setSeq_no(param.getSeqNo());
|
||||
demand.setWork_order(param.getWorkOrder());
|
||||
demand.setWork_order_code(param.getWorkOrderCode());
|
||||
demand.setSku_code(param.getSkuCode());
|
||||
demand.setSku_name(param.getSkuName());
|
||||
demand.setQty(param.getQty());
|
||||
demand.setUnit(param.getUnit());
|
||||
demand.setTarget_area(param.getTargetArea());
|
||||
demand.setTarget_house_code(param.getTargetHouseCode());
|
||||
demand.setCarrier_type(param.getCarrierType());
|
||||
demand.setProduction_line(param.getProductionLine());
|
||||
demand.setSn(param.getSn());
|
||||
demand.setIs_deleted(0);
|
||||
demand.setCreate_at(DateUtil.now());
|
||||
demand.setMax_load(param.getMaxLoad());
|
||||
demand.setStatus("01");
|
||||
demand.setInventory_dis("6.006");
|
||||
this.save(demand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchCreate(List<PmDemandParam> param) {
|
||||
final List<String> orders = param.stream()
|
||||
.filter(item-> !Objects.equals(item.getStatus(), "1"))
|
||||
.map(PmDemandParam::getWorkOrder).collect(Collectors.toList());
|
||||
if (!orders.isEmpty()){
|
||||
final int count = this.count(new LambdaQueryWrapper<PartDemand>()
|
||||
.in(PartDemand::getWork_order, orders)
|
||||
.eq(PartDemand::getIs_deleted,0));
|
||||
if (count>0){
|
||||
throw new BadRequestException("MES推送需求单失败,需求单已存在");
|
||||
}
|
||||
}
|
||||
for (PmDemandParam pmDemandParam : param) {
|
||||
if (StringUtils.isEmpty(pmDemandParam.getTargetHouseCode())){
|
||||
throw new BadRequestException("目标库位为空!");
|
||||
}
|
||||
if (Objects.equals(pmDemandParam.getStatus(), "1")){
|
||||
pmDemandParam.setStatus(DemandStatus.CANCEL.getValue());
|
||||
PartDemand demand = new PartDemand();
|
||||
demand.setId(pmDemandParam.getId());
|
||||
demand.setCreator(pmDemandParam.getCreator());
|
||||
demand.setCreate_time(pmDemandParam.getCreateTime());
|
||||
demand.setPriority(pmDemandParam.getPriority());
|
||||
demand.setStatus(pmDemandParam.getStatus());
|
||||
demand.setSeq_no(pmDemandParam.getSeqNo());
|
||||
demand.setWork_order(pmDemandParam.getWorkOrder());
|
||||
demand.setWork_order_code(pmDemandParam.getWorkOrderCode());
|
||||
demand.setSku_code(pmDemandParam.getSkuCode());
|
||||
demand.setSku_name(pmDemandParam.getSkuName());
|
||||
demand.setQty(pmDemandParam.getQty());
|
||||
demand.setUnit(pmDemandParam.getUnit());
|
||||
demand.setTarget_area(pmDemandParam.getTargetArea());
|
||||
demand.setProduction_line(pmDemandParam.getProductionLine());
|
||||
demand.setSn(pmDemandParam.getSn());
|
||||
demand.setMax_load(pmDemandParam.getMaxLoad());
|
||||
demand.setStatus("01");
|
||||
demand.setInventory_dis("6.006");
|
||||
this.updateById(demand);
|
||||
}else{
|
||||
this.create(pmDemandParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void update(PmDemandDto param) {
|
||||
PartDemand dbDemand = this.getById(param.getId());
|
||||
if (dbDemand == null) {
|
||||
throw new BadRequestException("需求单不存在");
|
||||
}
|
||||
PartDemand demand = new PartDemand();
|
||||
demand.setId(param.getId());
|
||||
demand.setCreator(param.getCreator());
|
||||
demand.setCreate_time(param.getCreateTime());
|
||||
demand.setPriority(param.getPriority());
|
||||
demand.setStatus(param.getStatus());
|
||||
demand.setWork_order(param.getWorkOrder());
|
||||
demand.setSku_code(param.getSkuCode());
|
||||
demand.setSku_name(param.getSkuName());
|
||||
demand.setQty(param.getQty());
|
||||
demand.setAssign_qty(param.getAssignQty());
|
||||
demand.setUnit(param.getUnit());
|
||||
demand.setTarget_area(param.getTargetArea());
|
||||
demand.setProduction_line(param.getProductionLine());
|
||||
demand.setSn(param.getSn());
|
||||
demand.setCreate_at(dbDemand.getCreate_at());
|
||||
this.updateById(demand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByIds(List<String> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
final List<PartDemand> pmDemands = this.listByIds(ids);
|
||||
for (PartDemand pmDemand : pmDemands) {
|
||||
if (!pmDemand.getStatus().equals(DemandStatus.CREATE.getValue())
|
||||
&& !pmDemand.getStatus().equals(DemandStatus.DIS.getValue())){
|
||||
throw new BadRequestException("删除失败,已经执行的需求单无法删除");
|
||||
}
|
||||
}
|
||||
for (String id : ids) {
|
||||
mesApi.delMesDemand(id);
|
||||
this.update(new LambdaUpdateWrapper<PartDemand>()
|
||||
.eq(PartDemand::getId,id)
|
||||
.set(PartDemand::getStatus, DemandStatus.CANCEL.getValue())
|
||||
.set(PartDemand::getIs_deleted,1));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void allocateInventory(String id, String inventoryDis) {
|
||||
PartDemand demand = this.getById(id);
|
||||
if (demand == null) {
|
||||
throw new BadRequestException("需求单不存在");
|
||||
}
|
||||
if (Objects.equals(demand.getStatus(), DemandStatus.FINISH.getValue())){
|
||||
throw new BadRequestException("单据已完成不允许分配");
|
||||
}
|
||||
demand.setInventory_dis(inventoryDis);
|
||||
demand.setStatus(DemandStatus.DIS.getValue());
|
||||
this.updateById(demand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchAllocateInventory(List<String> ids, String inventoryDis) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
throw new BadRequestException("请选择需求单");
|
||||
}
|
||||
List<PartDemand> demands = this.listByIds(ids);
|
||||
if (CollectionUtils.isEmpty(demands)) {
|
||||
throw new BadRequestException("需求单不存在");
|
||||
}
|
||||
for (PartDemand demand : demands) {
|
||||
if (!"0".equals(demand.getStatus())) {
|
||||
throw new BadRequestException("仅支持对生成状态的需求单进行批量分配");
|
||||
}
|
||||
}
|
||||
this.update(new LambdaUpdateWrapper<PartDemand>()
|
||||
.set(PartDemand::getInventory_dis, inventoryDis)
|
||||
.set(PartDemand::getStatus, DemandStatus.DIS.getValue())
|
||||
.in(PartDemand::getId, ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DemandInventryDto> queryInventory(String skuCode) {
|
||||
List<DemandInventryDto> resultList = new ArrayList<>();
|
||||
List<StInventoryDto> inventoryDtos = iStInventoryService.queryInventory(StInventoryQuery.builder().materialCode(skuCode).build());
|
||||
if (!CollectionUtils.isEmpty(inventoryDtos)) {
|
||||
for (StInventoryDto dto : inventoryDtos) {
|
||||
DemandInventryDto demandDto = new DemandInventryDto();
|
||||
demandDto.setSkuCode(dto.getMaterialCode());
|
||||
demandDto.setQty(dto.getQty());
|
||||
demandDto.setHouseCode(dto.getStorCode());
|
||||
demandDto.setHouseName(dto.getStorName());
|
||||
resultList.add(demandDto);
|
||||
}
|
||||
}else {
|
||||
DemandInventryDto demandDto = new DemandInventryDto();
|
||||
demandDto.setSkuCode(skuCode);
|
||||
demandDto.setQty(BigDecimal.ZERO);
|
||||
demandDto.setHouseCode("6.011");
|
||||
demandDto.setHouseName("'五期装配原材料平库'");
|
||||
}
|
||||
ResponseEntity<List<ZDInventory>> responseEntity = wmsToZDWmdService.queryInventory(skuCode);
|
||||
List<ZDInventory> zdInventorys = responseEntity.getBody();
|
||||
if (!CollectionUtils.isEmpty(zdInventorys)) {
|
||||
for (ZDInventory item : zdInventorys) {
|
||||
DemandInventryDto demandDto = new DemandInventryDto();
|
||||
demandDto.setSkuCode(item.getSkuCode());
|
||||
demandDto.setSkuName(null);
|
||||
demandDto.setQty(item.getQty());
|
||||
//中鼎库存有映射
|
||||
String houseMapping = WmsToZDWmdService.ZD_LOS_MAPPING.get(item.getHouseCode());
|
||||
if (StringUtils.isEmpty(houseMapping)){
|
||||
throw new BadRequestException("分配失败,当前中鼎仓库编码未配置映射");
|
||||
}
|
||||
demandDto.setHouseCode(houseMapping);
|
||||
demandDto.setHouseName("五期原材料立库6.002");
|
||||
resultList.add(demandDto);
|
||||
}
|
||||
}else {
|
||||
DemandInventryDto demandDto = new DemandInventryDto();
|
||||
demandDto.setSkuCode(skuCode);
|
||||
demandDto.setSkuName(null);
|
||||
demandDto.setQty(BigDecimal.ZERO);
|
||||
demandDto.setHouseCode("6.002");
|
||||
demandDto.setHouseName("五期原材料立库6.002");
|
||||
resultList.add(demandDto);
|
||||
}
|
||||
return resultList.stream().filter(i-> !i.getHouseName().contains("线边库")).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void pushDemand(List<PmDemandDto> pmDemandDtos) {
|
||||
if (CollectionUtils.isEmpty(pmDemandDtos)){
|
||||
throw new BadRequestException("下推失败,请求数据不能为空");
|
||||
}
|
||||
if (pmDemandDtos.stream().anyMatch(i -> !Objects.equals(i.getStatus(), "01"))){
|
||||
throw new BadRequestException("单据不为已分配状态不能下推");
|
||||
}
|
||||
// 一次性分成两组
|
||||
Param zdStorParam = iSysParamService.findByCode(EXTConstant.ZD_STOR_SET);
|
||||
List ZD_STOR_SET;
|
||||
if (zdStorParam!=null){
|
||||
ZD_STOR_SET = JSONObject.parseObject(zdStorParam.getValue(), List.class);
|
||||
} else {
|
||||
ZD_STOR_SET = new ArrayList<>();
|
||||
}
|
||||
Map<Boolean, List<PmDemandDto>> partitioned = pmDemandDtos.stream()
|
||||
.collect(Collectors.partitioningBy(a -> ZD_STOR_SET
|
||||
.contains(a.getInventoryDis())));
|
||||
List<PmDemandDto> zdDemands = partitioned.get(true);
|
||||
List<PmDemandDto> otherDemands = partitioned.get(false);
|
||||
if (!CollectionUtils.isEmpty(otherDemands)) {
|
||||
JSONObject billParam = convertDemandsToBillParam(otherDemands);
|
||||
iOutBillService.saveBill(billParam);
|
||||
this.update(new LambdaUpdateWrapper<PartDemand>()
|
||||
.set(PartDemand::getStatus,DemandStatus.SEND.getValue())
|
||||
.in(PartDemand::getId,otherDemands.stream()
|
||||
.map(PmDemandDto::getId).collect(Collectors.toList())));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(zdDemands)) {
|
||||
Map<String, List<PmDemandDto>> groupByWorkOrder = zdDemands.stream()
|
||||
.collect(Collectors.groupingBy(PmDemandDto::getWorkOrder));
|
||||
//判断是否存在其他工单的数据是则保存
|
||||
for (String workOrder : groupByWorkOrder.keySet()) {
|
||||
final List<PmDemandDto> demandDtos = groupByWorkOrder.get(workOrder);
|
||||
final int orderCount = this.count(new LambdaQueryWrapper<PartDemand>()
|
||||
.eq(PartDemand::getWork_order, workOrder)
|
||||
.in(PartDemand::getInventory_dis, ZD_STOR_SET)
|
||||
.ne(PartDemand::getIs_deleted, 1));
|
||||
if (orderCount > demandDtos.size()){
|
||||
throw new BadRequestException("工单"+workOrder+"下推中鼎失败,存在未勾选的单子");
|
||||
}
|
||||
List<PmDemandDto> zd = new ArrayList<>();
|
||||
List<AddInvParam> addInvParams = new ArrayList<>();
|
||||
List<InFinishParam> inFinishParams = new ArrayList<>();
|
||||
for (PmDemandDto zdDemand : demandDtos) {
|
||||
Structattr structattr = iStructattrService.getOne(new LambdaQueryWrapper<Structattr>()
|
||||
.eq(Structattr::getSect_code, zdDemand.getTargetHouseCode())
|
||||
.isNotNull(Structattr::getStoragevehicle_code)
|
||||
.last("limit 1"));
|
||||
AddInvParam addInvParam = new AddInvParam();
|
||||
addInvParam.setMaterialCode(zdDemand.getSkuCode());
|
||||
addInvParam.setUnitId("1");
|
||||
addInvParam.setUnitName(zdDemand.getUnit());
|
||||
addInvParam.setPcsn("1");
|
||||
addInvParam.setStoragevehicleCode(structattr.getStoragevehicle_code());
|
||||
addInvParam.setQty(zdDemand.getQty());
|
||||
addInvParam.setStorCode(structattr.getStor_code());
|
||||
addInvParam.setSectCode(structattr.getSect_code());
|
||||
addInvParam.setStructCode(structattr.getStruct_code());
|
||||
addInvParam.setRemark("中鼎需求单变动");
|
||||
addInvParams.add(addInvParam);
|
||||
InFinishParam inFinishParam = new InFinishParam();
|
||||
BeanUtils.copyProperties(addInvParam,inFinishParam);
|
||||
inFinishParams.add(inFinishParam);
|
||||
zd.add(zdDemand);
|
||||
}
|
||||
wmsToZDWmdService.syncDemandOrder(zd);
|
||||
try {
|
||||
iStInventoryService.changeInventory(InventoryChangeType.ADD_INV, addInvParams);
|
||||
iStInventoryService.changeInventory(InventoryChangeType.IN_FINISH, inFinishParams);
|
||||
this.update(new LambdaUpdateWrapper<PartDemand>()
|
||||
.set(PartDemand::getStatus,DemandStatus.FINISH.getValue())
|
||||
.in(PartDemand::getId,demandDtos.stream()
|
||||
.map(PmDemandDto::getId).collect(Collectors.toList())));
|
||||
}catch (Exception ex){
|
||||
log.error("回传中鼎成功,WMS库存变动失败"+ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private JSONObject convertDemandsToBillParam(List<PmDemandDto> demands) {
|
||||
if (CollectionUtils.isEmpty(demands)) {
|
||||
throw new BadRequestException("需求单数据为空");
|
||||
}
|
||||
|
||||
PmDemandDto firstDemand = demands.get(0);
|
||||
|
||||
JSONObject billParam = new JSONObject();
|
||||
billParam.put("stor_code", firstDemand.getInventoryDis());
|
||||
billParam.put("biz_date", DateUtil.today());
|
||||
billParam.put("bill_type", IOSEnum.BILL_TYPE.code("库存调拨"));
|
||||
billParam.put("remark", "部装需求单下推生成");
|
||||
|
||||
List<JSONObject> tableData = new ArrayList<>();
|
||||
//查询物料id;
|
||||
final List<MdMeMaterialbase> materialbases = iMdMeMaterialbaseService
|
||||
.list(new LambdaQueryWrapper<MdMeMaterialbase>()
|
||||
.in(MdMeMaterialbase::getMaterial_code,
|
||||
demands.stream().map(PmDemandDto::getSkuCode).collect(Collectors.toList()))
|
||||
.select(MdMeMaterialbase::getQty_unit_id,MdMeMaterialbase::getMaterial_id, MdMeMaterialbase::getMaterial_code));
|
||||
Map<String, MdMeMaterialbase> codeToIdMap = materialbases.stream()
|
||||
.collect(Collectors.toMap(
|
||||
MdMeMaterialbase::getMaterial_code, Function.identity()));
|
||||
for (PmDemandDto demand : demands) {
|
||||
JSONObject detailRow = new JSONObject();
|
||||
detailRow.put("material_code", demand.getSkuCode());
|
||||
MdMeMaterialbase materialbase = codeToIdMap.get(demand.getSkuCode());
|
||||
if (materialbase == null){
|
||||
throw new BadRequestException("下推失败,"+demand.getSkuCode()+"在WMS中不存在");
|
||||
}
|
||||
detailRow.put("material_id", materialbase.getMaterial_id());
|
||||
detailRow.put("qty_unit_name", demand.getUnit());
|
||||
detailRow.put("qty_unit_id", codeToIdMap.get(demand.getSkuCode()).getQty_unit_id());
|
||||
detailRow.put("qty", demand.getQty());
|
||||
detailRow.put("source_bill_code", demand.getId());
|
||||
//走调拨回传
|
||||
detailRow.put("callback_strategy", "DealLLDBBillPartDemandCallBack");
|
||||
detailRow.put("source_bill_type", "需求单");
|
||||
detailRow.put("source_billdtl_id", demand.getId());
|
||||
detailRow.put("source_bill_table", "pm_part_demand");
|
||||
detailRow.put("remark", "关联工单:" + demand.getWorkOrder());
|
||||
detailRow.put("load_port", demand.getTargetArea());
|
||||
detailRow.put("vehicle_type", demand.getCarrierType());
|
||||
tableData.add(detailRow);
|
||||
}
|
||||
billParam.put("tableData", tableData);
|
||||
return billParam;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void issueReturnBill(Set<String> ids) {
|
||||
final List<PartDemand> pmDemands = this.listByIds(ids);
|
||||
if (ObjectUtil.isEmpty(pmDemands)) {
|
||||
throw new BadRequestException("未找到选中的单据");
|
||||
}
|
||||
JSONObject callbackData = new JSONObject();
|
||||
callbackData.put("method", "DealLLDBBill");
|
||||
callbackData.put("type", "WMS");
|
||||
final String uuidBill = UUID.randomUUID().toString();
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("issueStorageOrgUnitNo", "01.09.14"); // 业务状态,可根据实际业务逻辑设置
|
||||
data.put("bizTypeNo", "331"); // 业务日期
|
||||
data.put("receiptStorageOrgUnitNo", "01.09.14"); // 创建人编号,从当前登录用户获取
|
||||
data.put("billNo", uuidBill); // 使用工单编号作为MES单号
|
||||
// 组装明细列表
|
||||
JSONArray entrys = new JSONArray();
|
||||
for (PartDemand pmDemand : pmDemands) {
|
||||
final SchBaseRegion region = iSchBaseRegionService.getOne(new LambdaQueryWrapper<SchBaseRegion>()
|
||||
.eq(SchBaseRegion::getRegion_code, pmDemand.getProduction_line())
|
||||
.select(SchBaseRegion::getPoint_type_explain));
|
||||
if (region==null){
|
||||
throw new BadRequestException("当前产线未配置对应仓库编码getPoint_type_explain");
|
||||
}
|
||||
cn.hutool.json.JSONObject entry = new cn.hutool.json.JSONObject();
|
||||
entry.put("unitNo", "PCS"); // 序号
|
||||
entry.put("qty", pmDemand.getQty()); // 数量
|
||||
entry.put("materialNo", pmDemand.getSku_code()); // 来源单据标识
|
||||
entry.put("issueWarehouseNo", pmDemand.getInventory_dis());
|
||||
entry.put("receiptWarehouseNo", region.getPoint_type_explain());
|
||||
entrys.add(entry);
|
||||
}
|
||||
data.put("entrys", entrys);
|
||||
callbackData.put("data", data);
|
||||
PmStockReturn stockReturn = new PmStockReturn();
|
||||
stockReturn.setRequest_Id(uuidBill);
|
||||
stockReturn.setRequest_type(IOSEnum.BILL_TYPE.code("库存调拨"));
|
||||
stockReturn.setStatus(StockReturnStatusEnum.TODO.getCode()); // 0-处理中
|
||||
stockReturn.setCreate_time(DateUtil.now());
|
||||
stockReturn.setRequest_data(callbackData.toString());
|
||||
iPmStockReturnService.save(stockReturn);
|
||||
this.update(new LambdaUpdateWrapper<PartDemand>()
|
||||
.set(PartDemand::getStatus,DemandStatus.FINISH.getValue())
|
||||
.in(PartDemand::getId,ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoAllcation(Set<String> ids) {
|
||||
final List<PartDemand> pmDemands = this.listByIds(ids);
|
||||
final List<PartDemand> needAllcation = new ArrayList<>();
|
||||
for (PartDemand pmDemand : pmDemands) {
|
||||
if (!pmDemand.getStatus().equals(DemandStatus.CREATE.getValue())){
|
||||
throw new BadRequestException("当前单子"+pmDemand.getWork_order()+"不是生成状态无法勾选");
|
||||
}
|
||||
final List<DemandInventryDto> demandInventryDtos = this.queryInventory(pmDemand.getSku_code());
|
||||
final Map<String, DemandInventryDto> inventryDtoMap = demandInventryDtos.stream().collect(Collectors.toMap(DemandInventryDto::getHouseCode, Function.identity()));
|
||||
final DemandInventryDto demandInventryDto = inventryDtoMap.get("6.002");
|
||||
final DemandInventryDto pInventryDto = inventryDtoMap.get("6.011");
|
||||
if (demandInventryDto !=null && demandInventryDto.getQty()!=null && demandInventryDto.getQty().compareTo(pmDemand.getQty())>=0){
|
||||
pmDemand.setInventory_dis("6.002");
|
||||
pmDemand.setStatus(DemandStatus.DIS.getValue());
|
||||
needAllcation.add(pmDemand);
|
||||
}else if (pInventryDto !=null && pInventryDto.getQty()!=null && pInventryDto.getQty().compareTo(pmDemand.getQty())>=0){
|
||||
pmDemand.setInventory_dis("6.011");
|
||||
pmDemand.setStatus(DemandStatus.DIS.getValue());
|
||||
}else {
|
||||
pmDemand.setInventory_dis("库存不足请手动分配");
|
||||
}
|
||||
needAllcation.add(pmDemand);
|
||||
}
|
||||
this.updateBatchById(needAllcation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package org.nl.wms.warehouse_manage.stockReturn.strategy.core.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.MapOf;
|
||||
import org.nl.wms.basedata_manage.service.IStructattrService;
|
||||
import org.nl.wms.basedata_manage.service.dao.Structattr;
|
||||
import org.nl.wms.ext_manage.api.MesApi;
|
||||
import org.nl.wms.pm_manage.demand.service.IPartDemandService;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.PartDemand;
|
||||
import org.nl.wms.pm_manage.demand.service.enums.DemandStatus;
|
||||
import org.nl.wms.sch_manage.service.ISchBaseRegionService;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBaseRegion;
|
||||
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInv;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInvDtl;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvDisMapper;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvMapper;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dto.IOStorInvDisDto;
|
||||
import org.nl.wms.warehouse_manage.inventory.IStInventoryService;
|
||||
import org.nl.wms.warehouse_manage.inventory.core.enums.InventoryChangeType;
|
||||
import org.nl.wms.warehouse_manage.inventory.core.param.impl.AddInvParam;
|
||||
import org.nl.wms.warehouse_manage.inventory.core.param.impl.InFinishParam;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.IPmStockReturnService;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.dao.PmStockReturn;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.enums.StockReturnStatusEnum;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.strategy.core.CallbackStrategy;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部装需求单库存调拨回传
|
||||
*/
|
||||
@Service(value = "DealLLDBBillPartDemandCallBack")
|
||||
@Slf4j
|
||||
public class DealLLDBBillPartDemandCallBack implements CallbackStrategy {
|
||||
|
||||
@Autowired
|
||||
private IPartDemandService iPmDemandService;
|
||||
@Autowired
|
||||
private IPmStockReturnService iPmStockReturnService;
|
||||
@Resource
|
||||
private IOStorInvDisMapper ioStorInvDisMapper;
|
||||
@Autowired
|
||||
private ISchBaseRegionService iSchBaseRegionService;
|
||||
@Autowired
|
||||
private IStructattrService iStructattrService;
|
||||
@Autowired
|
||||
private IStInventoryService iStInventoryService;
|
||||
@Autowired
|
||||
private IOStorInvMapper ioStorInvMapper;
|
||||
@Autowired
|
||||
private MesApi mesApi;
|
||||
|
||||
@Override
|
||||
public void buildCallback(IOStorInvDtl param) {
|
||||
final String orderCode = param.getSource_bill_code();
|
||||
PartDemand one = iPmDemandService.getOne(new LambdaQueryWrapper<PartDemand>().eq(PartDemand::getId, orderCode));
|
||||
if (one == null){
|
||||
throw new BadRequestException("需求单不存在");
|
||||
}
|
||||
final SchBaseRegion region = iSchBaseRegionService.getOne(new LambdaQueryWrapper<SchBaseRegion>()
|
||||
.eq(SchBaseRegion::getRegion_code, one.getProduction_line())
|
||||
.select(SchBaseRegion::getPoint_type_explain));
|
||||
if (region==null){
|
||||
throw new BadRequestException("当前产线未配置对应仓库编码getPoint_type_explain");
|
||||
}
|
||||
//更新库存,查询托盘
|
||||
final Structattr targetAttr = iStructattrService.getOne(new LambdaQueryWrapper<Structattr>()
|
||||
.eq(Structattr::getSect_code, region.getPoint_type_explain()));
|
||||
if (targetAttr ==null ||StringUtils.isEmpty(targetAttr.getStoragevehicle_code())){
|
||||
throw new BadRequestException("调拨失败,当前调拨目标区域缺少仓库熟悉"+targetAttr.getStruct_code());
|
||||
}
|
||||
final IOStorInv ioStorInv = ioStorInvMapper.selectById(param.getIostorinv_id());
|
||||
|
||||
List<AddInvParam> addInvParams = new ArrayList<>();
|
||||
AddInvParam addParam = new AddInvParam();
|
||||
addParam.setPcsn(StringUtils.isEmpty(param.getPcsn())?"1":param.getPcsn());
|
||||
addParam.setMaterialCode(param.getMaterial_code());
|
||||
addParam.setStoragevehicleCode(targetAttr.getStoragevehicle_code());
|
||||
addParam.setStructCode(targetAttr.getStruct_code());
|
||||
addParam.setSectCode(targetAttr.getSect_code());
|
||||
addParam.setStorCode(targetAttr.getStor_code());
|
||||
addParam.setUnitName(param.getQty_unit_name());
|
||||
addParam.setUnitId(param.getQty_unit_id());
|
||||
addParam.setExtCode(ioStorInv.getBill_code());
|
||||
addParam.setExtType(ioStorInv.getBill_type());
|
||||
addParam.setQty(param.getAssign_qty());
|
||||
addInvParams.add(addParam);
|
||||
iStInventoryService.changeInventory(InventoryChangeType.ADD_INV, addInvParams);
|
||||
final List<InFinishParam> inFinishParams = new ArrayList<>();
|
||||
InFinishParam inFinishParam = new InFinishParam();
|
||||
BeanUtils.copyProperties(addParam,inFinishParam);
|
||||
inFinishParam.setRemark("需求单库存调拨");
|
||||
inFinishParams.add(inFinishParam);
|
||||
iStInventoryService.changeInventory(InventoryChangeType.IN_FINISH, inFinishParams);
|
||||
if (one.getStatus().equals(DemandStatus.FINISH.getValue())){
|
||||
return;
|
||||
}
|
||||
one.setAssign_qty(param.getAssign_qty());
|
||||
if (one.getAssign_qty().intValue()>=one.getQty().intValue()){
|
||||
one.setStatus(DemandStatus.FINISH.getValue());
|
||||
final String now = DateUtil.now();
|
||||
JSONObject callbackData = new JSONObject();
|
||||
callbackData.put("method", "DealLLDBBill");
|
||||
callbackData.put("type", "WMS");
|
||||
// 组装data节点
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("issueStorageOrgUnitNo", "01.09.14"); // 业务状态,可根据实际业务逻辑设置
|
||||
data.put("bizTypeNo", "331"); // 业务日期
|
||||
data.put("receiptStorageOrgUnitNo", "01.09.14"); // 创建人编号,从当前登录用户获取
|
||||
data.put("billNo", param.getIostorinvdtl_id()+"#"+param.getSeq_no()); // 使用工单编号作为MES单号
|
||||
// 组装明细列表
|
||||
JSONArray entrys = new JSONArray();
|
||||
final List<IOStorInvDisDto> disSet = ioStorInvDisMapper.queryOutBillDisDtl(MapOf.of("iostorinvdtl_id", param.getIostorinvdtl_id()));
|
||||
for (IOStorInvDisDto ioStorInvDisDto : disSet) {
|
||||
JSONObject entry = new JSONObject();
|
||||
entry.put("unitNo", "PCS"); // 序号
|
||||
entry.put("qty", ioStorInvDisDto.getPlan_qty()); // 数量
|
||||
entry.put("materialNo", ioStorInvDisDto.getMaterial_code()); // 来源单据标识
|
||||
entry.put("issueWarehouseNo", ioStorInvDisDto.getSect_code());
|
||||
entry.put("receiptWarehouseNo", region.getPoint_type_explain());
|
||||
entrys.add(entry);
|
||||
}
|
||||
data.put("entrys", entrys);
|
||||
callbackData.put("data", data);
|
||||
PmStockReturn stockReturn = new PmStockReturn();
|
||||
stockReturn.setRequest_Id(orderCode);
|
||||
stockReturn.setRequest_Id(ioStorInv.getBill_code());
|
||||
stockReturn.setRequest_type(ioStorInv.getBill_type());
|
||||
stockReturn.setStatus(StockReturnStatusEnum.TODO.getCode()); // 0-处理中
|
||||
stockReturn.setCreate_time(now);
|
||||
stockReturn.setRequest_data(callbackData.toString());
|
||||
//回传MES
|
||||
try {
|
||||
mesApi.pmDemandCallback(Arrays.asList(new MesApi.PmDemandCall(
|
||||
one.getId()
|
||||
,one.getId()
|
||||
,now,one.getTarget_area()
|
||||
,1
|
||||
,disSet.get(0).getStoragevehicle_code(),
|
||||
param.getAssign_qty().toString())));
|
||||
}catch (Exception ex){
|
||||
log.error("DealLLDBBillPmDeamndCallBack#pmDemandCallback error:{}",ex.getMessage());
|
||||
}
|
||||
iPmStockReturnService.save(stockReturn);
|
||||
}
|
||||
this.iPmDemandService.updateById(one);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user