fix:需求单下推按仓库生成单据

This commit is contained in:
zhaoyf
2026-11-17 21:12:06 +08:00
parent 564f6fda4f
commit 1839f733b9
4 changed files with 129 additions and 24 deletions

View File

@@ -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<PartDemandMapper, PartDem
@Override
@Transactional(rollbackFor = Exception.class)
public void pushDemand(List<PmDemandDto> pmDemandDtos) {
if (CollectionUtils.isEmpty(pmDemandDtos)){
throw new BadRequestException("下推失败,请求数据不能为空");
@@ -329,8 +331,10 @@ public class PartDemandServiceImpl extends ServiceImpl<PartDemandMapper, PartDem
List<PmDemandDto> zdDemands = partitioned.get(true);
List<PmDemandDto> 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<PartDemand>()
.set(PartDemand::getStatus,DemandStatus.SEND.getValue())
.in(PartDemand::getId,otherDemands.stream()
@@ -390,15 +394,36 @@ public class PartDemandServiceImpl extends ServiceImpl<PartDemandMapper, PartDem
}
private JSONObject convertDemandsToBillParam(List<PmDemandDto> demands) {
/**
* 按分配仓库分组,为每个仓库生成一张出库单参数(一张出库单只能归属一个仓库)。
* 返回顺序与仓库在入参中首次出现的顺序一致。
*/
private List<JSONObject> convertDemandsToBillParams(List<PmDemandDto> demands) {
if (CollectionUtils.isEmpty(demands)) {
throw new BadRequestException("需求单数据为空");
}
Map<String, List<PmDemandDto>> 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<JSONObject> billParams = new ArrayList<>(demandsByWarehouse.size());
for (Map.Entry<String, List<PmDemandDto>> entry : demandsByWarehouse.entrySet()) {
billParams.add(convertDemandsToBillParam(entry.getKey(), entry.getValue()));
}
return billParams;
}
private JSONObject convertDemandsToBillParam(String storCode, 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("stor_code", storCode);
billParam.put("biz_date", DateUtil.today());
billParam.put("bill_type", IOSEnum.BILL_TYPE.code("库存调拨"));
billParam.put("remark", "部装需求单下推生成");

View File

@@ -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<PmDemandPlatingMappe
@Override
@Transactional(rollbackFor = Exception.class)
public void pushDemand(List<PmDemandDto> pmDemandDtos) {
if (CollectionUtils.isEmpty(pmDemandDtos)){
throw new BadRequestException("下推失败,请求数据不能为空");
@@ -334,8 +336,10 @@ public class PmDemandPlatingServiceImpl extends ServiceImpl<PmDemandPlatingMappe
List<PmDemandDto> zdDemands = partitioned.get(true);
List<PmDemandDto> 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<PmDemandPlating>()
.set(PmDemandPlating::getStatus,DemandStatus.SEND.getValue())
.in(PmDemandPlating::getId,otherDemands.stream()
@@ -395,15 +399,36 @@ public class PmDemandPlatingServiceImpl extends ServiceImpl<PmDemandPlatingMappe
}
private JSONObject convertDemandsToBillParam(List<PmDemandDto> demands) {
/**
* 按分配仓库分组,为每个仓库生成一张出库单参数(一张出库单只能归属一个仓库)。
* 返回顺序与仓库在入参中首次出现的顺序一致。
*/
private List<JSONObject> convertDemandsToBillParams(List<PmDemandDto> demands) {
if (CollectionUtils.isEmpty(demands)) {
throw new BadRequestException("需求单数据为空");
}
Map<String, List<PmDemandDto>> 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<JSONObject> billParams = new ArrayList<>(demandsByWarehouse.size());
for (Map.Entry<String, List<PmDemandDto>> entry : demandsByWarehouse.entrySet()) {
billParams.add(convertDemandsToBillParam(entry.getKey(), entry.getValue()));
}
return billParams;
}
private JSONObject convertDemandsToBillParam(String storCode, 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("stor_code", storCode);
billParam.put("biz_date", DateUtil.today());
billParam.put("bill_type", IOSEnum.BILL_TYPE.code("库存调拨"));
billParam.put("remark", "需求单下推生成");

View File

@@ -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<PmDemandMapper, PmDemand> i
@Override
@Transactional(rollbackFor = Exception.class)
public void pushDemand(List<PmDemandDto> pmDemandDtos) {
if (CollectionUtils.isEmpty(pmDemandDtos)) {
throw new BadRequestException("下推失败,请求数据不能为空");
@@ -399,8 +401,10 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> 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<PmDemand>()
.set(PmDemand::getStatus, DemandStatus.SEND.getValue())
.in(PmDemand::getId, otherDemands.stream()
@@ -546,15 +550,39 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
.apply("UPPER(unit_name) = {0}", DEFAULT_UNIT_NAME).last("limit 1"));
}
private JSONObject convertDemandsToBillParam(List<PmDemandDto> demands) {
/**
* 按分配仓库分组,为每个仓库生成一张出库单参数。
* <p>
* 批量下推时勾选的需求单可能分属不同仓库,而一张出库单只能归属一个仓库,
* 因此不能只取第一条需求的仓库作为整批单据的 stor_code,必须按仓库拆分。
* 返回顺序与仓库在入参中首次出现的顺序一致。
*/
private List<JSONObject> convertDemandsToBillParams(List<PmDemandDto> demands) {
if (CollectionUtils.isEmpty(demands)) {
throw new BadRequestException("需求单数据为空");
}
Map<String, List<PmDemandDto>> 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<JSONObject> billParams = new ArrayList<>(demandsByWarehouse.size());
for (Map.Entry<String, List<PmDemandDto>> entry : demandsByWarehouse.entrySet()) {
billParams.add(convertDemandsToBillParam(entry.getKey(), entry.getValue()));
}
return billParams;
}
private JSONObject convertDemandsToBillParam(String storCode, List<PmDemandDto> 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", "需求单下推生成");

View File

@@ -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<PmDemandStructureM
}
@Override
@Transactional(rollbackFor = Exception.class)
public void pushDemand(List<PmDemandDto> pmDemandDtos) {
if (CollectionUtils.isEmpty(pmDemandDtos)) {
throw new BadRequestException("下推失败,请求数据不能为空");
@@ -227,24 +230,48 @@ public class PmDemandStructureServiceImpl extends ServiceImpl<PmDemandStructureM
dto.setInventoryDis(RegionConstant.H005);
}
});
JSONObject billParam = convertDemandsToBillParam(pmDemandDtos);
iOutBillService.saveBill(billParam);
// 一次下推可能跨多个仓库,按仓库分组,每个仓库生成一张出库单
for (JSONObject billParam : convertDemandsToBillParams(pmDemandDtos)) {
iOutBillService.saveBill(billParam);
}
this.update(new LambdaUpdateWrapper<PmDemandStructure>()
.set(PmDemandStructure::getStatus, DemandStatus.SEND.getValue())
.in(PmDemandStructure::getId, ids));
}
/**
* 组装 WMS 出库单参数:类型生产出库,明细回传策略 sapStructureDemandOut(SAP PP055 领料出库)
* 按分配仓库分组,为每个仓库生成一张出库单参数(一张出库单只能归属一个仓库)。
* 返回顺序与仓库在入参中首次出现的顺序一致。
*/
private JSONObject convertDemandsToBillParam(List<PmDemandDto> demands) {
private List<JSONObject> convertDemandsToBillParams(List<PmDemandDto> demands) {
if (CollectionUtils.isEmpty(demands)) {
throw new BadRequestException("需求单数据为空");
}
Map<String, List<PmDemandDto>> 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<JSONObject> billParams = new ArrayList<>(demandsByWarehouse.size());
for (Map.Entry<String, List<PmDemandDto>> entry : demandsByWarehouse.entrySet()) {
billParams.add(convertDemandsToBillParam(entry.getKey(), entry.getValue()));
}
return billParams;
}
/**
* 组装 WMS 出库单参数:类型生产出库,明细回传策略 sapStructureDemandOut(SAP PP055 领料出库)
*/
private JSONObject convertDemandsToBillParam(String storCode, 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("stor_code", storCode);
billParam.put("biz_date", DateUtil.today());
billParam.put("bill_type", IOSEnum.BILL_TYPE.code("生产出库"));
billParam.put("remark", "结构件需求单下推生成");