From 6f0df10fdd0e55e5ed3e31b1720efd25e2bf02fb Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期三, 16 九月 2026 18:51:12 +0800
Subject: [PATCH] fix: 添加条件过滤以确保查询结果中合格数量大于零
---
src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java | 443 +++++++++++++++----------------------------------------
1 files changed, 120 insertions(+), 323 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
index 40dd74c..304d0e8 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.production.bean.dto.ProductionBomStructureDto;
import com.ruoyi.production.bean.vo.ProductionBomStructureVo;
@@ -31,7 +32,6 @@
import com.ruoyi.technology.pojo.TechnologyOperationParam;
import com.ruoyi.technology.pojo.TechnologyParam;
import lombok.RequiredArgsConstructor;
-import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -61,123 +61,137 @@
private final ProductionOrderRoutingOperationParamMapper productionOrderRoutingOperationParamMapper;
private final ProductionOperationTaskMapper productionOperationTaskMapper;
private final ProductionProductMainMapper productionProductMainMapper;
+ private final ProductModelMapper productModelMapper;
private final TechnologyOperationMapper technologyOperationMapper;
private final TechnologyOperationParamMapper technologyOperationParamMapper;
private final TechnologyParamMapper technologyParamMapper;
/**
- * 鏍规嵁BOM鏌ヨ骞剁粍瑁呯粨鏋勬爲銆�
+ * 鎸夎鍗旴OM鏌ヨ鎵佸钩鐗╂枡鏄庣粏銆�
*/
@Override
public List<ProductionBomStructureVo> listByBomId(Long bomId) {
- // 鎸塀OMID鏌ヨ鐢熶骇缁撴瀯鏁版嵁
- List<ProductionBomStructureVo> list = productionBomStructureMapper.listByBomId(bomId);
- Map<Long, ProductionBomStructureVo> map = new HashMap<>();
- for (ProductionBomStructureVo node : list) {
- node.setChildren(new ArrayList<>());
- map.put(node.getId(), node);
+ if (bomId == null) {
+ return new ArrayList<>();
}
-
- List<ProductionBomStructureVo> tree = new ArrayList<>();
- for (ProductionBomStructureVo node : list) {
- Long parentId = node.getParentId();
- if (parentId == null || parentId == 0L) {
- tree.add(node);
- continue;
- }
- ProductionBomStructureVo parent = map.get(parentId);
- if (parent != null) {
- parent.getChildren().add(node);
- }
- }
- return tree;
+ return productionBomStructureMapper.listByBomId(bomId);
}
+ /**
+ * 鎸夌敓浜ц鍗曟煡璇㈣鍗旴OM蹇収鐨勬墎骞崇墿鏂欐槑缁嗐��
+ */
+ @Override
+ public List<ProductionBomStructureVo> listByOrderId(Long productionOrderId) {
+ if (productionOrderId == null) {
+ return new ArrayList<>();
+ }
+ ProductionOrderBom orderBom = productionOrderBomMapper.selectOne(
+ Wrappers.<ProductionOrderBom>lambdaQuery()
+ .eq(ProductionOrderBom::getProductionOrderId, productionOrderId)
+ .orderByDesc(ProductionOrderBom::getId)
+ .last("limit 1"));
+ if (orderBom == null || orderBom.getId() == null) {
+ return new ArrayList<>();
+ }
+ return listByBomId(orderBom.getId());
+ }
+
+ /**
+ * 鍏ㄩ噺鍚屾璁㈠崟BOM蹇収鐨勬墎骞崇墿鏂欐槑缁嗭紝骞舵寜鍏朵腑鐨勫伐搴忛噸寤鸿鍗曞伐鑹鸿矾绾垮揩鐓т笌宸ュ崟銆�
+ */
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean addProductionBomStructure(ProductionBomStructureDto dto) {
- // 鏂板鐢熶骇BOM缁撴瀯
- // 璇诲彇褰撳墠璁㈠崟BOM涓婚敭锛屽苟鎶婂墠绔爲缁撴瀯鎷嶅钩鎴愬垪琛�
Long orderBomId = dto.getProductionOrderBomId();
- List<ProductionBomStructureDto> flatDtoList = new ArrayList<>();
- flattenTree(dto.getChildren(), flatDtoList);
+ if (orderBomId == null) {
+ throw new ServiceException("璁㈠崟BOM ID涓嶈兘涓虹┖");
+ }
+ ProductionOrderBom orderBom = productionOrderBomMapper.selectById(orderBomId);
+ if (orderBom == null) {
+ throw new ServiceException("璁㈠崟BOM涓嶅瓨鍦�");
+ }
+ Long productionOrderId = dto.getProductionOrderId() != null
+ ? dto.getProductionOrderId()
+ : orderBom.getProductionOrderId();
- // 鏌ヨ鏁版嵁搴撳凡鏈夌粨鏋勶紝鐢ㄤ簬鍚庣画鍋氬鍒犳敼瀵规瘮
+ List<ProductionBomStructureDto> detailList = dto.getDetailList() == null
+ ? Collections.emptyList()
+ : dto.getDetailList();
+
List<ProductionBomStructure> dbList = this.list(new LambdaQueryWrapper<ProductionBomStructure>()
.eq(ProductionBomStructure::getProductionOrderBomId, orderBomId));
+ Set<Long> dbIds = dbList.stream().map(ProductionBomStructure::getId).collect(Collectors.toSet());
- // 鏀堕泦鍓嶇浠嶇劧瀛樺湪鐨勮妭鐐笽D
- Set<Long> frontendIds = new HashSet<>();
- for (ProductionBomStructureDto item : flatDtoList) {
- if (item.getId() != null) {
- frontendIds.add(item.getId());
- }
- }
-
- // 璁$畻闇�瑕佸垹闄ょ殑鑺傜偣锛堟暟鎹簱鏈夈�佸墠绔凡鍒犻櫎锛�
- Set<Long> deleteIds = new HashSet<>();
- for (ProductionBomStructure dbItem : dbList) {
- if (!frontendIds.contains(dbItem.getId())) {
- deleteIds.add(dbItem.getId());
- }
- }
- // 鍏堝垹鎺夊墠绔凡缁忕Щ闄ょ殑鑺傜偣
- if (!deleteIds.isEmpty()) {
- this.removeByIds(deleteIds);
- }
-
- // 鎸夋槸鍚︽湁ID鎷嗗垎涓烘柊澧炲拰鏇存柊锛屽悓鏃剁紦瀛樻柊澧炶妭鐐圭殑涓存椂ID鏄犲皠
+ Set<Long> submittedIds = new HashSet<>();
+ Set<String> relationKeys = new HashSet<>();
List<ProductionBomStructure> insertList = new ArrayList<>();
List<ProductionBomStructure> updateList = new ArrayList<>();
- Map<String, ProductionBomStructure> tempEntityMap = new HashMap<>();
- for (ProductionBomStructureDto item : flatDtoList) {
+ for (ProductionBomStructureDto item : detailList) {
+ Long productModelId = item.getProductModelId();
+ Long technologyOperationId = item.getTechnologyOperationId();
+ if (productModelId == null) {
+ throw new ServiceException("璇烽�夋嫨鐗╂枡瑙勬牸");
+ }
+ if (productModelMapper.selectById(productModelId) == null) {
+ throw new ServiceException("鐗╂枡瑙勬牸涓嶅瓨鍦�");
+ }
+ if (technologyOperationId == null) {
+ throw new ServiceException("璇烽�夋嫨娑堣�楀伐搴�");
+ }
+ if (technologyOperationMapper.selectById(technologyOperationId) == null) {
+ throw new ServiceException("娑堣�楀伐搴忎笉瀛樺湪");
+ }
+ if (productModelId.equals(orderBom.getProductModelId())) {
+ throw new ServiceException("鎴愬搧瑙勬牸涓嶈兘浣滀负鑷韩鐨勭墿鏂�");
+ }
+ if (!relationKeys.add(productModelId + "#" + technologyOperationId)) {
+ throw new ServiceException("鍚屼竴鐗╂枡瑙勬牸鍦ㄥ悓涓�宸ュ簭涓嬩笉鑳介噸澶嶉厤缃�");
+ }
+
ProductionBomStructure entity = new ProductionBomStructure();
- BeanUtils.copyProperties(item, entity);
entity.setProductionOrderBomId(orderBomId);
+ entity.setProductionOrderId(productionOrderId);
+ entity.setProductModelId(productModelId);
+ entity.setTechnologyOperationId(technologyOperationId);
+ // 鎵佸钩蹇収涓嶅啀浣跨敤灞傜骇涓庢暟閲忚涔�
+ entity.setParentId(null);
+ entity.setUnitQuantity(null);
+ entity.setDemandedQuantity(null);
+ entity.setUnit(null);
+
if (item.getId() == null) {
- entity.setParentId(null);
insertList.add(entity);
- tempEntityMap.put(item.getTempId(), entity);
} else {
+ if (!dbIds.contains(item.getId())) {
+ throw new ServiceException("璁㈠崟BOM鐗╂枡鏄庣粏涓嶅瓨鍦ㄦ垨涓嶅睘浜庡綋鍓嶈鍗旴OM");
+ }
+ entity.setId(item.getId());
+ submittedIds.add(item.getId());
updateList.add(entity);
}
}
- // 鎵归噺鏂板锛屾嬁鍒版暟鎹簱鐢熸垚鐨勭湡瀹濱D
+ Set<Long> deleteIds = new HashSet<>(dbIds);
+ deleteIds.removeAll(submittedIds);
+ if (!deleteIds.isEmpty()) {
+ this.removeByIds(deleteIds);
+ }
+ if (!updateList.isEmpty()) {
+ this.updateBatchById(updateList);
+ }
if (!insertList.isEmpty()) {
this.saveBatch(insertList);
}
- // 鏂板鑺傜偣浜屾鍥炲啓鐖禝D锛堝墠绔紶鐨勬槸涓存椂鐖禝D锛�
- List<ProductionBomStructure> parentFixList = new ArrayList<>();
- for (ProductionBomStructureDto item : flatDtoList) {
- if (item.getId() == null && item.getParentTempId() != null) {
- ProductionBomStructure child = tempEntityMap.get(item.getTempId());
- if (child == null) {
- continue;
- }
- ProductionBomStructure parent = tempEntityMap.get(item.getParentTempId());
- // 鐖惰妭鐐规槸鏈鏂板鏃讹紝鐩存帴鐢ㄦ柊澧炲悗鐨勭湡瀹濱D锛涘惁鍒欏洖閫�涓哄墠绔紶鍏ョ埗ID
- Long realParentId = parent != null ? parent.getId() : Long.valueOf(item.getParentTempId());
- child.setParentId(realParentId);
- parentFixList.add(child);
- }
- }
-
- // 鍥炲啓鏂板鑺傜偣鐨勭埗瀛愬叧绯�
- if (!parentFixList.isEmpty()) {
- this.updateBatchById(parentFixList);
- }
- // 鎵归噺鏇存柊宸叉湁鑺傜偣
- if (!updateList.isEmpty()) {
- this.updateBatchById(updateList);
- }
- syncDemandedQuantityAndTaskPlanQuantity(orderBomId, dto.getProductionOrderId());
+ syncRoutingAndTaskByStructure(orderBomId, productionOrderId);
return true;
}
- private void syncDemandedQuantityAndTaskPlanQuantity(Long orderBomId, Long productionOrderId) {
+ /**
+ * 璁㈠崟BOM鐗╂枡鍙樺寲鍚庯紝鎸夊叾宸ュ簭闆嗗悎閲嶅缓璁㈠崟宸ヨ壓璺嚎宸ュ簭蹇収涓庡伐鍗曡鍒掓暟閲忋��
+ */
+ private void syncRoutingAndTaskByStructure(Long orderBomId, Long productionOrderId) {
if (orderBomId == null) {
return;
}
@@ -194,55 +208,20 @@
return;
}
- BigDecimal orderQuantity = defaultDecimal(productionOrder.getQuantity());
List<ProductionBomStructure> structureList = this.list(
Wrappers.<ProductionBomStructure>lambdaQuery()
.eq(ProductionBomStructure::getProductionOrderBomId, orderBomId)
.orderByAsc(ProductionBomStructure::getId));
- //鍚屾闇�姹傛暟閲�
- syncStructureDemandedQuantity(structureList, orderQuantity);
- Long rootProductModelId = orderBom.getProductModelId() != null ? orderBom.getProductModelId() : productionOrder.getProductModelId();
- //鍚屾鐢熶骇宸ヨ壓璺嚎
+ Long rootProductModelId = orderBom.getProductModelId() != null
+ ? orderBom.getProductModelId()
+ : productionOrder.getProductModelId();
+ // 鍚屾鐢熶骇宸ヨ壓璺嚎蹇収
syncRoutingOperationsByBom(currentProductionOrderId, productionOrder, orderBom, structureList, rootProductModelId);
- //鍚屾宸ュ崟
- syncTaskPlanQuantity(
- currentProductionOrderId,
- structureList,
- orderQuantity,
- rootProductModelId);
+ // 鍚屾宸ュ崟璁″垝鏁伴噺锛氭墎骞矪OM鏃犳暟閲忛厤缃紝璁″垝鏁伴噺缁熶竴鍙栬鍗曟暟閲�
+ syncTaskPlanQuantity(currentProductionOrderId, TaskPlanQuantityUtil.resolveTaskPlanQuantity(productionOrder));
}
- private void syncStructureDemandedQuantity(List<ProductionBomStructure> structureList, BigDecimal orderQuantity) {
- if (structureList == null || structureList.isEmpty()) {
- return;
- }
- List<ProductionBomStructure> updateList = new ArrayList<>();
- BigDecimal lastProcessDemandedQuantity = orderQuantity;
- for (ProductionBomStructure structure : structureList) {
- if (structure == null || structure.getId() == null) {
- continue;
- }
-
- BigDecimal demandedQuantity = lastProcessDemandedQuantity.multiply(defaultDecimal(structure.getUnitQuantity()));
-// if (compareDecimal(structure.getDemandedQuantity(), demandedQuantity) == 0) {
-// continue;
-// }
- ProductionBomStructure update = new ProductionBomStructure();
- update.setId(structure.getId());
- update.setDemandedQuantity(demandedQuantity);
- updateList.add(update);
- structure.setDemandedQuantity(demandedQuantity);
- lastProcessDemandedQuantity = demandedQuantity;
- }
- if (!updateList.isEmpty()) {
- this.updateBatchById(updateList);
- }
- }
-
- private void syncTaskPlanQuantity(Long productionOrderId,
- List<ProductionBomStructure> structureList,
- BigDecimal orderQuantity,
- Long rootProductModelId) {
+ private void syncTaskPlanQuantity(Long productionOrderId, BigDecimal planQuantity) {
List<ProductionOperationTask> taskList = productionOperationTaskMapper.selectList(
Wrappers.<ProductionOperationTask>lambdaQuery()
.eq(ProductionOperationTask::getProductionOrderId, productionOrderId)
@@ -250,33 +229,10 @@
if (taskList == null || taskList.isEmpty()) {
return;
}
- Set<Long> routingOperationIds = taskList.stream()
- .map(ProductionOperationTask::getProductionOrderRoutingOperationId)
- .filter(Objects::nonNull)
- .collect(Collectors.toSet());
- if (routingOperationIds.isEmpty()) {
- return;
- }
- Map<Long, ProductionOrderRoutingOperation> routingOperationMap = productionOrderRoutingOperationMapper
- .selectBatchIds(routingOperationIds)
- .stream()
- .filter(item -> item != null && item.getId() != null)
- .collect(Collectors.toMap(ProductionOrderRoutingOperation::getId, item -> item, (left, right) -> left));
- // Keep task plan quantities aligned with the same order BOM snapshot demand used during snapshot creation.
- Map<String, BigDecimal> demandedQuantityMap = TaskPlanQuantityUtil.buildOperationDemandedQuantityMap(structureList, rootProductModelId);
for (ProductionOperationTask task : taskList) {
- if (task == null || task.getId() == null || task.getProductionOrderRoutingOperationId() == null) {
+ if (task == null || task.getId() == null) {
continue;
}
- ProductionOrderRoutingOperation routingOperation = routingOperationMap.get(task.getProductionOrderRoutingOperationId());
- if (routingOperation == null) {
- continue;
- }
- BigDecimal planQuantity = resolveTaskPlanQuantity(
- routingOperation,
- demandedQuantityMap,
- orderQuantity,
- rootProductModelId);
if (compareDecimal(task.getPlanQuantity(), planQuantity) == 0) {
continue;
}
@@ -292,15 +248,8 @@
ProductionOrderBom orderBom,
List<ProductionBomStructure> structureList,
Long rootProductModelId) {
- // 閲嶆柊鏌ヨBOM缁撴瀯锛屾寜瀛愯妭鐐逛紭鍏堟帓搴�
- List<ProductionBomStructure> routingStructureList = this.list(
- Wrappers.<ProductionBomStructure>lambdaQuery()
- .eq(ProductionBomStructure::getProductionOrderBomId, orderBom.getId())
- .orderByDesc(ProductionBomStructure::getParentId)
- .orderByAsc(ProductionBomStructure::getId));
-
ProductionOrderRouting orderRouting = getOrCreateOrderRoutingSnapshot(productionOrderId, productionOrder, orderBom, rootProductModelId);
- List<ProductionOrderRoutingOperation> desiredOperationList = buildDesiredRoutingOperationList(routingStructureList, rootProductModelId);
+ List<ProductionOrderRoutingOperation> desiredOperationList = buildDesiredRoutingOperationList(structureList, rootProductModelId);
List<ProductionOrderRoutingOperation> existingOperationList = productionOrderRoutingOperationMapper.selectList(
Wrappers.<ProductionOrderRoutingOperation>lambdaQuery()
.eq(ProductionOrderRoutingOperation::getOrderRoutingId, orderRouting.getId())
@@ -381,30 +330,30 @@
return orderRouting;
}
+ /**
+ * 鎵佸钩BOM鎸夊伐搴忓幓閲嶇敓鎴愭湡鏈涚殑璁㈠崟宸ュ簭鍒楄〃锛�
+ * 椤哄簭鍙栫墿鏂欐槑缁嗕腑宸ュ簭棣栨鍑虹幇鐨勯『搴忥紝浜у嚭瑙勬牸鍥哄畾涓鸿鍗曟垚鍝佽鏍笺��
+ */
private List<ProductionOrderRoutingOperation> buildDesiredRoutingOperationList(List<ProductionBomStructure> structureList,
Long rootProductModelId) {
if (structureList == null || structureList.isEmpty()) {
return Collections.emptyList();
}
- Map<Long, ProductionBomStructure> structureById = structureList.stream()
- .filter(item -> item != null && item.getId() != null)
- .collect(Collectors.toMap(ProductionBomStructure::getId, item -> item, (left, right) -> left));
+ Set<Long> uniqueOperationIdList = new LinkedHashSet<>();
+ for (ProductionBomStructure structure : structureList) {
+ if (structure == null || structure.getTechnologyOperationId() == null) {
+ continue;
+ }
+ uniqueOperationIdList.add(structure.getTechnologyOperationId());
+ }
- // 鏋勫缓鐖�-瀛愭槧灏勫叧绯�
- Map<Long, List<ProductionBomStructure>> treeMap = buildParentChildMap(structureList);
-
- // 浣跨敤鍚庡簭閬嶅巻鏋勫缓鎿嶄綔鍒楄〃锛堝厛瀛愬悗鐖讹紝纭繚宸ヨ壓璺嚎椤哄簭姝g‘锛�
- Map<String, ProductionBomStructure> uniqueOperationMap = new LinkedHashMap<>();
- buildOperationListPostOrder(null, treeMap, uniqueOperationMap, structureById, rootProductModelId);
-
- List<ProductionOrderRoutingOperation> desiredOperationList = new ArrayList<>();
+ List<ProductionOrderRoutingOperation> desiredOperationList = new ArrayList<>(uniqueOperationIdList.size());
int dragSort = 1;
- for (ProductionBomStructure bomStructure : uniqueOperationMap.values()) {
- Long outputProductModelId = resolveOutputProductModelId(resolveOperationOutputNode(bomStructure, structureById), rootProductModelId);
- TechnologyOperation technologyOperation = getTechnologyOperation(bomStructure.getTechnologyOperationId());
+ for (Long operationId : uniqueOperationIdList) {
+ TechnologyOperation technologyOperation = getTechnologyOperation(operationId);
ProductionOrderRoutingOperation routingOperation = new ProductionOrderRoutingOperation();
- routingOperation.setProductModelId(outputProductModelId);
- routingOperation.setTechnologyOperationId(bomStructure.getTechnologyOperationId());
+ routingOperation.setProductModelId(rootProductModelId);
+ routingOperation.setTechnologyOperationId(operationId);
routingOperation.setOperationName(technologyOperation == null ? null : technologyOperation.getName());
routingOperation.setIsQuality(technologyOperation == null ? null : technologyOperation.getIsQuality());
routingOperation.setIsProduction(technologyOperation == null ? null : technologyOperation.getIsProduction());
@@ -413,52 +362,6 @@
desiredOperationList.add(routingOperation);
}
return desiredOperationList;
- }
-
- private Map<Long, List<ProductionBomStructure>> buildParentChildMap(List<ProductionBomStructure> structureList) {
- Map<Long, List<ProductionBomStructure>> treeMap = new LinkedHashMap<>();
- Map<Long, Integer> childCountMap = new HashMap<>();
-
- // 绗竴閬嶏細缁熻姣忎釜鑺傜偣鐨勫瓙鑺傜偣鏁伴噺锛屽悓鏃舵瀯寤哄垵濮嬫槧灏�
- for (ProductionBomStructure structure : structureList) {
- if (structure == null) continue;
- Long parentId = structure.getParentId();
- childCountMap.merge(parentId, 1, Integer::sum); // 缁熻姣忎釜鐖惰妭鐐规湁澶氬皯涓瓙鑺傜偣
- treeMap.computeIfAbsent(parentId, k -> new ArrayList<>()).add(structure);
- }
-
- // 绗簩閬嶏細瀵规瘡涓埗鑺傜偣涓嬬殑瀛愯妭鐐规寜瀛愯妭鐐规暟閲忓�掑簭鎺掑簭锛堟湁瀛愯妭鐐圭殑浼樺厛锛�
- for (Map.Entry<Long, List<ProductionBomStructure>> entry : treeMap.entrySet()) {
- List<ProductionBomStructure> children = entry.getValue();
- children.sort((a, b) -> {
- int countA = childCountMap.getOrDefault(a.getId(), 0);
- int countB = childCountMap.getOrDefault(b.getId(), 0);
- return Integer.compare(countB, countA); // 瀛愯妭鐐瑰鐨勬帓鍓嶉潰
- });
- }
-
- return treeMap;
- }
-
- private void buildOperationListPostOrder(Long parentId,
- Map<Long, List<ProductionBomStructure>> treeMap,
- Map<String, ProductionBomStructure> uniqueOperationMap,
- Map<Long, ProductionBomStructure> structureById,
- Long rootProductModelId) {
- List<ProductionBomStructure> children = treeMap.get(parentId);
- if (children == null || children.isEmpty()) {
- return;
- }
- for (ProductionBomStructure child : children) {
- // 鍏堥�掑綊澶勭悊瀛愯妭鐐�
- buildOperationListPostOrder(child.getId(), treeMap, uniqueOperationMap, structureById, rootProductModelId);
-
- // 鍐嶅鐞嗗綋鍓嶈妭鐐�
- if (child.getTechnologyOperationId() != null) {
- Long outputProductModelId = resolveOutputProductModelId(resolveOperationOutputNode(child, structureById), rootProductModelId);
- uniqueOperationMap.putIfAbsent(buildBomOperationDedupKey(child, outputProductModelId), child);
- }
- }
}
private Map<String, Deque<ProductionOrderRoutingOperation>> buildExistingRoutingOperationBucketMap(List<ProductionOrderRoutingOperation> existingOperationList) {
@@ -536,12 +439,6 @@
if (!Objects.equals(currentOperation.getIsProduction(), desiredOperation.getIsProduction())) {
update.setIsProduction(desiredOperation.getIsProduction());
currentOperation.setIsProduction(desiredOperation.getIsProduction());
- changed = true;
- }
- // 鏇存柊 dragSort 瀛楁锛岀‘淇濆伐鑹鸿矾绾块『搴忔纭�
- if (!Objects.equals(currentOperation.getDragSort(), desiredOperation.getDragSort())) {
- update.setDragSort(desiredOperation.getDragSort());
- currentOperation.setDragSort(desiredOperation.getDragSort());
changed = true;
}
if (!Objects.equals(currentOperation.getType(), desiredOperation.getType())) {
@@ -631,7 +528,7 @@
return;
}
if (defaultDecimal(task.getCompleteQuantity()).compareTo(BigDecimal.ZERO) > 0) {
- throw new ServiceException("宸ュ簭宸蹭骇鐢熸姤宸ヨ褰曪紝鏃犳硶鏍规嵁 BOM 鍙樻洿鍒犻櫎瀵瑰簲宸ュ簭蹇収");
+ throw new ServiceException("宸ュ簭宸蹭骇鐢熸姤宸ヨ褰曪紝鏃犳硶鏍规嵁 BOM 鍙樻洿鍒犻櫎瀵瑰簲宸ュ簭蹇収" + task.getWorkOrderNo());
}
long reportCount = productionProductMainMapper.selectCount(
Wrappers.<ProductionProductMain>lambdaQuery()
@@ -672,94 +569,8 @@
}
}
- private Map<String, BigDecimal> buildOperationDemandedQuantityMap(List<ProductionBomStructure> structureList,
- Long rootProductModelId) {
- if (structureList == null || structureList.isEmpty()) {
- return Collections.emptyMap();
- }
- Map<Long, ProductionBomStructure> structureById = structureList.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 : structureList) {
- if (bomStructure == null || bomStructure.getTechnologyOperationId() == null) {
- continue;
- }
- // Resolve the output node first, then read the output node demand for the task plan quantity.
- 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;
- }
- // Multiple input rows can point to the same output node, so only count that output demand once.
- String key = buildOperationDemandedQuantityKey(bomStructure.getTechnologyOperationId(), outputProductModelId);
- demandedQuantityMap.merge(key, defaultDecimal(outputNode == null ? null : outputNode.getDemandedQuantity()), BigDecimal::add);
- }
- return demandedQuantityMap;
- }
-
- private BigDecimal resolveTaskPlanQuantity(ProductionOrderRoutingOperation routingOperation,
- Map<String, BigDecimal> demandedQuantityMap,
- BigDecimal orderQuantity,
- Long rootProductModelId) {
- if (routingOperation == null || demandedQuantityMap == null || demandedQuantityMap.isEmpty()) {
- return orderQuantity;
- }
- Long outputProductModelId = routingOperation.getProductModelId() != null
- ? routingOperation.getProductModelId()
- : rootProductModelId;
- String key = buildOperationDemandedQuantityKey(
- routingOperation.getTechnologyOperationId(),
- outputProductModelId);
- BigDecimal planQuantity = demandedQuantityMap.get(key);
- return planQuantity != null ? planQuantity : orderQuantity;
- }
-
- private String buildOperationDemandedQuantityKey(Long operationId, Long outputProductModelId) {
- return String.valueOf(operationId) + "#" + String.valueOf(outputProductModelId);
- }
-
private String buildRoutingOperationBucketKey(Long operationId, Long outputProductModelId) {
return String.valueOf(operationId) + "#" + String.valueOf(outputProductModelId);
- }
-
- private String buildBomOperationDedupKey(ProductionBomStructure bomStructure, Long outputProductModelId) {
- Long operationId = bomStructure == null ? null : bomStructure.getTechnologyOperationId();
- Long parentId = bomStructure == null ? null : bomStructure.getParentId();
- return operationId + "#" + outputProductModelId + "#" + parentId;
- }
-
- 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; other 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;
}
private TechnologyOperation getTechnologyOperation(Long technologyOperationId) {
@@ -793,20 +604,6 @@
private int compareDecimal(BigDecimal left, BigDecimal right) {
return defaultDecimal(left).compareTo(defaultDecimal(right));
- }
-
- /**
- * 灏嗘爲褰㈢粨鏋勬媿骞虫垚鍒楄〃锛屼究浜庣粺涓�淇濆瓨銆�
- */
- private void flattenTree(List<ProductionBomStructureDto> source, List<ProductionBomStructureDto> result) {
- // 鎵佸钩鍖栧鐞嗘爲
- if (source == null) {
- return;
- }
- for (ProductionBomStructureDto node : source) {
- flattenTree(node.getChildren(), result); // 鍏堥�掑綊娣诲姞瀛愯妭鐐�
- result.add(node);
- }
}
}
--
Gitblit v1.9.3