From 09228dd9f467146a3313652089a81cc45608ea87 Mon Sep 17 00:00:00 2001 From: xins Date: Fri, 29 Mar 2024 10:22:52 +0800 Subject: [PATCH] =?UTF-8?q?1.9.1=20WMS=EF=BC=9APDA=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E7=A7=BB=E5=BA=93=E3=80=81PDA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=8E=B7=E5=8F=96=E7=A7=BB=E5=BA=93=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E3=80=81PDA=E6=8E=A5=E5=8F=A3=E7=A7=BB?= =?UTF-8?q?=E5=BA=93=E5=87=BA=E5=BA=93=E5=92=8CPDA=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=A7=BB=E5=BA=93=E5=85=A5=E5=BA=93=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wms/controller/WmsMobileController.java | 30 +- .../main/java/com/hw/wms/domain/WmsMove.java | 81 +++ .../com/hw/wms/domain/vo/WmsMoveApplyVo.java | 32 + .../java/com/hw/wms/domain/vo/WmsMoveVo.java | 6 +- .../hw/wms/mapper/WmsMoveDetailMapper.java | 7 +- .../java/com/hw/wms/mapper/WmsMoveMapper.java | 20 +- .../com/hw/wms/service/IWmsMoveService.java | 15 +- .../wms/service/impl/WmsMoveServiceImpl.java | 581 +++++++++--------- .../mapper/wms/WmsMoveDetailMapper.xml | 7 +- .../resources/mapper/wms/WmsMoveMapper.xml | 67 +- 10 files changed, 522 insertions(+), 324 deletions(-) create mode 100644 hw-modules/hw-wms/src/main/java/com/hw/wms/domain/vo/WmsMoveApplyVo.java diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsMobileController.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsMobileController.java index e3c2cc4..b0d8959 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsMobileController.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsMobileController.java @@ -118,7 +118,6 @@ public class WmsMobileController extends BaseController { // public AjaxResult getRawOutstockByOutstockId(@PathVariable("rawOutstockId") Long rawOutstockId) { // return success(wmsRawOutstockService.selectWmsRawOutstockByRawOutstockId(rawOutstockId)); // } - @GetMapping(value = "/getRawOutstockByTaskCode/{taskCode}") public AjaxResult getRawOutstockByTaskCode(@PathVariable("taskCode") String taskCode) { return success(wmsRawOutstockService.selectWmsRawOutstockByTaskCode(taskCode)); @@ -409,9 +408,7 @@ public class WmsMobileController extends BaseController { } - - //todo:入库时校验warehousematerial,入库出库需要校验库位状态,是否是移库合库锁定等 - + //todo:入库时校验warehousematerial,入库出库需要校验库位状态,是否是移库合库锁定等 /** @@ -419,8 +416,8 @@ public class WmsMobileController extends BaseController { */ @Log(title = "人工移库", businessType = BusinessType.APPLY) @PostMapping(("/applyMove")) - public AjaxResult applyMove(@Validated @RequestBody WmsMove wmsMove) { - return toAjax(wmsMoveService.applyMove(wmsMove)); + public AjaxResult applyMove(@Validated @RequestBody WmsMoveApplyVo wmsMoveApplyVo) { + return toAjax(wmsMoveService.applyMove(wmsMoveApplyVo)); } /** @@ -431,7 +428,8 @@ public class WmsMobileController extends BaseController { public TableDataInfo getMoveList(WmsMove wmsMove) { startPage(); wmsMove.setMoveWay(WmsConstants.WMS_MOVEMERGE_WAY_MANUAL); - List wmsMoves = wmsMoveService.selectWmsMoveJoinList(wmsMove); + wmsMove.setExecuteStatusStr(WmsConstants.WMS_EXECUTE_STATUS_TOEXECUTE + "," + WmsConstants.WMS_MOVE_EXECUTE_STATUS_EXECUTING); + List wmsMoves = wmsMoveService.selectWmsMoveGroupJoinList(wmsMove); return getDataTable(wmsMoves); } @@ -439,12 +437,12 @@ public class WmsMobileController extends BaseController { * 获取人工移库记明细 */ // @RequiresPermissions("wms:rawoutstock:query") - @GetMapping(value = "/getMoveDetail/{moveId}") - public AjaxResult getMoveDetail(@PathVariable("moveId") Long moveId) { - WmsMoveDetail queryMoveDetail = new WmsMoveDetail(); - queryMoveDetail.setMoveId(moveId); - List wmsMoveDetailList = wmsMoveService.selectWmsMoveDetailJoinList(queryMoveDetail); - return success(wmsMoveDetailList); + @GetMapping(value = "/getMoveDetail/{taskCode}") + public AjaxResult getMoveDetail(@PathVariable("taskCode") String taskCode) { + WmsMove queryMove = new WmsMove(); + queryMove.setTaskCode(taskCode); + List wmsMoveList = wmsMoveService.selectWmsMoveJoinList(queryMove); + return success(wmsMoveList); } @@ -468,10 +466,4 @@ public class WmsMobileController extends BaseController { } - - - - - - } diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsMove.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsMove.java index 91efbd9..a3bef50 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsMove.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsMove.java @@ -1,5 +1,6 @@ package com.hw.wms.domain; +import java.math.BigDecimal; import java.util.List; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; @@ -37,6 +38,26 @@ public class WmsMove extends BaseEntity @Excel(name = "目标库位编码") private String targetLocationCode; + /** 物料批次 */ + @Excel(name = "物料批次") + private String instockBatch; + + /** 物料ID */ + @Excel(name = "物料ID") + private Long materialId; + + /** 计划出库数量 */ + @Excel(name = "计划出库数量") + private BigDecimal planAmount; + + /** 实际出库数量 */ + @Excel(name = "实际出库数量") + private BigDecimal realOutstockAmount; + + /** 计划入库数量 */ + @Excel(name = "计划入库数量") + private BigDecimal realInstockAmount; + /** 操作类型(0自动,1人工,2强制,3调度) */ @Excel(name = "操作类型(0自动,1人工,2强制,3调度)") private String operationType; @@ -100,10 +121,14 @@ public class WmsMove extends BaseEntity private String warehouseName; + private String materialName; /** 移库合库记录明细;原材料入库记录对应的明细信息信息 */ private List wmsMoveDetailList; + /** 执行状态(0待执行,1执行中,2执行完成) 多个以,隔开*/ + private String executeStatusStr; + public void setMoveId(Long moveId) { this.moveId = moveId; @@ -149,6 +174,47 @@ public class WmsMove extends BaseEntity { return targetLocationCode; } + + public String getInstockBatch() { + return instockBatch; + } + + public void setInstockBatch(String instockBatch) { + this.instockBatch = instockBatch; + } + + public Long getMaterialId() { + return materialId; + } + + public void setMaterialId(Long materialId) { + this.materialId = materialId; + } + + public BigDecimal getPlanAmount() { + return planAmount; + } + + public void setPlanAmount(BigDecimal planAmount) { + this.planAmount = planAmount; + } + + public BigDecimal getRealOutstockAmount() { + return realOutstockAmount; + } + + public void setRealOutstockAmount(BigDecimal realOutstockAmount) { + this.realOutstockAmount = realOutstockAmount; + } + + public BigDecimal getRealInstockAmount() { + return realInstockAmount; + } + + public void setRealInstockAmount(BigDecimal realInstockAmount) { + this.realInstockAmount = realInstockAmount; + } + public void setOperationType(String operationType) { this.operationType = operationType; @@ -286,6 +352,13 @@ public class WmsMove extends BaseEntity this.wmsMoveDetailList = wmsMoveDetailList; } + public String getExecuteStatusStr() { + return executeStatusStr; + } + + public void setExecuteStatusStr(String executeStatusStr) { + this.executeStatusStr = executeStatusStr; + } public String getWarehouseName() { return warehouseName; @@ -295,6 +368,14 @@ public class WmsMove extends BaseEntity this.warehouseName = warehouseName; } + public String getMaterialName() { + return materialName; + } + + public void setMaterialName(String materialName) { + this.materialName = materialName; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/vo/WmsMoveApplyVo.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/vo/WmsMoveApplyVo.java new file mode 100644 index 0000000..2ade65f --- /dev/null +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/vo/WmsMoveApplyVo.java @@ -0,0 +1,32 @@ +package com.hw.wms.domain.vo; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; + +/** + * @Description: 申请移库合库VO对象 + * @ClassName: WmsMoveApplyVo + * @Author : xins + * @Date :2024-03-28 14:51 + * @Version :1.0 + */ +@Data +public class WmsMoveApplyVo { + + //仓库ID + @NotNull(message="warehouseId必须输入") + private Long warehouseId; + + @NotBlank(message="原库位编码必须输入") + private String oriLocationCode; + + @NotBlank(message="目标库位编码必须输入") + private String targetLocationCode; + + @NotBlank(message="类型(1移库,2合库)必须输入") + private String moveType; + +} diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/vo/WmsMoveVo.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/vo/WmsMoveVo.java index 984a3ec..116da6d 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/vo/WmsMoveVo.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/vo/WmsMoveVo.java @@ -26,9 +26,9 @@ public class WmsMoveVo { @NotNull(message="数量必须输入") private BigDecimal applyQty; - //数量 - @NotNull(message="moveId必须输入") - private Long moveId; + //任务编号 + @NotBlank(message="taskCode必须输入") + private String taskCode; @NotBlank(message="类型必须输入") private String moveType; diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsMoveDetailMapper.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsMoveDetailMapper.java index 4493c30..75995ac 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsMoveDetailMapper.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsMoveDetailMapper.java @@ -67,11 +67,11 @@ public interface WmsMoveDetailMapper * 查询移库合库记录明细 * * @param moveId 移库合库记录主键 - * @param batchCode 物料批次 + * @param materialBarcode 物料条码 * @return 移库合库记录明细 */ - public WmsMoveDetail selectWmsMoveDetailByMoveIdAndBatchCode(@Param("moveId") Long moveId, - @Param("batchCode") String batchCode); + public WmsMoveDetail selectWmsMoveDetailByMoveIdAndBarCode(@Param("moveId") Long moveId, + @Param("materialBarcode") String materialBarcode); /** @@ -82,4 +82,5 @@ public interface WmsMoveDetailMapper */ public List selectWmsMoveDetailJoinList(WmsMoveDetail wmsMoveDetail); + } diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsMoveMapper.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsMoveMapper.java index f3de53a..9cbfa41 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsMoveMapper.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsMoveMapper.java @@ -91,7 +91,25 @@ public interface WmsMoveMapper /** - * 查询移库合库记录列表,Join warehouse + * 查询移库合库记录列表,group by wm.task_code,wm.warehouse_id,wm.ori_location_code,wm.target_location_code + * + * @param wmsMove 移库合库记录 + * @return 移库合库记录集合 + */ + public List selectWmsMoveGroupJoinList(WmsMove wmsMove); + + + /** + * 批量新增移库合库记录; + * + * @param wmsMoveList 移库合库记录; + * @return 结果 + */ + public int batchWmsMove(List wmsMoveList); + + + /** + * 查询移库合库记录列表,Join material,warehouse * * @param wmsMove 移库合库记录 * @return 移库合库记录集合 diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsMoveService.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsMoveService.java index 5e12c18..49a8d24 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsMoveService.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsMoveService.java @@ -3,6 +3,7 @@ package com.hw.wms.service; import java.util.List; import com.hw.wms.domain.WmsMove; import com.hw.wms.domain.WmsMoveDetail; +import com.hw.wms.domain.vo.WmsMoveApplyVo; import com.hw.wms.domain.vo.WmsMoveVo; /** @@ -72,14 +73,14 @@ public interface IWmsMoveService * @param wmsMove 移库合库记录 * @return 移库合库记录 */ - public List selectWmsMoveJoinList(WmsMove wmsMove); + public List selectWmsMoveGroupJoinList(WmsMove wmsMove); /** * 申请移库 - * @param wmsMove + * @param wmsMoveApplyVo * @return */ - public int applyMove(WmsMove wmsMove); + public int applyMove(WmsMoveApplyVo wmsMoveApplyVo); /** * 获取移库合库记录明细,join material @@ -88,6 +89,13 @@ public interface IWmsMoveService */ public List selectWmsMoveDetailJoinList(WmsMoveDetail wmsMoveDetail); + /** + * 查询移库合库记录列表,Join material + * + * @param wmsMove 移库合库记录 + * @return 移库合库记录集合 + */ + public List selectWmsMoveJoinList(WmsMove wmsMove); /** * 人工移库出库 @@ -102,4 +110,5 @@ public interface IWmsMoveService * @return */ public int moveInstock(WmsMoveVo wmsMoveVo); + } diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsMoveServiceImpl.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsMoveServiceImpl.java index 7ef0b12..ceb28b3 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsMoveServiceImpl.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsMoveServiceImpl.java @@ -14,6 +14,7 @@ import com.hw.common.security.utils.SecurityUtils; import com.hw.mes.api.RemoteMesService; import com.hw.mes.api.domain.MesBaseBarcodeInfo; import com.hw.wms.domain.*; +import com.hw.wms.domain.vo.WmsMoveApplyVo; import com.hw.wms.domain.vo.WmsMoveVo; import com.hw.wms.mapper.*; import org.springframework.beans.factory.annotation.Autowired; @@ -157,28 +158,28 @@ public class WmsMoveServiceImpl implements IWmsMoveService { /** - * 查询移库合库记录列表,Join warehouse + * 查询移库合库记录列表,Join warehouse,group * * @param wmsMove 移库合库记录 * @return 移库合库记录 */ @Override - public List selectWmsMoveJoinList(WmsMove wmsMove) { - return wmsMoveMapper.selectWmsMoveJoinList(wmsMove); + public List selectWmsMoveGroupJoinList(WmsMove wmsMove) { + return wmsMoveMapper.selectWmsMoveGroupJoinList(wmsMove); } /** * 申请移库 * - * @param wmsMove + * @param wmsMoveApplyVo * @return */ @Override @Transactional(rollbackFor = Exception.class) - public int applyMove(WmsMove wmsMove) { - String oriLocationCode = wmsMove.getOriLocationCode(); - String targetLocationCode = wmsMove.getTargetLocationCode(); + public int applyMove(WmsMoveApplyVo wmsMoveApplyVo) { + String oriLocationCode = wmsMoveApplyVo.getOriLocationCode(); + String targetLocationCode = wmsMoveApplyVo.getTargetLocationCode(); if (oriLocationCode.equals(targetLocationCode)) { throw new ServiceException("原库位与目标库位不能相同"); } @@ -207,9 +208,11 @@ public class WmsMoveServiceImpl implements IWmsMoveService { } WmsBaseWarehouse baseWareHouse = wmsBaseWarehouseMapper. - selectWmsBaseWarehouseByWarehouseId(wmsMove.getWarehouseId()); + selectWmsBaseWarehouseByWarehouseId(wmsMoveApplyVo.getWarehouseId()); String warehouseInstockType = baseWareHouse.getWarehouseInstockType(); - List toInsertedMoveDetails = new ArrayList<>(); + List toInsertedMoves = new ArrayList<>(); + Date currentDate = new Date(); + String userName = SecurityUtils.getUsername(); if (warehouseInstockType.equals(WmsConstants.WMS_WAREHOUSE_INSTOCK_TYPE_RAW)) {//如果是原材料 WmsRawStock queryRawStock = new WmsRawStock(); queryRawStock.setLocationCode(oriLocationCode); @@ -232,7 +235,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService { throw new ServiceException("目标库位有库存,不能进行移库"); } - toInsertedMoveDetails = getMoveDetailsByRawStocks(wmsRawStocks); + toInsertedMoves = getMovesByRawStocks(wmsRawStocks, wmsMoveApplyVo, userName, currentDate); } else {//如果是成品 WmsProductStock queryProductStock = new WmsProductStock(); queryProductStock.setLocationCode(oriLocationCode); @@ -255,11 +258,9 @@ public class WmsMoveServiceImpl implements IWmsMoveService { throw new ServiceException("目标库位有库存,不能进行移库"); } - toInsertedMoveDetails = getMoveDetailsByProductStocks(productStocks); + toInsertedMoves = getMovesByProductStocks(productStocks, wmsMoveApplyVo, userName, currentDate); } - Date currentDate = new Date(); - String userName = SecurityUtils.getUsername(); oriLocation.setLocationStatus(WmsConstants.WMS_BASE_LOCATION_STATUS_MOVE_LOCK); oriLocation.setUpdateTime(currentDate); oriLocation.setUpdateBy(userName); @@ -270,47 +271,78 @@ public class WmsMoveServiceImpl implements IWmsMoveService { targetLocation.setUpdateBy(userName); wmsBaseLocationMapper.updateWmsBaseLocation(targetLocation); - wmsMove.setTaskCode(Seq.getId(Seq.wmsMoveSeqType, Seq.wmsMoveSeqCode)); - wmsMove.setOperationType(WmsConstants.WMS_OPERATION_TYPE_MANUAL); - wmsMove.setMoveWay(WmsConstants.WMS_MOVEMERGE_WAY_MANUAL); - wmsMove.setMoveType(WmsConstants.WMS_MOVEMERGE_TYPE_MOVE); - wmsMove.setAuditStatus(WmsConstants.WMS_AUDIT_STATUS_PASS); - wmsMove.setExecuteStatus(WmsConstants.WMS_EXECUTE_STATUS_TOEXECUTE); - wmsMove.setApplyBy(userName); - wmsMove.setApplyDate(currentDate); - int rows = wmsMoveMapper.insertWmsMove(wmsMove); - - batchInsertMoveDetails(toInsertedMoveDetails, wmsMove.getMoveId(), userName, currentDate); + int rows = wmsMoveMapper.batchWmsMove(toInsertedMoves); return rows; } - public List getMoveDetailsByRawStocks(List wmsRawStocks) { - List wmsMoveDetailList = new ArrayList<>(); + private List getMovesByRawStocks(List wmsRawStocks, WmsMoveApplyVo wmsMoveApplyVo, + String userName, Date currentDate) { + List wmsMoveList = new ArrayList<>(); + String taskCode = Seq.getId(Seq.wmsMoveSeqType, Seq.wmsMoveSeqCode); wmsRawStocks.forEach(wmsRawStock -> { - WmsMoveDetail wmsMoveDetail = new WmsMoveDetail(); - wmsMoveDetail.setInstockBatch(wmsRawStock.getInstockBatch()); - wmsMoveDetail.setMaterialId(wmsRawStock.getMaterialId()); - wmsMoveDetail.setPlanAmount(wmsRawStock.getTotalAmount()); - wmsMoveDetail.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_TOEXECUTE); - wmsMoveDetailList.add(wmsMoveDetail); + WmsMove wmsMove = new WmsMove(); + wmsMove.setInstockBatch(wmsRawStock.getInstockBatch()); + wmsMove.setMaterialId(wmsRawStock.getMaterialId()); + wmsMove.setWarehouseId(wmsRawStock.getWarehouseId()); + wmsMove.setOriLocationCode(wmsMoveApplyVo.getOriLocationCode()); + wmsMove.setTargetLocationCode(wmsMoveApplyVo.getTargetLocationCode()); + wmsMove.setPlanAmount(wmsRawStock.getTotalAmount()); + wmsMove.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_TOEXECUTE); + wmsMove.setTaskCode(taskCode); + wmsMove.setOperationType(WmsConstants.WMS_OPERATION_TYPE_MANUAL); + wmsMove.setMoveWay(WmsConstants.WMS_MOVEMERGE_WAY_MANUAL); + wmsMove.setMoveType(wmsMoveApplyVo.getMoveType()); + wmsMove.setAuditStatus(WmsConstants.WMS_AUDIT_STATUS_PASS); + wmsMove.setExecuteStatus(WmsConstants.WMS_EXECUTE_STATUS_TOEXECUTE); + wmsMove.setApplyBy(userName); + wmsMove.setApplyDate(currentDate); + + wmsMoveList.add(wmsMove); }); - return wmsMoveDetailList; + return wmsMoveList; } - public List getMoveDetailsByProductStocks(List wmsProductStocks) { - List wmsMoveDetailList = new ArrayList<>(); + private List getMovesByProductStocks(List wmsProductStocks, WmsMoveApplyVo wmsMoveApplyVo, + String userName, Date currentDate) { + List wmsMoveList = new ArrayList<>(); + String taskCode = Seq.getId(Seq.wmsMoveSeqType, Seq.wmsMoveSeqCode); wmsProductStocks.forEach(wmsProductStock -> { - WmsMoveDetail wmsMoveDetail = new WmsMoveDetail(); - wmsMoveDetail.setInstockBatch(wmsProductStock.getProductBatch()); - wmsMoveDetail.setMaterialId(wmsProductStock.getProductId()); - wmsMoveDetail.setPlanAmount(wmsProductStock.getTotalAmount()); - wmsMoveDetail.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_TOEXECUTE); - wmsMoveDetailList.add(wmsMoveDetail); + WmsMove wmsMove = new WmsMove(); + wmsMove.setInstockBatch(wmsProductStock.getProductBatch()); + wmsMove.setWarehouseId(wmsProductStock.getWarehouseId()); + wmsMove.setOriLocationCode(wmsMoveApplyVo.getOriLocationCode()); + wmsMove.setTargetLocationCode(wmsMoveApplyVo.getTargetLocationCode()); + wmsMove.setMaterialId(wmsProductStock.getProductId()); + wmsMove.setPlanAmount(wmsProductStock.getTotalAmount()); + wmsMove.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_TOEXECUTE); + wmsMove.setTaskCode(taskCode); + wmsMove.setOperationType(WmsConstants.WMS_OPERATION_TYPE_MANUAL); + wmsMove.setMoveWay(WmsConstants.WMS_MOVEMERGE_WAY_MANUAL); + wmsMove.setMoveType(wmsMoveApplyVo.getMoveType()); + wmsMove.setAuditStatus(WmsConstants.WMS_AUDIT_STATUS_PASS); + wmsMove.setExecuteStatus(WmsConstants.WMS_EXECUTE_STATUS_TOEXECUTE); + wmsMove.setApplyBy(userName); + wmsMove.setApplyDate(currentDate); + + wmsMoveList.add(wmsMove); }); - return wmsMoveDetailList; + return wmsMoveList; + } + + + /** + * 查询移库合库记录列表,Join material,warehouse + * + * @param wmsMove 移库合库记录 + * @return 移库合库记录 + */ + @Override + public List selectWmsMoveJoinList(WmsMove wmsMove) { + return wmsMoveMapper.selectWmsMoveJoinList(wmsMove); } + public void batchInsertMoveDetails(List wmsMoveDetailList, Long moveId, String userName, Date currentDate) { wmsMoveDetailList.forEach(moveDetail -> { moveDetail.setMoveId(moveId); @@ -341,7 +373,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService { @Override @Transactional(rollbackFor = Exception.class) public int moveOutstock(WmsMoveVo wmsMoveVo) { - Long moveId = wmsMoveVo.getMoveId(); + String taskCode = wmsMoveVo.getTaskCode(); String materialBarcode = wmsMoveVo.getMaterialBarcode(); String locationCode = wmsMoveVo.getLocationCode(); BigDecimal applyQty = wmsMoveVo.getApplyQty(); @@ -355,6 +387,13 @@ public class WmsMoveServiceImpl implements IWmsMoveService { throw new ServiceException("物料编码有误"); } + String batchFlag = baseBarcodeInfo.getBatchFlag(); + if (!batchFlag.equals(MesConstants.IS_BATCH)) { + if (applyQty.compareTo(BigDecimal.ONE) > 0) { + throw new ServiceException("出库数量需等于1"); + } + } + WmsBaseLocation oriLocation = wmsBaseLocationMapper.selectWmsBaseLocationByLocationCode(locationCode); if (oriLocation == null) { throw new ServiceException("库位编码有误"); @@ -362,74 +401,109 @@ public class WmsMoveServiceImpl implements IWmsMoveService { String userName = SecurityUtils.getUsername(); Date currentDate = new Date(); - - String barcodeType = baseBarcodeInfo.getBarcodeType(); - if (barcodeType.equals(MesConstants.MES_BARCODE_TYPE_RAW)) {//如果是原材料 - moveOutUpdateRawStock(locationCode, baseBarcodeInfo.getBatchCode(), applyQty, userName, currentDate); - } else {//如果是成品 - moveOutUpdateProductStock(locationCode, baseBarcodeInfo.getBatchCode(), applyQty, userName, currentDate); - } - - WmsMoveDetail queryMoveDetail = new WmsMoveDetail(); - queryMoveDetail.setMoveId(moveId); - List wmsMoveDetailList = wmsMoveDetailMapper.selectWmsMoveDetailList(queryMoveDetail); - if (wmsMoveDetailList == null || wmsMoveDetailList.isEmpty()) { + String batchCode = baseBarcodeInfo.getBatchCode(); + + WmsMove queryMove = new WmsMove(); + queryMove.setTaskCode(taskCode); +// queryMove.setInstockBatch(batchCode); + queryMove.setOriLocationCode(locationCode); + List wmsMoveList = wmsMoveMapper.selectWmsMoveList(queryMove); + if (wmsMoveList == null || wmsMoveList.isEmpty()) { throw new ServiceException("没有此移库信息"); } - Map moveDetailMap = wmsMoveDetailList.stream(). - collect(Collectors.toMap(WmsMoveDetail::getInstockBatch, wmsMoveDetail -> wmsMoveDetail)); - - WmsMoveDetail moveDetail = moveDetailMap.get(baseBarcodeInfo.getBatchCode()); - if (moveDetail == null) { + WmsMove wmsMove = wmsMoveList.stream().filter(move -> + move.getInstockBatch().equals(batchCode)).findFirst().get(); + if (wmsMove == null) { throw new ServiceException("没有此移库信息"); } - String executeStatus = moveDetail.getExecuteStatus(); - BigDecimal planAmount = moveDetail.getPlanAmount(); - BigDecimal realAmount = moveDetail.getRealAmount() == null ? BigDecimal.ZERO : moveDetail.getRealAmount(); - BigDecimal remainingAmount = planAmount.subtract(realAmount); + String executeStatus = wmsMove.getExecuteStatus(); if (executeStatus.equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH)) { - throw new ServiceException("已经移库出库完成,无需再出库"); + throw new ServiceException("此批次已移库出库完成,不能再出库"); } - if (executeStatus.equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH)) { - throw new ServiceException("已经移库入库完成,无需再出库"); + throw new ServiceException("此批次已移库入库完成,不能再出库"); } - if (applyQty.compareTo(remainingAmount) > 0) { - throw new ServiceException("数量不能大于" + remainingAmount); + BigDecimal planAmount = wmsMove.getPlanAmount(); + BigDecimal realOutstockAmount = wmsMove.getRealOutstockAmount(); + BigDecimal updateRealOutstockAmount = realOutstockAmount.add(applyQty); + + if (updateRealOutstockAmount.compareTo(planAmount) > 0) { + throw new ServiceException("数量不能大于" + planAmount.subtract(realOutstockAmount)); } - WmsMove wmsMove = wmsMoveMapper.selectWmsMoveByMoveId(moveId); - if(!locationCode.equals(wmsMove.getOriLocationCode())){ - throw new ServiceException("库位错误"); + WmsMoveDetail existedMoveDetail = wmsMoveDetailMapper.selectWmsMoveDetailByMoveIdAndBarCode(wmsMove.getMoveId(), materialBarcode); + if (existedMoveDetail != null) { + throw new ServiceException("此物料条码已经出库,不能重复出库"); } - String moveExecuteStatus = WmsConstants.WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH; - if(moveDetail.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_TOEXECUTE)){ - moveDetail.setExecuteTime(currentDate); - moveDetail.setExecutePerson(userName); + String barcodeType = baseBarcodeInfo.getBarcodeType(); + if (barcodeType.equals(MesConstants.MES_BARCODE_TYPE_RAW)) {//如果是原材料 + moveOutUpdateRawStock(locationCode, batchCode, applyQty, userName, currentDate); + } else {//如果是成品 + moveOutUpdateProductStock(locationCode, batchCode, applyQty, userName, currentDate); } - if (applyQty.compareTo(remainingAmount) < 0) { - moveDetail.setRealAmount(applyQty.subtract(realAmount)); - moveDetail.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_EXECUTING); - } else { - moveDetail.setRealAmount(applyQty.subtract(realAmount)); - moveDetail.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH); + //插入移库合库明细记录 + insertMoveDetail(wmsMove.getMoveId(), baseBarcodeInfo, applyQty, userName, currentDate); - for (WmsMoveDetail wmsMoveDetail : wmsMoveDetailList) { - if (!wmsMoveDetail.getMoveDetailId().equals(moveDetail.getMoveDetailId())) { - if (wmsMoveDetail.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_TOEXECUTE) - || wmsMoveDetail.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_EXECUTING)) { - moveExecuteStatus = WmsConstants.WMS_MOVE_EXECUTE_STATUS_EXECUTING; + //更新移库合库记录,并判断是否解锁库位 + outstockUpdateWmsMove(wmsMove, wmsMoveList, oriLocation, applyQty, userName, currentDate); + + return 1; + } + + + public void insertMoveDetail(Long moveId, MesBaseBarcodeInfo baseBarcodeInfo, BigDecimal applyQty, + String userName, Date currentDate) { + WmsMoveDetail toInsertedWmsMoveDetail = new WmsMoveDetail(); + toInsertedWmsMoveDetail.setMoveId(moveId); + toInsertedWmsMoveDetail.setMaterialBarcode(baseBarcodeInfo.getBarcodeInfo()); + toInsertedWmsMoveDetail.setInstockBatch(baseBarcodeInfo.getBatchCode()); + toInsertedWmsMoveDetail.setMaterialId(baseBarcodeInfo.getMaterialId()); + toInsertedWmsMoveDetail.setPlanAmount(applyQty); + toInsertedWmsMoveDetail.setRealAmount(applyQty); + toInsertedWmsMoveDetail.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH); + toInsertedWmsMoveDetail.setExecutePerson(userName); + toInsertedWmsMoveDetail.setExecuteTime(currentDate); + wmsMoveDetailMapper.insertWmsMoveDetail(toInsertedWmsMoveDetail); + } + + /** + * 在移库出库时更新移库合库记录,判断是否解锁原库位 + * + * @param wmsMove + * @param wmsMoveList + * @param oriLocation + * @param applyQty + * @param userName + * @param currentDate + */ + public void outstockUpdateWmsMove(WmsMove wmsMove, List wmsMoveList, WmsBaseLocation oriLocation, + BigDecimal applyQty, String userName, Date currentDate) { + BigDecimal planAmount = wmsMove.getPlanAmount(); + BigDecimal realOutstockAmount = wmsMove.getRealOutstockAmount(); + BigDecimal remainingAmount = planAmount.subtract(realOutstockAmount); + if (applyQty.compareTo(remainingAmount) < 0) { + wmsMove.setRealOutstockAmount(realOutstockAmount.add(applyQty)); + wmsMove.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_EXECUTING); + } else { + wmsMove.setRealOutstockAmount(planAmount); + wmsMove.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH); + boolean allOustocked = true;//用来判断原库位是否都已出库完成 + for (WmsMove move : wmsMoveList) { + if (!move.getMoveId().equals(wmsMove.getMoveId())) { + if (move.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_TOEXECUTE) + || move.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_EXECUTING)) { + allOustocked = false; } } } - //解锁库位 - if (moveExecuteStatus.equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH)){ + //如果都已出库完成,解锁库位 + if (allOustocked) { oriLocation.setLocationStatus(WmsConstants.WMS_BASE_LOCATION_STATUS_NORMAL); oriLocation.setUpdateBy(userName); oriLocation.setUpdateTime(currentDate); @@ -437,21 +511,15 @@ public class WmsMoveServiceImpl implements IWmsMoveService { } } - - wmsMoveDetailMapper.updateWmsMoveDetail(moveDetail); - - if (!wmsMove.getExecuteStatus().equals(moveExecuteStatus)) { - if (wmsMove.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_TOEXECUTE)) { - wmsMove.setBeginTime(currentDate); - } - wmsMove.setExecuteStatus(moveExecuteStatus); - wmsMoveMapper.updateWmsMove(wmsMove); + if (wmsMove.getBeginTime() == null) { + wmsMove.setBeginTime(currentDate); } - return 1; + wmsMove.setUpdateDate(currentDate); + wmsMove.setUpdateBy(userName); + wmsMoveMapper.updateWmsMove(wmsMove); } - public void moveOutUpdateRawStock(String locationCode, String batchCode, BigDecimal applyQty, String userName, Date currentDate) { WmsRawStock wmsRawStock = wmsRawStockMapper.selectRawStockByLocationAndBatch(locationCode, batchCode); @@ -505,7 +573,6 @@ public class WmsMoveServiceImpl implements IWmsMoveService { wmsProductStock.setUpdateDate(currentDate); wmsProductStockMapper.updateWmsProductStock(wmsProductStock); } - } @@ -516,7 +583,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService { * @return */ public int moveInstock(WmsMoveVo wmsMoveVo) { - Long moveId = wmsMoveVo.getMoveId(); + String taskCode = wmsMoveVo.getTaskCode(); String materialBarcode = wmsMoveVo.getMaterialBarcode(); String locationCode = wmsMoveVo.getLocationCode(); BigDecimal applyQty = wmsMoveVo.getApplyQty(); @@ -530,228 +597,178 @@ public class WmsMoveServiceImpl implements IWmsMoveService { throw new ServiceException("物料编码有误"); } - WmsBaseLocation location = wmsBaseLocationMapper.selectWmsBaseLocationByLocationCode(locationCode); - if (location == null) { + WmsBaseLocation targetLocation = wmsBaseLocationMapper.selectWmsBaseLocationByLocationCode(locationCode); + if (targetLocation == null) { throw new ServiceException("库位编码有误"); } String userName = SecurityUtils.getUsername(); Date currentDate = new Date(); - String barcodeType = baseBarcodeInfo.getBarcodeType(); - String moveExecuteStatus = ""; - + String batchCode = baseBarcodeInfo.getBatchCode(); - WmsMoveDetail queryMoveDetail = new WmsMoveDetail(); - queryMoveDetail.setMoveId(moveId); - List moveDetails = wmsMoveDetailMapper.selectWmsMoveDetailList(queryMoveDetail); - if (moveDetails == null || moveDetails.isEmpty()) { - throw new ServiceException("没有移库出库记录"); + WmsMove queryMove = new WmsMove(); + queryMove.setTaskCode(taskCode); +// queryMove.setInstockBatch(batchCode); + queryMove.setTargetLocationCode(locationCode); + List wmsMoveList = wmsMoveMapper.selectWmsMoveList(queryMove); + if (wmsMoveList == null || wmsMoveList.isEmpty()) { + throw new ServiceException("没有此移库信息"); } - Map moveDetailMap = moveDetails.stream(). - collect(Collectors.toMap(WmsMoveDetail::getMaterialBarcode, wmsMoveDetail -> wmsMoveDetail)); + WmsMove wmsMove = wmsMoveList.stream().filter(move -> + move.getInstockBatch().equals(batchCode)).findFirst().get(); + if (wmsMove == null) { + throw new ServiceException("没有此移库信息"); + } - WmsMoveDetail wmsMoveDetail = moveDetailMap.get(materialBarcode); - if (wmsMoveDetail == null) { - throw new ServiceException("没有移库出库记录"); + String executeStatus = wmsMove.getExecuteStatus(); + if (executeStatus.equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH)) { + throw new ServiceException("此批次已移库入库完成,不能再入库"); } - moveDetailMap.remove(wmsMoveDetail); + BigDecimal planAmount = wmsMove.getPlanAmount(); + BigDecimal realInstockAmount = wmsMove.getRealInstockAmount(); + BigDecimal updateRealInstockAmount = realInstockAmount.add(applyQty); - if (wmsMoveDetail.getPlanAmount().compareTo(applyQty) != 0) { - throw new ServiceException("入库数量需等于" + wmsMoveDetail.getPlanAmount()); + if (updateRealInstockAmount.compareTo(planAmount) > 0) { + throw new ServiceException("数量不能大于" + planAmount.subtract(realInstockAmount)); } + WmsMoveDetail existedMoveDetail = wmsMoveDetailMapper.selectWmsMoveDetailByMoveIdAndBarCode(wmsMove.getMoveId(), materialBarcode); + if (existedMoveDetail == null) { + throw new ServiceException("此物料条码还未移库出库,不能移库入库"); + } + if (existedMoveDetail.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH)) { + throw new ServiceException("此物料条码已移库入库,不能重复入库"); + } + if (!existedMoveDetail.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH)) { + throw new ServiceException("此物料条码还未移库出库,不能移库入库"); + } + if (existedMoveDetail.getRealAmount().compareTo(applyQty) != 0) { + throw new ServiceException("数量需等于" + existedMoveDetail.getRealAmount()); + } + + String barcodeType = baseBarcodeInfo.getBarcodeType(); + //更新库存 if (barcodeType.equals(MesConstants.MES_BARCODE_TYPE_RAW)) {//如果是原材料 -// moveExecuteStatus = moveInUpdateRawStock(Map < String, WmsMoveDetail > moveDetailMap); + moveInUpdateRawStock(targetLocation, baseBarcodeInfo, applyQty, userName, currentDate); } else {//如果是成品 -// moveExecuteStatus = updateProductStock(locationCode, baseBarcodeInfo.getBatchCode(), applyQty, userName, currentDate, location); + moveInUpdateProductStock(targetLocation, baseBarcodeInfo, applyQty, userName, currentDate); } - if (moveExecuteStatus.equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH)) { - WmsMove wmsMove = wmsMoveMapper.selectWmsMoveByMoveId(moveId); - wmsMove.setEndTime(currentDate); - wmsMove.setExecuteStatus(moveExecuteStatus); - wmsMoveMapper.updateWmsMove(wmsMove); - } + //更新移库合库明细记录 + existedMoveDetail.setRealInstockAmount(applyQty); + existedMoveDetail.setExecuteEndTime(currentDate); + existedMoveDetail.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH); + existedMoveDetail.setUpdateDate(currentDate); + existedMoveDetail.setUpdateBy(userName); + existedMoveDetail.setRealInstockAmount(applyQty); + wmsMoveDetailMapper.updateWmsMoveDetail(existedMoveDetail); - wmsMoveDetail.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH); - wmsMoveDetail.setExecuteEndTime(currentDate); - wmsMoveDetail.setUpdateBy(userName); - wmsMoveDetail.setUpdateDate(currentDate); + //更新移库合库记录,并判断是否解锁库位 + instockUpdateWmsMove(wmsMove, wmsMoveList, targetLocation, applyQty, userName, currentDate); - return wmsMoveDetailMapper.updateWmsMoveDetail(wmsMoveDetail); + return 1; } - public String moveInUpdateRawStock(Map moveDetailMap, String locationCode, - MesBaseBarcodeInfo mesBaseBarcodeInfo) { - String moveExecuteStatus = WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH; - //先判断是否已全部出库完成 - if (moveDetailMap != null || !moveDetailMap.isEmpty()) { - for (Map.Entry wmsMoveDetailEntry : moveDetailMap.entrySet()) { - WmsMoveDetail wmsMoveDetail = wmsMoveDetailEntry.getValue(); - if (!wmsMoveDetail.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH)) { -// moveExecuteStatus = WmsConstants. - } - } - } - - + public void moveInUpdateRawStock(WmsBaseLocation location, MesBaseBarcodeInfo mesBaseBarcodeInfo, + BigDecimal applyQty, String userName, Date currentDate) { String batchCode = mesBaseBarcodeInfo.getBatchCode(); + String locationCode = location.getLocationCode(); WmsRawStock rawStock = wmsRawStockMapper.selectRawStockByLocationAndBatch(locationCode, batchCode); if (rawStock != null) { -// rawStock.setTotalAmount(); -// rawStock.setUpdateDate(); -// rawStock.setUpdateBy(); + rawStock.setTotalAmount(rawStock.getTotalAmount().add(applyQty)); + rawStock.setUpdateDate(currentDate); + rawStock.setUpdateBy(userName); wmsRawStockMapper.updateWmsRawStock(rawStock); } else { rawStock = new WmsRawStock(); -// rawStock.setTotalAmount(); -// rawStock.setLocationCode(); -// rawStock.setInstockBatch(); -// rawStock.setWarehouseId(); -// rawStock.setWarehouseFloor(); -// rawStock.setStockType(); -// rawStock.setMaterialId(); -// rawStock.setInstockDate();//条码中的入库时间 -// rawStock.setLastOutstockTime(); + rawStock.setTotalAmount(applyQty); + rawStock.setLocationCode(locationCode); + rawStock.setInstockBatch(mesBaseBarcodeInfo.getBatchCode()); + rawStock.setWarehouseId(location.getWarehouseId()); + rawStock.setWarehouseFloor(location.getWarehouseFloor()); + rawStock.setStockType(WmsConstants.RWA_STOCK_STOCK_TYPE_RAW); + rawStock.setMaterialId(mesBaseBarcodeInfo.getMaterialId()); + rawStock.setInstockDate(mesBaseBarcodeInfo.getAcceptedDate());//条码中的入库时间 + rawStock.setLastOutstockTime(mesBaseBarcodeInfo.getLastOutstockDate()); // rawStock.setQualityStatus(); -// rawStock.setCompleteFlag(); -// rawStock.setCreateDate(); -// rawStock.setCreateBy(); + rawStock.setCompleteFlag(WmsConstants.WMS_RAW_STOCK_COMPLETE_FLAG_YES); + rawStock.setCreateDate(currentDate); + rawStock.setCreateBy(userName); wmsRawStockMapper.insertWmsRawStock(rawStock); } - return moveExecuteStatus; + } + + + public void moveInUpdateProductStock(WmsBaseLocation location, MesBaseBarcodeInfo mesBaseBarcodeInfo, + BigDecimal applyQty, String userName, Date currentDate) { + String materialBarcode = mesBaseBarcodeInfo.getBarcodeInfo(); + String locationCode = location.getLocationCode(); + + WmsProductStock productStock = new WmsProductStock(); + productStock.setTotalAmount(applyQty); + productStock.setLocationCode(locationCode); + productStock.setProductBatch(materialBarcode); + productStock.setWarehouseId(location.getWarehouseId()); + productStock.setWarehouseFloor(location.getWarehouseFloor()); + productStock.setStockType(mesBaseBarcodeInfo.getBarcodeType()); + productStock.setProductId(mesBaseBarcodeInfo.getMaterialId()); + productStock.setInstockDate(mesBaseBarcodeInfo.getAcceptedDate());//条码中的入库时间 + productStock.setPlanCode(mesBaseBarcodeInfo.getPlanCode()); + productStock.setPlanDetailCode(mesBaseBarcodeInfo.getPlanDetailCode()); + productStock.setSaleOrderId(mesBaseBarcodeInfo.getSaleOrderId()); + productStock.setSaleorderCode(mesBaseBarcodeInfo.getSaleorderCode()); +// rawStock.setQualityStatus(); + productStock.setCreateDate(currentDate); + productStock.setCreateBy(userName); + wmsProductStockMapper.insertWmsProductStock(productStock); } /** - * 人工移库出库 + * 在移库入库时更新移库合库记录,判断是否解锁目标库位 * - * @param wmsMoveVo - * @return + * @param wmsMove + * @param wmsMoveList + * @param oriLocation + * @param applyQty + * @param userName + * @param currentDate */ - /* @Override - @Transactional(rollbackFor = Exception.class) - public int moveOutstock(WmsMoveVo wmsMoveVo) { - String materialBarcode = wmsMoveVo.getMaterialBarcode(); - String locationCode = wmsMoveVo.getLocationCode(); - BigDecimal applyQty = wmsMoveVo.getApplyQty(); - if (applyQty.compareTo(BigDecimal.ZERO) <= 0) { - throw new ServiceException("出库数量需大于0"); - } - - R baseBarcodeInfoR = remoteMesService.getBarcode(materialBarcode, SecurityConstants.INNER); - MesBaseBarcodeInfo baseBarcodeInfo = baseBarcodeInfoR.getData(); - if (baseBarcodeInfo == null) { - throw new ServiceException("物料编码有误"); - } - - String batchFlag = baseBarcodeInfo.getBatchFlag(); - if (!batchFlag.equals(MesConstants.IS_BATCH)) { - if (applyQty.compareTo(BigDecimal.ONE) > 0) { - throw new ServiceException("出库数量需等于1"); - } - } - - WmsBaseLocation location = wmsBaseLocationMapper.selectWmsBaseLocationByLocationCode(locationCode); - if (location == null) { - throw new ServiceException("库位编码有误"); - } - - - String userName = SecurityUtils.getUsername(); - Date currentDate = new Date(); - - String barcodeType = baseBarcodeInfo.getBarcodeType(); - if (barcodeType.equals(MesConstants.MES_BARCODE_TYPE_RAW)) {//如果是原材料 - WmsRawStock wmsRawStock = wmsRawStockMapper.selectRawStockByLocationAndBatch(locationCode, baseBarcodeInfo.getBatchCode()); - if (wmsRawStock == null) { - throw new ServiceException("无库存信息"); - } - BigDecimal totalAmount = wmsRawStock.getTotalAmount() == null ? BigDecimal.ZERO : wmsRawStock.getTotalAmount(); - BigDecimal occupyAmount = wmsRawStock.getOccupyAmount() == null ? BigDecimal.ZERO : wmsRawStock.getOccupyAmount(); - BigDecimal frozenAmount = wmsRawStock.getFrozenAmount() == null ? BigDecimal.ZERO : wmsRawStock.getFrozenAmount(); - BigDecimal availableAmount = totalAmount.subtract(occupyAmount).subtract(frozenAmount); - if (applyQty.compareTo(availableAmount) > 0) { - throw new ServiceException("移库出库数量不能大于" + availableAmount); - } - - totalAmount = totalAmount.subtract(applyQty); - if (totalAmount.compareTo(BigDecimal.ZERO) == 0) { - wmsRawStockMapper.deleteWmsRawStockByRawStockId(wmsRawStock.getRawStockId()); - } else { - wmsRawStock.setTotalAmount(totalAmount); - wmsRawStock.setUpdateBy(userName); - wmsRawStock.setUpdateDate(currentDate); - wmsRawStockMapper.updateWmsRawStock(wmsRawStock); + public void instockUpdateWmsMove(WmsMove wmsMove, List wmsMoveList, WmsBaseLocation targetLocation, + BigDecimal applyQty, String userName, Date currentDate) { + BigDecimal planAmount = wmsMove.getPlanAmount(); + BigDecimal realInstockAmount = wmsMove.getRealInstockAmount(); + BigDecimal remainingAmount = planAmount.subtract(realInstockAmount); + if (applyQty.compareTo(remainingAmount) < 0) { + wmsMove.setRealInstockAmount(realInstockAmount.add(applyQty)); + } else { + wmsMove.setRealInstockAmount(planAmount); + wmsMove.setExecuteStatus(WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH); + wmsMove.setEndTime(currentDate); + boolean allInstocked = true;//用来判断原库位是否都已入库完成 + for (WmsMove move : wmsMoveList) { + if (!move.getMoveId().equals(wmsMove.getMoveId())) { + if (!move.getExecuteStatus().equals(WmsConstants.WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH)) { + allInstocked = false; + } + } } - } else {//如果是成品 - WmsProductStock wmsProductStock = wmsProductStockMapper.selectProductStockByBatch(materialBarcode); - if (wmsProductStock == null || !wmsProductStock.getLocationCode().equals(locationCode)) { - throw new ServiceException("无此库存信息"); - } - BigDecimal totalAmount = wmsProductStock.getTotalAmount() == null ? BigDecimal.ZERO : wmsProductStock.getTotalAmount(); - BigDecimal occupyAmount = wmsProductStock.getOccupyAmount() == null ? BigDecimal.ZERO : wmsProductStock.getOccupyAmount(); - BigDecimal frozenAmount = wmsProductStock.getFrozenAmount() == null ? BigDecimal.ZERO : wmsProductStock.getFrozenAmount(); - BigDecimal availableAmount = totalAmount.subtract(occupyAmount).subtract(frozenAmount); - if (applyQty.compareTo(availableAmount) > 0) { - throw new ServiceException("移库出库数量不能大于" + availableAmount); - } - totalAmount = totalAmount.subtract(applyQty); - if (totalAmount.compareTo(BigDecimal.ZERO) == 0) { - wmsProductStockMapper.deleteWmsProductStockByProductStockId(wmsProductStock.getProductStockId()); - } else { - wmsProductStock.setTotalAmount(totalAmount); - wmsProductStock.setUpdateBy(userName); - wmsProductStock.setUpdateDate(currentDate); - wmsProductStockMapper.updateWmsProductStock(wmsProductStock); + //如果都已入库完成,解锁库位 + if (allInstocked) { + targetLocation.setLocationStatus(WmsConstants.WMS_BASE_LOCATION_STATUS_NORMAL); + targetLocation.setUpdateBy(userName); + targetLocation.setUpdateTime(currentDate); + wmsBaseLocationMapper.updateWmsBaseLocation(targetLocation); } } - WmsMoveDetail queryMoveDetail = new WmsMoveDetail(); - queryMoveDetail.setMaterialBarcode(materialBarcode); - queryMoveDetail.setMoveExecuteStatus(WmsConstants.WMS_EXECUTE_STATUS_EXECUTING);//移库合库记录执行状态正在执行中的,对于已完成的可以重复移库合库 - List wmsMoveDetails = wmsMoveDetailMapper.selectWmsMoveDetailList(queryMoveDetail); - if (wmsMoveDetails != null && !wmsMoveDetails.isEmpty()) { - throw new ServiceException("已经有此物料信息的移库记录"); - } - - WmsMove wmsMove = new WmsMove(); - wmsMove.setTaskCode(Seq.getId(Seq.wmsMoveSeqType, Seq.wmsMoveSeqCode)); - wmsMove.setWarehouseId(location.getWarehouseId()); - wmsMove.setOriLocationCode(locationCode); - wmsMove.setOperationType(WmsConstants.WMS_OPERATION_TYPE_MANUAL); - wmsMove.setMoveWay(WmsConstants.WMS_MOVEMERGE_WAY_MANUAL); - wmsMove.setMoveType(WmsConstants.WMS_MOVEMERGE_TYPE_MOVE); - wmsMove.setAuditStatus(WmsConstants.WMS_AUDIT_STATUS_PASS); - wmsMove.setExecuteStatus(WmsConstants.WMS_EXECUTE_STATUS_EXECUTING); - wmsMove.setApplyBy(userName); - wmsMove.setApplyDate(currentDate); - wmsMove.setBeginTime(currentDate); - - wmsMoveMapper.insertWmsMove(wmsMove); - - WmsMoveDetail wmsMoveDetail = new WmsMoveDetail(); - wmsMoveDetail.setMoveId(wmsMove.getMoveId()); - wmsMoveDetail.setLocationCode(locationCode); - wmsMoveDetail.setMaterialBarcode(materialBarcode); - wmsMoveDetail.setInstockBatch(baseBarcodeInfo.getBatchCode()); - wmsMoveDetail.setMaterialId(baseBarcodeInfo.getMaterialId()); - wmsMoveDetail.setPlanAmount(applyQty); - wmsMoveDetail.setRealAmount(applyQty); - wmsMoveDetail.setExecuteStatus(WmsConstants.WMS_EXECUTE_STATUS_FINISH); - wmsMoveDetail.setExecutePerson(userName); - wmsMoveDetail.setExecuteTime(currentDate); - wmsMoveDetail.setMoveDetailType(WmsConstants.WMS_MOVE_DETAIL_TYPE_OUT); - wmsMoveDetail.setCreateBy(userName); - wmsMoveDetail.setCreateDate(currentDate); - - wmsMoveDetailMapper.insertWmsMoveDetail(wmsMoveDetail); - - return 1; - }*/ + wmsMove.setUpdateDate(currentDate); + wmsMove.setUpdateBy(userName); + wmsMoveMapper.updateWmsMove(wmsMove); + } } diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsMoveDetailMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsMoveDetailMapper.xml index d2019e4..9db0cf3 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsMoveDetailMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsMoveDetailMapper.xml @@ -105,6 +105,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" material_id = #{materialId}, plan_amount = #{planAmount}, real_amount = #{realAmount}, + real_instock_amount = #{realInstockAmount}, execute_status = #{executeStatus}, execute_person = #{executePerson}, execute_time = #{executeTime}, @@ -135,9 +136,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - where move_id = #{moveId} and instock_batch = #{instockBatch} + where move_id = #{moveId} and material_barcode = #{materialBarcode} @@ -167,4 +168,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsMoveMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsMoveMapper.xml index 58335f3..f8d1475 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsMoveMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsMoveMapper.xml @@ -10,6 +10,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + @@ -25,7 +30,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + @@ -54,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select move_id, task_code, warehouse_id, ori_location_code, target_location_code, operation_type, move_way, move_type, apply_reason, audit_reason, audit_status, execute_status, apply_by, apply_date, audit_by, audit_date, update_by, update_date, begin_time, end_time from wms_move + select move_id, task_code, warehouse_id, ori_location_code, target_location_code, instock_batch, material_id, plan_amount, real_outstock_amount, real_instock_amount, operation_type, move_way, move_type, apply_reason, audit_reason, audit_status, execute_status, apply_by, apply_date, audit_by, audit_date, update_by, update_date, begin_time, end_time from wms_move @@ -96,6 +103,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" warehouse_id, ori_location_code, target_location_code, + instock_batch, + material_id, + plan_amount, + real_outstock_amount, + real_instock_amount, operation_type, move_way, move_type, @@ -111,12 +123,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update_date, begin_time, end_time, - + #{taskCode}, #{warehouseId}, #{oriLocationCode}, #{targetLocationCode}, + #{instockBatch}, + #{materialId}, + #{planAmount}, + #{realOutstockAmount}, + #{realInstockAmount}, #{operationType}, #{moveWay}, #{moveType}, @@ -132,7 +149,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{updateDate}, #{beginTime}, #{endTime}, - + @@ -142,6 +159,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" warehouse_id = #{warehouseId}, ori_location_code = #{oriLocationCode}, target_location_code = #{targetLocationCode}, + instock_batch = #{instockBatch}, + material_id = #{materialId}, + plan_amount = #{planAmount}, + real_outstock_amount = #{realOutstockAmount}, + real_instock_amount = #{realInstockAmount}, operation_type = #{operationType}, move_way = #{moveWay}, move_type = #{moveType}, @@ -199,18 +221,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select wm.move_id, wm.task_code, wm.warehouse_id, wm.ori_location_code, wm.target_location_code, wm.operation_type, wm.move_way, wm.move_type, - wm.execute_status, wm.apply_by, wm.apply_date, wm.begin_time, wm.end_time, - wbw.warehouse_name - from wms_move wm left join wms_base_warehouse wbw on wm.warehouse_id = wbw.warehouse_id + select wm.move_id, wm.task_code, wm.warehouse_id, wm.ori_location_code, wm.target_location_code, + wm.move_type,wm.instock_batch,wm.plan_amount,wm.real_outstock_amount,wm.real_instock_amount,wm.execute_status, + mbmi.material_name,wbw.warehouse_name + from wms_move wm left join mes_base_material_info mbmi on wm.material_id = mbmi.material_id + left join wms_base_warehouse wbw on wm.warehouse_id = wbw.warehouse_id + + + + + + + insert into wms_move(move_id, task_code, warehouse_id,ori_location_code,target_location_code, instock_batch, material_id, plan_amount,operation_type,move_way,move_type,audit_status, execute_status, apply_by, apply_date) values + + ( #{item.moveId}, #{item.taskCode}, #{item.warehouseId}, #{item.oriLocationCode}, #{item.targetLocationCode}, #{item.instockBatch}, #{item.materialId}, #{item.planAmount}, #{item.operationType}, #{item.moveWay}, #{item.moveType}, #{item.auditStatus}, #{item.executeStatus}, #{item.applyBy}, #{item.applyDate}) + + +