From 3066a8f5c1f475997bfe23857ba4bae9395900c4 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期四, 13 八月 2026 10:19:24 +0800
Subject: [PATCH] fix: 领料功能修改,移除订单领料,添加工序领料功能,支持按工序查询物料与已领料记录
---
src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java | 237 +++++++++++++---------------------------------------------
1 files changed, 55 insertions(+), 182 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
index caff402..e9a0487 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
@@ -34,6 +34,7 @@
import com.ruoyi.quality.pojo.QualityInspectFile;
import com.ruoyi.quality.pojo.QualityInspectParam;
import com.ruoyi.production.service.ProductionOrderService;
+import com.ruoyi.production.util.TaskPlanQuantityUtil;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.stock.mapper.StockInventoryMapper;
@@ -250,18 +251,8 @@
.eq(TechnologyRoutingOperation::getTechnologyRoutingId, technologyRouting.getId())
.orderByDesc(TechnologyRoutingOperation::getDragSort)
.orderByDesc(TechnologyRoutingOperation::getId));
- // Build task plan quantities from order BOM snapshot demand instead of recomputing from technology BOM units.
- Long rootProductModelId = orderBom != null && orderBom.getProductModelId() != null
- ? orderBom.getProductModelId()
- : productionOrder.getProductModelId();
- List<ProductionBomStructure> orderBomStructureList = orderBom == null || orderBom.getId() == null
- ? Collections.emptyList()
- : productionBomStructureMapper.selectList(
- Wrappers.<ProductionBomStructure>lambdaQuery()
- .eq(ProductionBomStructure::getProductionOrderBomId, orderBom.getId())
- .orderByAsc(ProductionBomStructure::getId));
- Map<String, BigDecimal> operationDemandedQuantityMap =
- buildOperationDemandedQuantityMap(orderBomStructureList, rootProductModelId);
+ // 鎵佸钩 BOM 涓嶉厤缃暟閲忥紝宸ュ崟璁″垝鏁伴噺缁熶竴鍙栬鍗曟暟閲忋��
+ BigDecimal taskPlanQuantity = TaskPlanQuantityUtil.resolveTaskPlanQuantity(productionOrder);
Map<Long, String> operationNameMap = technologyOperationMapper.selectBatchIds(
// 閬嶅巻澶勭悊鏁版嵁骞剁粍瑁呯粨鏋�
routingOperations.stream()
@@ -295,11 +286,7 @@
ProductionOperationTask task = new ProductionOperationTask();
task.setProductionOrderRoutingOperationId(targetOperation.getId());
task.setProductionOrderId(productionOrder.getId());
- task.setPlanQuantity(resolveTaskPlanQuantity(
- sourceOperation,
- operationDemandedQuantityMap,
- productionOrder,
- rootProductModelId));
+ task.setPlanQuantity(taskPlanQuantity);
task.setCompleteQuantity(BigDecimal.ZERO);
task.setWorkOrderNo(generateNextTaskNo());
task.setStatus(2);
@@ -334,87 +321,11 @@
return syncedParamCount;
}
- private Map<String, BigDecimal> buildOperationDemandedQuantityMap(List<ProductionBomStructure> bomStructures,
- Long rootProductModelId) {
- if (bomStructures == null || bomStructures.isEmpty()) {
- return Collections.emptyMap();
- }
- Map<Long, ProductionBomStructure> structureById = bomStructures.stream()
- .filter(item -> item != null && item.getId() != null)
- .collect(Collectors.toMap(ProductionBomStructure::getId, item -> item, (left, right) -> left));
- Map<String, BigDecimal> demandedQuantityMap = new HashMap<>();
- Set<String> mergedOutputNodeKeySet = new HashSet<>();
- for (ProductionBomStructure bomStructure : bomStructures) {
- if (bomStructure == null || bomStructure.getTechnologyOperationId() == null) {
- continue;
- }
- // The BOM row points to the producing operation; task quantity should come from that operation's output node.
- ProductionBomStructure outputNode = resolveOperationOutputNode(bomStructure, structureById);
- Long outputProductModelId = resolveOutputProductModelId(outputNode, rootProductModelId);
- if (outputProductModelId == null) {
- continue;
- }
- String mergedOutputNodeKey = buildOperationOutputNodeKey(
- bomStructure.getTechnologyOperationId(),
- outputNode == null ? null : outputNode.getId(),
- outputProductModelId);
- if (!mergedOutputNodeKeySet.add(mergedOutputNodeKey)) {
- continue;
- }
- // demandedQuantity is already the order-level required output quantity for the current output node.
- BigDecimal demandedQuantity = defaultDecimal(outputNode == null ? null : outputNode.getDemandedQuantity());
- String key = buildOperationDemandedQuantityKey(bomStructure.getTechnologyOperationId(), outputProductModelId);
- demandedQuantityMap.merge(key, demandedQuantity, BigDecimal::add);
- }
- return demandedQuantityMap;
- }
-
- private BigDecimal resolveTaskPlanQuantity(TechnologyRoutingOperation sourceOperation,
- Map<String, BigDecimal> operationDemandedQuantityMap,
- ProductionOrder productionOrder,
- Long rootProductModelId) {
- if (sourceOperation == null || operationDemandedQuantityMap == null || operationDemandedQuantityMap.isEmpty()) {
- return defaultDecimal(productionOrder == null ? null : productionOrder.getQuantity());
- }
- Long outputProductModelId = sourceOperation.getProductModelId() != null
- ? sourceOperation.getProductModelId()
- : rootProductModelId;
- String key = buildOperationDemandedQuantityKey(sourceOperation.getTechnologyOperationId(), outputProductModelId);
- BigDecimal planQuantity = operationDemandedQuantityMap.get(key);
- return planQuantity != null ? planQuantity : defaultDecimal(productionOrder == null ? null : productionOrder.getQuantity());
- }
-
- private String buildOperationDemandedQuantityKey(Long operationId, Long outputProductModelId) {
- return String.valueOf(operationId) + "#" + String.valueOf(outputProductModelId);
- }
-
- private String buildOperationOutputNodeKey(Long operationId, Long outputNodeId, Long outputProductModelId) {
- return String.valueOf(operationId) + "#" + String.valueOf(outputNodeId) + "#" + String.valueOf(outputProductModelId);
- }
-
- private ProductionBomStructure resolveOperationOutputNode(ProductionBomStructure bomStructure,
- Map<Long, ProductionBomStructure> structureById) {
- if (bomStructure == null) {
- return null;
- }
- // The root node is the first output node; child rows use their direct parent as the current operation output.
- if (bomStructure.getParentId() == null) {
- return bomStructure;
- }
- ProductionBomStructure parent = structureById.get(bomStructure.getParentId());
- return parent != null ? parent : bomStructure;
- }
-
- private Long resolveOutputProductModelId(ProductionBomStructure outputNode,
- Long rootProductModelId) {
- if (outputNode == null) {
- return rootProductModelId;
- }
- return outputNode.getProductModelId() != null ? outputNode.getProductModelId() : rootProductModelId;
- }
-
+ /**
+ * 鍚屾璁㈠崟BOM蹇収锛氭墎骞冲鍒垛�滅墿鏂欒鏍� + 娑堣�楀伐搴忊�濆叧绯汇��
+ * 涓嶅啀鐢熸垚鎴愬搧鏍硅妭鐐癸紝涔熶笉鍐嶈绠楀崟浣嶇敤閲忓拰闇�姹傛暟閲忋��
+ */
private ProductionOrderBom syncProductionOrderBomSnapshot(ProductionOrder productionOrder, TechnologyRouting technologyRouting) {
- // 鍚屾璁㈠崟BOM蹇収缁撴瀯
if (technologyRouting.getBomId() == null) {
return null;
}
@@ -422,41 +333,32 @@
if (technologyBom == null) {
throw new ServiceException("宸ヨ壓BOM涓嶅瓨鍦�");
}
- // 鏌ヨ骞跺噯澶囦笟鍔℃暟鎹�
+ // 鍙彇鐪熷疄鐗╂枡琛岋細蹇呴』鏈夋秷鑰楀伐搴忥紝鍘嗗彶鎴愬搧鏍硅妭鐐癸紙鏃犲伐搴忥級涓嶅睘浜庣墿鏂�
List<TechnologyBomStructure> structureList = technologyBomStructureMapper.selectList(
Wrappers.<TechnologyBomStructure>lambdaQuery()
.eq(TechnologyBomStructure::getBomId, technologyBom.getId())
+ .isNotNull(TechnologyBomStructure::getOperationId)
.orderByAsc(TechnologyBomStructure::getId));
- // 閬嶅巻澶勭悊鏁版嵁骞剁粍瑁呯粨鏋�
- TechnologyBomStructure root = structureList.stream().filter(item -> item.getParentId() == null).findFirst().orElse(null);
- BigDecimal orderQuantity = defaultDecimal(productionOrder.getQuantity());
ProductionOrderBom orderBom = new ProductionOrderBom();
orderBom.setProductionOrderId(productionOrder.getId());
orderBom.setBomId(Long.valueOf(technologyBom.getId()));
- orderBom.setProductModelId(root != null ? root.getProductModelId() : productionOrder.getProductModelId());
+ // BOM 涓昏〃鏈韩鍗充唬琛ㄦ垚鍝佽鏍�
+ orderBom.setProductModelId(technologyBom.getProductModelId() != null
+ ? technologyBom.getProductModelId()
+ : productionOrder.getProductModelId());
orderBom.setRemark(technologyBom.getRemark());
orderBom.setBomNo(technologyBom.getBomNo());
orderBom.setVersion(technologyBom.getVersion());
- // 鎸佷箙鍖栨垨杈撳嚭澶勭悊缁撴灉
productionOrderBomMapper.insert(orderBom);
- Map<Long, Long> idMap = new HashMap<>();
- BigDecimal lastProcessDemandedQuantity = orderQuantity;
for (TechnologyBomStructure source : structureList) {
- // 瀛愯妭鐐� parentId 闇�瑕佹槧灏勬垚鏂板揩鐓ц妭鐐� id锛屾墠鑳戒繚鐣欏師濮� BOM 灞傜骇銆�
ProductionBomStructure target = new ProductionBomStructure();
target.setProductionOrderId(productionOrder.getId());
target.setProductionOrderBomId(orderBom.getId());
- target.setParentId(source.getParentId() == null ? null : idMap.get(source.getParentId()));
target.setProductModelId(source.getProductModelId());
target.setTechnologyOperationId(source.getOperationId());
- target.setUnitQuantity(source.getUnitQuantity());
- target.setDemandedQuantity(lastProcessDemandedQuantity.multiply(source.getUnitQuantity()));
- target.setUnit(source.getUnit());
productionBomStructureMapper.insert(target);
- idMap.put(source.getId(), target.getId());
- lastProcessDemandedQuantity = target.getDemandedQuantity();
}
return orderBom;
}
@@ -1059,12 +961,20 @@
@Override
public List<ProductionOrderPickVo> pick(Long productionOrderId) {
- // 鏌ヨ璁㈠崟棰嗘枡銆佹姇鏂欎笌閫�鏂欐槑缁�
+ return pick(productionOrderId, null);
+ }
+
+ /**
+ * 鎸夎鍗旴OM蹇収缁欏嚭鍙鐢ㄧ墿鏂欏缓璁��
+ * 鎵佸钩BOM鍙弿杩扳�滅墿鏂欒鏍� + 娑堣�楀伐搴忊�濓紝鍥犳杩欓噷涓嶅啀璁$畻闇�姹傛暟閲忥紱
+ * 浼犲叆宸ュ簭ID鏃跺彧杩斿洖璇ュ伐搴忕殑鐗╂枡銆�
+ */
+ @Override
+ public List<ProductionOrderPickVo> pick(Long productionOrderId, Long technologyOperationId) {
if (productionOrderId == null) {
return Collections.emptyList();
}
- // 鏌ヨ骞跺噯澶囦笟鍔℃暟鎹�
ProductionOrderBom orderBom = productionOrderBomMapper.selectOne(
Wrappers.<ProductionOrderBom>lambdaQuery()
.eq(ProductionOrderBom::getProductionOrderId, productionOrderId)
@@ -1074,67 +984,35 @@
return Collections.emptyList();
}
- // 鏌ヨ瀹屾暣鐨凚OM缁撴瀯锛堝寘鎷牴鑺傜偣锛夛紝鐢ㄤ簬璁$畻灞傜骇闇�姹傛暟閲�
List<ProductionBomStructureVo> bomStructureList = productionBomStructureMapper.listByBomId(orderBom.getId());
if (bomStructureList == null || bomStructureList.isEmpty()) {
return Collections.emptyList();
}
- // 鏌ヨ鐢熶骇璁㈠崟鑾峰彇璁㈠崟鏁伴噺
ProductionOrder productionOrder = productionOrderMapper.selectById(productionOrderId);
- BigDecimal orderQuantity = productionOrder != null ? defaultDecimal(productionOrder.getQuantity()) : BigDecimal.ZERO;
- // 鏋勫缓鏍戝舰缁撴瀯骞惰绠楀眰绾ч渶姹傛暟閲�
- Map<Long, ProductionBomStructureVo> structureByIdMap = bomStructureList.stream()
- .filter(s -> s != null && s.getId() != null)
- .collect(Collectors.toMap(ProductionBomStructureVo::getId, s -> s));
-
- // 鎸夊眰绾ц绠楅渶姹傛暟閲忥細瀛愮骇闇�姹傛暟閲� = 鐖剁骇闇�姹傛暟閲� 脳 瀛愮骇鍗曚綅浜у嚭鎵�闇�鏁伴噺
- for (ProductionBomStructureVo structure : bomStructureList) {
- if (structure == null) continue;
-
- if (structure.getParentId() == null || structure.getParentId() == 0) {
- // 鏍硅妭鐐癸細闇�姹傛暟閲� = 璁㈠崟鏁伴噺
- structure.setDemandedQuantity(orderQuantity);
- } else {
- // 瀛愯妭鐐癸細闇�姹傛暟閲� = 鐖剁骇闇�姹傛暟閲� 脳 瀛愮骇鍗曚綅浜у嚭鎵�闇�鏁伴噺
- ProductionBomStructureVo parent = structureByIdMap.get(structure.getParentId());
- if (parent != null) {
- BigDecimal parentDemandedQty = defaultDecimal(parent.getDemandedQuantity());
- BigDecimal unitQuantity = defaultDecimal(structure.getUnitQuantity());
- structure.setDemandedQuantity(parentDemandedQty.multiply(unitQuantity));
- }
- }
- }
-
- // 鏀堕泦璁㈠崟鎴愬搧瑙勬牸ID锛氬寘鍚敓浜ц鍗曟垚鍝佽鏍间笌BOM鏍硅妭鐐硅鏍硷紝鐢ㄤ簬鎺掗櫎鈥滆嚜宸扁�濊繖涓�鐗╂枡
+ // 鎴愬搧瑙勬牸涓嶉渶瑕侀鏂欙細鍏煎鍘嗗彶蹇収涓彲鑳藉瓨鍦ㄧ殑鎴愬搧鏍硅妭鐐�
Set<Long> finishedProductModelIds = new HashSet<>();
if (productionOrder != null && productionOrder.getProductModelId() != null) {
finishedProductModelIds.add(productionOrder.getProductModelId());
}
- bomStructureList.stream()
- .filter(s -> s != null && (s.getParentId() == null || s.getParentId() == 0))
- .map(ProductionBomStructureVo::getProductModelId)
- .filter(Objects::nonNull)
- .forEach(finishedProductModelIds::add);
+ if (orderBom.getProductModelId() != null) {
+ finishedProductModelIds.add(orderBom.getProductModelId());
+ }
- // 鏀堕泦鎵�鏈夎寮曠敤涓虹埗绾х殑鑺傜偣ID锛欱OM浠庢渶鍚庝竴閬撳伐搴忓線閲岄厤缃墠涓�閬撳伐搴忥紝
- // 涓棿鑺傜偣鏄笂涓�閬撳伐搴忕殑浜у嚭锛堣嚜鍒讹級锛屽彧鏈夋瘡鏉″垎鏀渶閲屽眰鐨勫彾瀛愯妭鐐规墠鏄湡姝i渶瑕侀鐢ㄧ殑鐗╂枡銆�
- Set<Long> parentNodeIds = bomStructureList.stream()
- .filter(s -> s != null && s.getParentId() != null && s.getParentId() != 0)
- .map(ProductionBomStructureVo::getParentId)
+ List<ProductionBomStructureVo> materialStructureList = bomStructureList.stream()
.filter(Objects::nonNull)
- .collect(Collectors.toSet());
-
- // 杩囨护鍑哄彾瀛愯妭鐐癸紙瀹為檯棰嗘枡椤癸級锛氶潪鏍硅妭鐐广�侀潪涓棿鑺傜偣锛屽苟鎺掗櫎涓庤鍗曟垚鍝佸悓瑙勬牸鐨勭墿鏂欙紙鑷埗鎴愬搧鏃犻渶棰嗘枡锛�
- List<ProductionBomStructureVo> childStructureList = bomStructureList.stream()
- .filter(s -> s != null && s.getParentId() != null && s.getParentId() != 0)
- .filter(s -> s.getId() == null || !parentNodeIds.contains(s.getId()))
- .filter(s -> s.getProductModelId() == null || !finishedProductModelIds.contains(s.getProductModelId()))
+ .filter(s -> s.getProductModelId() != null && !finishedProductModelIds.contains(s.getProductModelId()))
+ .filter(s -> s.getTechnologyOperationId() != null)
+ .filter(s -> technologyOperationId == null
+ || technologyOperationId.equals(s.getTechnologyOperationId()))
.collect(Collectors.toList());
+ if (materialStructureList.isEmpty()) {
+ return Collections.emptyList();
+ }
// 閬嶅巻澶勭悊鏁版嵁骞剁粍瑁呯粨鏋�
- List<Long> productModelIds = childStructureList.stream()
+ List<Long> productModelIds = materialStructureList.stream()
.map(ProductionBomStructureVo::getProductModelId)
.filter(Objects::nonNull)
.distinct()
@@ -1160,31 +1038,26 @@
}
Map<String, ProductionOrderPickVo> mergedPickMap = new LinkedHashMap<>();
- for (ProductionBomStructureVo structure : childStructureList) {
- if (structure == null || structure.getProductModelId() == null) {
+ for (ProductionBomStructureVo structure : materialStructureList) {
+ Long productModelId = structure.getProductModelId();
+ String mergeKey = structure.getTechnologyOperationId() + "#" + productModelId;
+ if (mergedPickMap.containsKey(mergeKey)) {
continue;
}
- Long productModelId = structure.getProductModelId();
- String mergeKey = String.valueOf(structure.getTechnologyOperationId()) + "#" + productModelId;
- ProductionOrderPickVo vo = mergedPickMap.get(mergeKey);
- if (vo == null) {
- vo = new ProductionOrderPickVo();
- vo.setProductModelId(productModelId);
- vo.setOperationName(structure.getOperationName());
- vo.setTechnologyOperationId(structure.getTechnologyOperationId());
- vo.setProductName(structure.getProductName());
- vo.setModel(structure.getModel());
- vo.setDemandedQuantity(BigDecimal.ZERO);
- vo.setUnit(structure.getUnit());
- List<String> batchNoList = stockBatchNoMap.get(productModelId) == null
- ? Collections.emptyList()
- : new ArrayList<>(stockBatchNoMap.get(productModelId));
- vo.setBatchNoList(batchNoList);
- vo.setStockQuantity(stockQuantityMap.getOrDefault(productModelId, BigDecimal.ZERO));
- vo.setBom(true);
- mergedPickMap.put(mergeKey, vo);
- }
- vo.setDemandedQuantity(defaultDecimal(vo.getDemandedQuantity()).add(defaultDecimal(structure.getDemandedQuantity())));
+ ProductionOrderPickVo vo = new ProductionOrderPickVo();
+ vo.setProductModelId(productModelId);
+ vo.setOperationName(structure.getOperationName());
+ vo.setTechnologyOperationId(structure.getTechnologyOperationId());
+ vo.setProductName(structure.getProductName());
+ vo.setModel(structure.getModel());
+ vo.setUnit(structure.getUnit());
+ List<String> batchNoList = stockBatchNoMap.get(productModelId) == null
+ ? Collections.emptyList()
+ : new ArrayList<>(stockBatchNoMap.get(productModelId));
+ vo.setBatchNoList(batchNoList);
+ vo.setStockQuantity(stockQuantityMap.getOrDefault(productModelId, BigDecimal.ZERO));
+ vo.setBom(true);
+ mergedPickMap.put(mergeKey, vo);
}
return new ArrayList<>(mergedPickMap.values());
}
--
Gitblit v1.9.3