From 01b476b84bad5350cd26009745b1ff38e61cce01 Mon Sep 17 00:00:00 2001 From: "HUOJIN\\92525" Date: Tue, 20 Jan 2026 14:52:49 +0800 Subject: [PATCH] no message --- .../service/processor/BatchProcessor.java | 4 +- .../impl/IConveyorLineServiceImpl.java | 14 +- .../service/processor/AllocateProcessor.java | 157 +++++++++--------- 3 files changed, 85 insertions(+), 90 deletions(-) diff --git a/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/base/service/processor/BatchProcessor.java b/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/base/service/processor/BatchProcessor.java index 8b0528e..3904826 100644 --- a/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/base/service/processor/BatchProcessor.java +++ b/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/base/service/processor/BatchProcessor.java @@ -116,9 +116,7 @@ public class BatchProcessor { * 批量处理分配操作 */ @Transactional(rollbackFor = Exception.class) - public boolean batchAllocate(Map inventoryUpdateMap, Map pickDetailUpdateMap, List createToTask) { - List updateToInventory = new ArrayList<>(inventoryUpdateMap.values()); - List updateToPickDetail = new ArrayList<>(pickDetailUpdateMap.values()); + public boolean batchAllocate(List updateToInventory, List updateToPickDetail, List createToTask) { if (CollectionUtils.isNotEmpty(updateToInventory)) { batchUtil.updateBatchInventory(updateToInventory); } diff --git a/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/conveyorLine/service/impl/IConveyorLineServiceImpl.java b/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/conveyorLine/service/impl/IConveyorLineServiceImpl.java index b51f2bd..7dac4ce 100644 --- a/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/conveyorLine/service/impl/IConveyorLineServiceImpl.java +++ b/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/conveyorLine/service/impl/IConveyorLineServiceImpl.java @@ -78,13 +78,15 @@ public class IConveyorLineServiceImpl implements IConveyorLineService { public void updateResMessageAsn(ScanTrayRequest scanTrayRequest) { ScanTrayData data = scanTrayProcessor.prepareScanTrayData(scanTrayRequest); Asn asn = data.getAsn(); - if (asn != null) { - if (asn.getResMessage().equals("检测成功")) { - return; - } - asn.setResMessage(scanTrayRequest.getContent().getSignal().getErrorReason().toString()); - asnMapper.updateById(asn); + if (asn == null) { + return; } + if ("检测成功".equals(asn.getResMessage())) { + return; + } + + asn.setResMessage(scanTrayRequest.getContent().getSignal().getErrorReason().toString()); + asnMapper.updateById(asn); } @Override diff --git a/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/shipping/service/processor/AllocateProcessor.java b/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/shipping/service/processor/AllocateProcessor.java index be9a5fc..c332dba 100644 --- a/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/shipping/service/processor/AllocateProcessor.java +++ b/cpte-boot-module/cpte-module-wms/src/main/java/org/cpte/modules/shipping/service/processor/AllocateProcessor.java @@ -18,7 +18,6 @@ import org.cpte.modules.conveyorLine.service.processor.ScanTrayProcessor; import org.cpte.modules.conveyorLine.vo.Station; import org.cpte.modules.inventory.entity.Inventory; import org.cpte.modules.inventory.mapper.InventoryMapper; -import org.cpte.modules.inventoryLog.service.IInventoryLogService; import org.cpte.modules.serialNumber.MoveSerialNumberRule; import org.cpte.modules.shipping.entity.Pick; import org.cpte.modules.shipping.entity.PickDetail; @@ -81,9 +80,6 @@ public class AllocateProcessor { @Autowired private ITaskService taskService; - @Autowired - private IInventoryLogService inventoryLogService; - @Autowired private BaseCommonService baseCommonService; @@ -125,19 +121,19 @@ public class AllocateProcessor { } //3.创建数据结构 - Map inventoryUpdateMap = new HashMap<>(); - Map pickDetailUpdateMap = new HashMap<>(); + List updateToInventory = new ArrayList<>(); + List updateToPickDetail = new ArrayList<>(); List createToTask = new ArrayList<>(); List movePoints = new ArrayList<>(); //4.分配 - allocate(data, inventoryUpdateMap, pickDetailUpdateMap, createToTask, movePoints, errorMsgSet); + allocate(data, updateToInventory, updateToPickDetail, createToTask, movePoints, errorMsgSet); //5.生成移位任务 moveTask(createToTask, movePoints); //6.批量操作 - batchProcessor.batchAllocate(inventoryUpdateMap, pickDetailUpdateMap, createToTask); + batchProcessor.batchAllocate(updateToInventory, updateToPickDetail, createToTask); //7.刷新出库单 refreshData(data); @@ -164,19 +160,19 @@ public class AllocateProcessor { } //3.创建数据结构 - Map inventoryUpdateMap = new HashMap<>(); - Map pickDetailUpdateMap = new HashMap<>(); + List updateToInventory = new ArrayList<>(); + List updateToPickDetail = new ArrayList<>(); List createToTask = new ArrayList<>(); List movePoints = new ArrayList<>(); //4.分配 - allocate(data, inventoryUpdateMap, pickDetailUpdateMap, createToTask, movePoints, errorMsgSet); + allocate(data, updateToInventory, updateToPickDetail, createToTask, movePoints, errorMsgSet); //5.生成移位任务 moveTask(createToTask, movePoints); //6.批量操作 - boolean result = batchProcessor.batchAllocate(inventoryUpdateMap, pickDetailUpdateMap, createToTask); + boolean result = batchProcessor.batchAllocate(updateToInventory, updateToPickDetail, createToTask); //7.刷新出库单 refreshData(data); @@ -395,10 +391,10 @@ public class AllocateProcessor { /** * 分配 */ - private void allocate(AllocationData data, Map inventoryUpdateMap, Map pickDetailUpdateMap, List createToTask, List movePoints, Set errorMsgSet) { + private void allocate(AllocationData data, List updateToInventory, List updateToPickDetail, List createToTask, List movePoints, Set errorMsgSet) { for (PickDetail pickDetail : data.getPickDetails()) { try { - allocatePickDetail(pickDetail, data, errorMsgSet, inventoryUpdateMap, pickDetailUpdateMap, createToTask, movePoints); + allocatePickDetail(pickDetail, data, errorMsgSet, updateToInventory, updateToPickDetail, createToTask, movePoints); } catch (Exception e) { errorMsgSet.add(String.format("分配异常,明细ID:%s,原因:%s", pickDetail.getId(), e.getMessage())); @@ -409,16 +405,16 @@ public class AllocateProcessor { /** * 分配出库明细 * - * @param pickDetail 出库明细 - * @param data 数据 - * @param errorMsgSet 错误信息 - * @param inventoryUpdateMap 更新库存 - * @param pickDetailUpdateMap 更新出库明细 - * @param createToTask 创建任务 + * @param pickDetail 出库明细 + * @param data 数据 + * @param errorMsgSet 错误信息 + * @param updateToInventory 更新库存 + * @param updateToPickDetail 更新出库明细 + * @param createToTask 创建任务 */ private void allocatePickDetail(PickDetail pickDetail, AllocationData data, - Set errorMsgSet, Map inventoryUpdateMap, - Map pickDetailUpdateMap, List createToTask, List movePoints) { + Set errorMsgSet, List updateToInventory, + List updateToPickDetail, List createToTask, List movePoints) { Pick pick = data.getPickMap().get(pickDetail.getPickId()); Item item = data.getItemMap().get(pickDetail.getItemId()); @@ -435,14 +431,14 @@ public class AllocateProcessor { } // 分配库存 - String lockKey = "allocate:" + pick.getId(); + String lockKey = "allocate:" + pickDetail.getId(); String lockValue = null; try { lockValue = redissonLock.tryLock(lockKey, 10); if (StringUtils.isEmpty(lockValue)) { throw new RuntimeException("分配处理中,请稍后重试"); } - allocateInventory(pickDetail, item, pick, matchedInventories, inventoryUpdateMap, pickDetailUpdateMap, + allocateInventory(pickDetail, item, pick, matchedInventories, updateToInventory, updateToPickDetail, createToTask, movePoints, data, unAllocatedQty, errorMsgSet); } catch (Exception e) { log.error("分配异常,出库单ID: {}", pick.getId(), e); @@ -510,15 +506,15 @@ public class AllocateProcessor { * @param item 物料 * @param pick 拣货单 * @param matchedInventories 匹配库存 - * @param inventoryUpdateMap 更新库存 - * @param pickDetailUpdateMap 更新出库明细 + * @param updateToInventory 更新库存 + * @param updateToPickDetail 更新出库明细 * @param createToTask 创建任务 * @param data 数据 * @param totalUnAllocatedQty 未分配数量 */ private void allocateInventory(PickDetail pickDetail, Item item, Pick pick, - List matchedInventories, Map inventoryUpdateMap, - Map pickDetailUpdateMap, List createToTask, List movePoints, + List matchedInventories, List updateToInventory, + List updateToPickDetail, List createToTask, List movePoints, AllocationData data, BigDecimal totalUnAllocatedQty, Set errorMsgSet) { // 智能排序库存 @@ -556,9 +552,9 @@ public class AllocateProcessor { //本次分配数量(取最小值) BigDecimal allocateQty = remainingQty.min(availableQty); // 更新库存 - updateInventoryAllocation(inventory, allocateQty, inventoryUpdateMap); + updateInventoryAllocation(inventory, allocateQty, updateToInventory); // 更新拣货明细 - updatePickDetailAllocation(pickDetail, allocateQty, pickDetailUpdateMap); + updatePickDetailAllocation(pickDetail, allocateQty, updateToPickDetail); // 创建任务 createPickTask(pickDetail, pick, item, inventory, inventoryScore, allocateQty, createToTask, data); // 获取需要移位的库位 @@ -767,68 +763,67 @@ public class AllocateProcessor { /** * 更新库存 * - * @param inventory 库存 - * @param allocateQty 分配数量 - * @param inventoryUpdateMap 库更新集合 + * @param inventory 库存 + * @param allocateQty 分配数量 + * @param updateToInventory 库更新集合 */ private void updateInventoryAllocation(Inventory inventory, BigDecimal allocateQty, - Map inventoryUpdateMap) { - Inventory targetInventory = inventoryUpdateMap.getOrDefault(inventory.getId(), inventory); - BigDecimal newQueuedQty = BigDecimalUtil.add(targetInventory.getQueuedQty(), allocateQty, 0); - targetInventory.setQueuedQty(newQueuedQty); - targetInventory.setStatus(InventoryStatusEnum.ALLOCATED.getValue()); - inventoryUpdateMap.put(targetInventory.getId(), targetInventory); + List updateToInventory) { + BigDecimal quantity = BigDecimalUtil.add(inventory.getQuantity(), allocateQty, 0); + BigDecimal queuedQty = BigDecimalUtil.add(inventory.getQueuedQty(), allocateQty, 0); + inventory.setQuantity(quantity); + inventory.setQueuedQty(queuedQty); + inventory.setStatus(InventoryStatusEnum.ALLOCATED.getValue()); + updateToInventory.add(inventory); } /** * 更新出库明细 * - * @param pickDetail 出库明细 - * @param allocateQty 分配数量 - * @param pickDetailUpdateMap 拣货明细更新集合 + * @param pickDetail 出库明细 + * @param allocateQty 分配数量 + * @param updateToPickDetail 拣货明细更新集合 */ private void updatePickDetailAllocation(PickDetail pickDetail, BigDecimal allocateQty, - Map pickDetailUpdateMap) { - PickDetail targetPickDetail = pickDetailUpdateMap.getOrDefault(pickDetail.getId(), pickDetail); - BigDecimal newAllocatedQty = BigDecimalUtil.add(targetPickDetail.getAllocatedQty(), allocateQty, 0); - Integer status = newAllocatedQty.compareTo(targetPickDetail.getOrderQty()) >= 0 ? - PickStatusEnum.ASSIGNED.getValue() : PickStatusEnum.PARTIAL.getValue(); - targetPickDetail.setAllocatedQty(newAllocatedQty); - targetPickDetail.setStatus(status); - pickDetailUpdateMap.put(targetPickDetail.getId(), targetPickDetail); + List updateToPickDetail) { + if (pickDetail == null) { + return; // 安全保护 + } -/* PickDetail detailToUpdate = pickDetailUpdateMap.computeIfAbsent( - pickDetail.getId(), id -> { - // 2. 用Builder实现拷贝 - return PickDetail.builder() - .id(pickDetail.getId()) - .pickId(pickDetail.getPickId()) - .itemId(pickDetail.getItemId()) - .lineNo(pickDetail.getLineNo()) - .unit(pickDetail.getUnit()) - .project(pickDetail.getProject()) - .taskNo(pickDetail.getTaskNo()) - .orderQty(pickDetail.getOrderQty()) - .allocatedQty(BigDecimal.ZERO) - .pickedQty(pickDetail.getPickedQty()) - .status(pickDetail.getStatus()) - .propC1(pickDetail.getPropC1()) - .propC3(pickDetail.getPropC3()) - .description(pickDetail.getDescription()) - .tenantId(pickDetail.getTenantId()) - .sysOrgCode(pickDetail.getSysOrgCode()) - .createBy(pickDetail.getCreateBy()) - .createTime(pickDetail.getCreateTime()) - .build(); - }); + // 累加分配数量 + BigDecimal existingQty = pickDetail.getAllocatedQty() == null + ? BigDecimal.ZERO + : pickDetail.getAllocatedQty(); - BigDecimal newAllocatedQty = BigDecimalUtil.add(detailToUpdate.getAllocatedQty(), allocateQty, 0); - detailToUpdate.setAllocatedQty(newAllocatedQty); + BigDecimal newAllocateQty = existingQty.add(allocateQty); + + // 订单总数量 + BigDecimal orderQty = pickDetail.getOrderQty() == null + ? BigDecimal.ZERO + : pickDetail.getOrderQty(); + + // 确保 newAllocateQty 不超过 orderQty + if (newAllocateQty.compareTo(orderQty) > 0) { + newAllocateQty = orderQty; + } + + // 更新数量 + pickDetail.setAllocatedQty(newAllocateQty); + + // 计算状态:是否完全拣完 + Integer status; + if (newAllocateQty.compareTo(orderQty) >= 0) { + status = PickStatusEnum.ASSIGNED.getValue(); + } else if (newAllocateQty.compareTo(BigDecimal.ZERO) > 0) { + status = PickStatusEnum.PARTIAL.getValue(); + } else { + status = pickDetail.getStatus(); + } + + pickDetail.setStatus(status); + + updateToPickDetail.add(pickDetail); - // 更新状态 - Integer status = newAllocatedQty.compareTo(detailToUpdate.getOrderQty()) >= 0 ? - PickStatusEnum.ASSIGNED.getValue() : PickStatusEnum.PARTIAL.getValue(); - detailToUpdate.setStatus(status);*/ } /** @@ -987,7 +982,7 @@ public class AllocateProcessor { throw e; } } - if (CollectionUtils.isNotEmpty(moveInventoryList)){ + if (CollectionUtils.isNotEmpty(moveInventoryList)) { inventoryMapper.updateById(moveInventoryList); } return moveList;