diff --git a/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PartDemandServiceImpl.java b/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PartDemandServiceImpl.java index 9e107345..6ffa92aa 100644 --- a/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PartDemandServiceImpl.java +++ b/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PartDemandServiceImpl.java @@ -49,6 +49,7 @@ 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.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; @@ -308,6 +309,7 @@ public class PartDemandServiceImpl extends ServiceImpl pmDemandDtos) { if (CollectionUtils.isEmpty(pmDemandDtos)){ throw new BadRequestException("下推失败,请求数据不能为空"); @@ -329,8 +331,10 @@ public class PartDemandServiceImpl extends ServiceImpl zdDemands = partitioned.get(true); List otherDemands = partitioned.get(false); if (!CollectionUtils.isEmpty(otherDemands)) { - JSONObject billParam = convertDemandsToBillParam(otherDemands); - iOutBillService.saveBill(billParam); + // 一次下推可能跨多个仓库,按仓库分组,每个仓库生成一张出库单 + for (JSONObject billParam : convertDemandsToBillParams(otherDemands)) { + iOutBillService.saveBill(billParam); + } this.update(new LambdaUpdateWrapper() .set(PartDemand::getStatus,DemandStatus.SEND.getValue()) .in(PartDemand::getId,otherDemands.stream() @@ -390,15 +394,36 @@ public class PartDemandServiceImpl extends ServiceImpl demands) { + /** + * 按分配仓库分组,为每个仓库生成一张出库单参数(一张出库单只能归属一个仓库)。 + * 返回顺序与仓库在入参中首次出现的顺序一致。 + */ + private List convertDemandsToBillParams(List demands) { + if (CollectionUtils.isEmpty(demands)) { + throw new BadRequestException("需求单数据为空"); + } + Map> demandsByWarehouse = new LinkedHashMap<>(); + for (PmDemandDto demand : demands) { + String warehouseCode = StringUtils.trimToNull(demand.getInventoryDis()); + if (warehouseCode == null) { + throw new BadRequestException("下推失败,需求单" + demand.getWorkOrder() + "未分配仓库"); + } + demandsByWarehouse.computeIfAbsent(warehouseCode, key -> new ArrayList<>()).add(demand); + } + List billParams = new ArrayList<>(demandsByWarehouse.size()); + for (Map.Entry> entry : demandsByWarehouse.entrySet()) { + billParams.add(convertDemandsToBillParam(entry.getKey(), entry.getValue())); + } + return billParams; + } + + private JSONObject convertDemandsToBillParam(String storCode, List 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("stor_code", storCode); billParam.put("biz_date", DateUtil.today()); billParam.put("bill_type", IOSEnum.BILL_TYPE.code("库存调拨")); billParam.put("remark", "部装需求单下推生成"); diff --git a/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandPlatingServiceImpl.java b/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandPlatingServiceImpl.java index 04db24e0..f05f974f 100644 --- a/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandPlatingServiceImpl.java +++ b/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandPlatingServiceImpl.java @@ -49,6 +49,7 @@ 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.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; @@ -308,6 +309,7 @@ public class PmDemandPlatingServiceImpl extends ServiceImpl pmDemandDtos) { if (CollectionUtils.isEmpty(pmDemandDtos)){ throw new BadRequestException("下推失败,请求数据不能为空"); @@ -334,8 +336,10 @@ public class PmDemandPlatingServiceImpl extends ServiceImpl zdDemands = partitioned.get(true); List otherDemands = partitioned.get(false); if (!CollectionUtils.isEmpty(otherDemands)) { - JSONObject billParam = convertDemandsToBillParam(otherDemands); - iOutBillService.saveBill(billParam); + // 一次下推可能跨多个仓库,按仓库分组,每个仓库生成一张出库单 + for (JSONObject billParam : convertDemandsToBillParams(otherDemands)) { + iOutBillService.saveBill(billParam); + } this.update(new LambdaUpdateWrapper() .set(PmDemandPlating::getStatus,DemandStatus.SEND.getValue()) .in(PmDemandPlating::getId,otherDemands.stream() @@ -395,15 +399,36 @@ public class PmDemandPlatingServiceImpl extends ServiceImpl demands) { + /** + * 按分配仓库分组,为每个仓库生成一张出库单参数(一张出库单只能归属一个仓库)。 + * 返回顺序与仓库在入参中首次出现的顺序一致。 + */ + private List convertDemandsToBillParams(List demands) { + if (CollectionUtils.isEmpty(demands)) { + throw new BadRequestException("需求单数据为空"); + } + Map> demandsByWarehouse = new LinkedHashMap<>(); + for (PmDemandDto demand : demands) { + String warehouseCode = StringUtils.trimToNull(demand.getInventoryDis()); + if (warehouseCode == null) { + throw new BadRequestException("下推失败,需求单" + demand.getWorkOrder() + "未分配仓库"); + } + demandsByWarehouse.computeIfAbsent(warehouseCode, key -> new ArrayList<>()).add(demand); + } + List billParams = new ArrayList<>(demandsByWarehouse.size()); + for (Map.Entry> entry : demandsByWarehouse.entrySet()) { + billParams.add(convertDemandsToBillParam(entry.getKey(), entry.getValue())); + } + return billParams; + } + + private JSONObject convertDemandsToBillParam(String storCode, List 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("stor_code", storCode); billParam.put("biz_date", DateUtil.today()); billParam.put("bill_type", IOSEnum.BILL_TYPE.code("库存调拨")); billParam.put("remark", "需求单下推生成"); diff --git a/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandServiceImpl.java b/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandServiceImpl.java index 128a71c9..b3fdb349 100644 --- a/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandServiceImpl.java +++ b/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandServiceImpl.java @@ -58,6 +58,7 @@ 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.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; @@ -371,6 +372,7 @@ public class PmDemandServiceImpl extends ServiceImpl i @Override + @Transactional(rollbackFor = Exception.class) public void pushDemand(List pmDemandDtos) { if (CollectionUtils.isEmpty(pmDemandDtos)) { throw new BadRequestException("下推失败,请求数据不能为空"); @@ -399,8 +401,10 @@ public class PmDemandServiceImpl extends ServiceImpl i if (!CollectionUtils.isEmpty(otherDemands)) { // validateEasInventory(otherDemands); - JSONObject billParam = convertDemandsToBillParam(otherDemands); - iOutBillService.saveBill(billParam); + // 一次下推可能跨多个仓库,按仓库分组,每个仓库生成一张出库单 + for (JSONObject billParam : convertDemandsToBillParams(otherDemands)) { + iOutBillService.saveBill(billParam); + } this.update(new LambdaUpdateWrapper() .set(PmDemand::getStatus, DemandStatus.SEND.getValue()) .in(PmDemand::getId, otherDemands.stream() @@ -546,15 +550,39 @@ public class PmDemandServiceImpl extends ServiceImpl i .apply("UPPER(unit_name) = {0}", DEFAULT_UNIT_NAME).last("limit 1")); } - private JSONObject convertDemandsToBillParam(List demands) { + /** + * 按分配仓库分组,为每个仓库生成一张出库单参数。 + *

+ * 批量下推时勾选的需求单可能分属不同仓库,而一张出库单只能归属一个仓库, + * 因此不能只取第一条需求的仓库作为整批单据的 stor_code,必须按仓库拆分。 + * 返回顺序与仓库在入参中首次出现的顺序一致。 + */ + private List convertDemandsToBillParams(List demands) { + if (CollectionUtils.isEmpty(demands)) { + throw new BadRequestException("需求单数据为空"); + } + Map> demandsByWarehouse = new LinkedHashMap<>(); + for (PmDemandDto demand : demands) { + String warehouseCode = resolveInventoryWarehouse(demand.getInventoryDis()); + if (StringUtils.isBlank(warehouseCode)) { + throw new BadRequestException("下推失败,需求单" + demand.getWorkOrder() + "未分配仓库"); + } + demandsByWarehouse.computeIfAbsent(warehouseCode, key -> new ArrayList<>()).add(demand); + } + List billParams = new ArrayList<>(demandsByWarehouse.size()); + for (Map.Entry> entry : demandsByWarehouse.entrySet()) { + billParams.add(convertDemandsToBillParam(entry.getKey(), entry.getValue())); + } + return billParams; + } + + private JSONObject convertDemandsToBillParam(String storCode, List demands) { if (CollectionUtils.isEmpty(demands)) { throw new BadRequestException("需求单数据为空"); } - PmDemandDto firstDemand = demands.get(0); - JSONObject billParam = new JSONObject(); - billParam.put("stor_code", resolveInventoryWarehouse(firstDemand.getInventoryDis())); + billParam.put("stor_code", storCode); billParam.put("biz_date", DateUtil.today()); billParam.put("bill_type", IOSEnum.BILL_TYPE.code("生产出库")); billParam.put("remark", "需求单下推生成"); diff --git a/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandStructureServiceImpl.java b/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandStructureServiceImpl.java index 6aca0e57..f2312ee4 100644 --- a/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandStructureServiceImpl.java +++ b/nladmin-system/wms-server/src/main/java/org/nl/wms/pm_manage/demand/service/impl/PmDemandStructureServiceImpl.java @@ -28,9 +28,11 @@ import org.nl.wms.warehouse_manage.enums.IOSEnum; import org.nl.wms.warehouse_manage.inAndOut.service.IOutBillService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -198,6 +200,7 @@ public class PmDemandStructureServiceImpl extends ServiceImpl pmDemandDtos) { if (CollectionUtils.isEmpty(pmDemandDtos)) { throw new BadRequestException("下推失败,请求数据不能为空"); @@ -227,24 +230,48 @@ public class PmDemandStructureServiceImpl extends ServiceImpl() .set(PmDemandStructure::getStatus, DemandStatus.SEND.getValue()) .in(PmDemandStructure::getId, ids)); } /** - * 组装 WMS 出库单参数:类型生产出库,明细回传策略 sapStructureDemandOut(SAP PP055 领料出库) + * 按分配仓库分组,为每个仓库生成一张出库单参数(一张出库单只能归属一个仓库)。 + * 返回顺序与仓库在入参中首次出现的顺序一致。 */ - private JSONObject convertDemandsToBillParam(List demands) { + private List convertDemandsToBillParams(List demands) { + if (CollectionUtils.isEmpty(demands)) { + throw new BadRequestException("需求单数据为空"); + } + Map> demandsByWarehouse = new LinkedHashMap<>(); + for (PmDemandDto demand : demands) { + String warehouseCode = StringUtils.trimToNull(demand.getInventoryDis()); + if (warehouseCode == null) { + throw new BadRequestException("下推失败,需求单" + demand.getWorkOrder() + "未分配仓库"); + } + demandsByWarehouse.computeIfAbsent(warehouseCode, key -> new ArrayList<>()).add(demand); + } + List billParams = new ArrayList<>(demandsByWarehouse.size()); + for (Map.Entry> entry : demandsByWarehouse.entrySet()) { + billParams.add(convertDemandsToBillParam(entry.getKey(), entry.getValue())); + } + return billParams; + } + + /** + * 组装 WMS 出库单参数:类型生产出库,明细回传策略 sapStructureDemandOut(SAP PP055 领料出库) + */ + private JSONObject convertDemandsToBillParam(String storCode, List 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("stor_code", storCode); billParam.put("biz_date", DateUtil.today()); billParam.put("bill_type", IOSEnum.BILL_TYPE.code("生产出库")); billParam.put("remark", "结构件需求单下推生成");