From 0989ec1e6b465141f99ed67e40fa2a0b928dce94 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 29 四月 2026 16:54:51 +0800
Subject: [PATCH] feat(production): 新增生产核算和生产工单功能模块 - 添加生产核算控制器、服务接口及实现类 - 实现生产核算分页查询和工人生产工资信息查询功能 - 添加生产工单控制器、服务接口及实现类 - 实现生产工单的增删改查和状态统计功能 - 集成工单流转卡下载和二维码生成功能 - 添加工单相关的数据传输对象和值对象 - 实现工单与用户关联的分配功能 - 完善工单附件图片处理和展示功能

---
 src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java |  273 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 162 insertions(+), 111 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 b05665f..f994bb6 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
@@ -15,15 +15,18 @@
 import com.ruoyi.common.constant.StorageAttachmentConstants;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.production.bean.dto.ProductionOrderDto;
+import com.ruoyi.production.bean.vo.ProductionBomStructureVo;
+import com.ruoyi.production.bean.vo.ProductionOrderPickVo;
 import com.ruoyi.production.bean.vo.ProductionOrderVo;
+import com.ruoyi.production.bean.vo.ProductionPlanVo;
 import com.ruoyi.production.enums.ProductOrderStatusEnum;
 import com.ruoyi.production.mapper.*;
 import com.ruoyi.production.pojo.*;
 import com.ruoyi.production.service.ProductionOrderService;
 import com.ruoyi.sales.mapper.SalesLedgerMapper;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
-import com.ruoyi.sales.pojo.SalesLedger;
-import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import com.ruoyi.stock.mapper.StockInventoryMapper;
+import com.ruoyi.stock.pojo.StockInventory;
 import com.ruoyi.technology.mapper.*;
 import com.ruoyi.technology.pojo.*;
 import lombok.RequiredArgsConstructor;
@@ -51,6 +54,7 @@
     private final ProductionOrderPickMapper productionOrderPickMapper;
     private final ProductionOrderPickRecordMapper productionOrderPickRecordMapper;
     private final ProductionPlanMapper productionPlanMapper;
+    private final StockInventoryMapper stockInventoryMapper;
     private final StorageAttachmentMapper storageAttachmentMapper;
     private final StorageBlobMapper storageBlobMapper;
     private final SalesLedgerMapper salesLedgerMapper;
@@ -105,7 +109,6 @@
         if (!saved) {
             return false;
         }
-        syncProductionPlanIssueStatus(oldOrder, productionOrder);
         boolean needSync = productionOrder.getTechnologyRoutingId() != null
                 && (oldOrder == null
                 || !Objects.equals(oldOrder.getTechnologyRoutingId(), productionOrder.getTechnologyRoutingId())
@@ -114,11 +117,7 @@
                 || productionOrderRoutingMapper.selectCount(Wrappers.<ProductionOrderRouting>lambdaQuery()
                         .eq(ProductionOrderRouting::getProductionOrderId, productionOrder.getId())) == 0);
         if (needSync) {
-            // 宸ヨ壓銆佷骇鍝佹垨鏁伴噺鍙樺寲鍚庯紝璁㈠崟蹇収蹇呴』鍜屽綋鍓嶄笅鍗曟暟鎹噸鏂板榻愩��
             syncProductionOrderSnapshot(productionOrder.getId());
-        } else {
-            // 鏈噸寤哄揩鐓ф椂锛屼篃瑕佺‘淇濆鏂欎富鍗曞拰璁㈠崟鏁伴噺淇濇寔鍚屾銆�
-            upsertOrderPick(productionOrder);
         }
         return true;
     }
@@ -180,6 +179,16 @@
     }
 
     @Override
+    public List<ProductionPlanVo> getSource(Long id) {
+        ProductionOrder productionOrder = baseMapper.selectById(id);
+        if (productionOrder != null && productionOrder.getProductionPlanIds() != null) {
+            List<Long> planIds = parsePlanIds(productionOrder.getProductionPlanIds());
+            return productionPlanMapper.getSource(planIds);
+        }
+        return null;
+    }
+
+    @Override
     public int syncProductionOrderSnapshot(Long productionOrderId) {
         ProductionOrder productionOrder = this.getById(productionOrderId);
         if (productionOrder == null) {
@@ -224,15 +233,16 @@
             ProductionOrderRoutingOperation targetOperation = new ProductionOrderRoutingOperation();
             targetOperation.setProductionOrderId(productionOrder.getId());
             targetOperation.setTechnologyRoutingOperationId(sourceOperation.getId());
-            targetOperation.setTechnologyRoutingId(orderRouting.getId());
+            targetOperation.setOrderRoutingId(orderRouting.getId());
             targetOperation.setProductModelId(sourceOperation.getProductModelId());
             targetOperation.setDragSort(sourceOperation.getDragSort());
             targetOperation.setIsQuality(sourceOperation.getIsQuality());
             targetOperation.setOperationName(operationNameMap.get(sourceOperation.getTechnologyOperationId()));
+            targetOperation.setTechnologyOperationId(sourceOperation.getTechnologyOperationId());
             productionOrderRoutingOperationMapper.insert(targetOperation);
 
             ProductionOperationTask task = new ProductionOperationTask();
-            task.setTechnologyRoutingOperationId(targetOperation.getId());
+            task.setProductionOrderRoutingOperationId(targetOperation.getId());
             task.setProductionOrderId(productionOrder.getId());
             task.setPlanQuantity(defaultDecimal(productionOrder.getQuantity()));
             task.setCompleteQuantity(BigDecimal.ZERO);
@@ -248,7 +258,7 @@
                 // 宸ュ簭鎵ц鍙傛暟鍚屾牱鍋氬揩鐓э紝閬垮厤宸ヨ壓鍙傛暟璋冩暣褰卞搷宸蹭笅杈捐鍗曘��
                 ProductionOrderRoutingOperationParam targetParam = new ProductionOrderRoutingOperationParam();
                 targetParam.setProductionOrderId(productionOrder.getId());
-                targetParam.setTechnologyRoutingOperationId(targetOperation.getId());
+                targetParam.setProductionOrderRoutingOperationId(targetOperation.getId());
                 targetParam.setTechnologyRoutingOperationParamId(sourceParam.getId());
                 targetParam.setParamId(sourceParam.getParamId());
                 targetParam.setTechnologyOperationId(sourceParam.getTechnologyOperationId());
@@ -265,8 +275,6 @@
                 syncedParamCount++;
             }
         }
-
-        upsertOrderPick(productionOrder);
         return syncedParamCount;
     }
 
@@ -289,10 +297,9 @@
         orderBom.setProductionOrderId(productionOrder.getId());
         orderBom.setBomId(Long.valueOf(technologyBom.getId()));
         orderBom.setProductModelId(root != null ? root.getProductModelId() : productionOrder.getProductModelId());
-        orderBom.setTechnologyOperationId(root == null ? null : root.getOperationId());
-        orderBom.setUnitQuantity(root != null && root.getUnitQuantity() != null ? root.getUnitQuantity() : BigDecimal.ONE);
-        orderBom.setDemandedQuantity(orderQuantity);
-        orderBom.setUnit(root == null ? null : root.getUnit());
+        orderBom.setRemark(technologyBom.getRemark());
+        orderBom.setBomNo(technologyBom.getBomNo());
+        orderBom.setVersion(technologyBom.getVersion());
         productionOrderBomMapper.insert(orderBom);
 
         Map<Long, Long> idMap = new HashMap<>();
@@ -305,7 +312,7 @@
             target.setProductModelId(source.getProductModelId());
             target.setTechnologyOperationId(source.getOperationId());
             target.setUnitQuantity(source.getUnitQuantity());
-            target.setDemandedQuantity(resolveBomDemandQuantity(source, orderQuantity));
+            target.setDemandedQuantity(source.getUnitQuantity().multiply(orderQuantity));
             target.setUnit(source.getUnit());
             productionBomStructureMapper.insert(target);
             idMap.put(source.getId(), target.getId());
@@ -354,7 +361,6 @@
         ProductionOrder query = dto == null ? new ProductionOrder() : dto;
         return Wrappers.<ProductionOrder>lambdaQuery()
                 .eq(query.getId() != null, ProductionOrder::getId, query.getId())
-                .eq(query.getSalesLedgerId() != null, ProductionOrder::getSalesLedgerId, query.getSalesLedgerId())
                 .eq(query.getProductModelId() != null, ProductionOrder::getProductModelId, query.getProductModelId())
                 .eq(query.getTechnologyRoutingId() != null, ProductionOrder::getTechnologyRoutingId, query.getTechnologyRoutingId())
                 .like(query.getNpsNo() != null && !query.getNpsNo().trim().isEmpty(), ProductionOrder::getNpsNo, query.getNpsNo())
@@ -406,7 +412,6 @@
         if (productionOrder == null) {
             throw new ServiceException("鐢熶骇璁㈠崟涓嶈兘涓虹┖");
         }
-        fillFromSalesLedgerProduct(productionOrder);
         fillFromProductionPlans(productionOrder);
         if (productionOrder.getProductModelId() == null) {
             throw new ServiceException("浜у搧瑙勬牸ID涓嶈兘涓虹┖");
@@ -414,54 +419,23 @@
         if (defaultDecimal(productionOrder.getQuantity()).compareTo(BigDecimal.ZERO) <= 0) {
             throw new ServiceException("涓嬪崟鏁伴噺蹇呴』澶т簬0");
         }
-//        if (productionOrder.getTechnologyRoutingId() == null) {
-//            // 鏈樉寮忔寚瀹氬伐鑹鸿矾绾挎椂锛屾寜浜у搧瑙勬牸閫夋渶鏂颁竴鏉″伐鑹轰綔涓洪粯璁よ矾绾裤��
-//            TechnologyRouting technologyRouting = technologyRoutingMapper.selectOne(
-//                    Wrappers.<TechnologyRouting>lambdaQuery()
-//                            .eq(TechnologyRouting::getProductModelId, productionOrder.getProductModelId())
-//                            .orderByDesc(TechnologyRouting::getId)
-//                            .last("limit 1"));
-//            if (technologyRouting == null) {
-//                throw new ServiceException("鏈壘鍒拌浜у搧瑙勬牸瀵瑰簲鐨勫伐鑹鸿矾绾�");
-//            }
-//            productionOrder.setTechnologyRoutingId(technologyRouting.getId());
-//        }
+        if (productionOrder.getTechnologyRoutingId() == null) {
+            // 鏈樉寮忔寚瀹氬伐鑹鸿矾绾挎椂锛屾寜浜у搧瑙勬牸閫夋渶鏂颁竴鏉″伐鑹轰綔涓洪粯璁よ矾绾裤��
+            TechnologyRouting technologyRouting = technologyRoutingMapper.selectOne(
+                    Wrappers.<TechnologyRouting>lambdaQuery()
+                            .eq(TechnologyRouting::getProductModelId, productionOrder.getProductModelId())
+                            .orderByDesc(TechnologyRouting::getId)
+                            .last("limit 1"));
+            if (technologyRouting != null) {
+                productionOrder.setTechnologyRoutingId(technologyRouting.getId());
+            }
+        }
         if (oldOrder != null && ProductOrderStatusEnum.isStarted(oldOrder.getStatus())) {
             // 寮�宸ュ悗鍙厑璁镐慨姝i潪鏍稿績瀛楁锛屾牳蹇冪敓浜т緷鎹攣瀹氥��
             if (!Objects.equals(oldOrder.getProductModelId(), productionOrder.getProductModelId())
                     || !Objects.equals(oldOrder.getTechnologyRoutingId(), productionOrder.getTechnologyRoutingId())
                     || compareDecimal(oldOrder.getQuantity(), productionOrder.getQuantity()) != 0) {
                 throw new ServiceException("鐢熶骇璁㈠崟宸插紑宸ワ紝涓嶈兘淇敼浜у搧銆佸伐鑹鸿矾绾挎垨鏁伴噺");
-            }
-        }
-    }
-
-    private void fillFromSalesLedgerProduct(ProductionOrder productionOrder) {
-        if (productionOrder.getSalesLedgerProductId() == null) {
-            return;
-        }
-        // 閿�鍞槑缁嗘槸璁㈠崟鏉ユ簮鏃讹紝浠ラ攢鍞槑缁嗕负鍑嗗洖濉攢鍞彴璐︺�佷骇鍝佽鏍煎拰榛樿鏁伴噺銆�
-        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(productionOrder.getSalesLedgerProductId().longValue());
-        if (salesLedgerProduct == null) {
-            throw new ServiceException("閿�鍞彴璐︿骇鍝佷笉瀛樺湪");
-        }
-        if (productionOrder.getSalesLedgerId() == null) {
-            productionOrder.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId());
-        } else if (!Objects.equals(productionOrder.getSalesLedgerId(), salesLedgerProduct.getSalesLedgerId())) {
-            throw new ServiceException("閿�鍞彴璐D涓庨攢鍞彴璐︿骇鍝佷笉涓�鑷�");
-        }
-        if (productionOrder.getProductModelId() == null) {
-            productionOrder.setProductModelId(salesLedgerProduct.getProductModelId());
-        } else if (!Objects.equals(productionOrder.getProductModelId(), salesLedgerProduct.getProductModelId())) {
-            throw new ServiceException("浜у搧瑙勬牸ID涓庨攢鍞彴璐︿骇鍝佷笉涓�鑷�");
-        }
-        if (productionOrder.getQuantity() == null || productionOrder.getQuantity().compareTo(BigDecimal.ZERO) <= 0) {
-            productionOrder.setQuantity(salesLedgerProduct.getQuantity());
-        }
-        if (productionOrder.getPlanCompleteTime() == null && productionOrder.getSalesLedgerId() != null) {
-            SalesLedger salesLedger = salesLedgerMapper.selectById(productionOrder.getSalesLedgerId());
-            if (salesLedger != null && salesLedger.getDeliveryDate() != null) {
-                productionOrder.setPlanCompleteTime(salesLedger.getDeliveryDate());
             }
         }
     }
@@ -476,6 +450,12 @@
         if (productionPlans.size() != planIds.size()) {
             throw new ServiceException("閮ㄥ垎鐢熶骇璁″垝涓嶅瓨鍦�");
         }
+        Map<Long, ProductionPlan> planMap = productionPlans.stream()
+                .collect(Collectors.toMap(ProductionPlan::getId, item -> item, (left, right) -> left));
+        ProductionPlan mainPlan = planMap.get(planIds.get(0));
+        if (mainPlan == null) {
+            throw new ServiceException("涓荤敓浜ц鍒掍笉瀛樺湪");
+        }
         Set<Long> productModelIds = productionPlans.stream()
                 .map(ProductionPlan::getProductModelId)
                 .collect(Collectors.toSet());
@@ -485,7 +465,7 @@
         if (productionPlans.stream().anyMatch(item -> item.getStatus() != null && item.getStatus() == 2)) {
             throw new ServiceException("鎵�閫夌敓浜ц鍒掑凡涓嬪彂");
         }
-        ProductionPlan firstPlan = productionPlans.get(0);
+        ProductionPlan firstPlan = mainPlan;
         if (productionOrder.getProductModelId() == null) {
             productionOrder.setProductModelId(firstPlan.getProductModelId());
         } else if (!Objects.equals(productionOrder.getProductModelId(), firstPlan.getProductModelId())) {
@@ -507,76 +487,73 @@
         productionOrder.setProductionPlanIds(formatPlanIds(planIds));
     }
 
-    private void syncProductionPlanIssueStatus(ProductionOrder oldOrder, ProductionOrder newOrder) {
-        // 鍙鐞嗘湰娆″閲忓彉鍖栵紝閬垮厤鏃犲叧璁″垝琚噸澶嶅啓鐘舵�併��
-        Set<Long> oldIds = new LinkedHashSet<>(parsePlanIds(oldOrder == null ? null : oldOrder.getProductionPlanIds()));
-        Set<Long> newIds = new LinkedHashSet<>(parsePlanIds(newOrder == null ? null : newOrder.getProductionPlanIds()));
-        Set<Long> toRelease = new LinkedHashSet<>(oldIds);
-        toRelease.removeAll(newIds);
-        Set<Long> toIssue = new LinkedHashSet<>(newIds);
-        toIssue.removeAll(oldIds);
-        if (!toRelease.isEmpty()) {
-            updatePlanIssuedFlag(new ArrayList<>(toRelease), false);
-        }
-        if (!toIssue.isEmpty()) {
-            updatePlanIssuedFlag(new ArrayList<>(toIssue), true);
-        }
-    }
-
     private void releaseProductionPlanIssueStatus(ProductionOrder productionOrder) {
         if (productionOrder == null) {
             return;
         }
         List<Long> planIds = parsePlanIds(productionOrder.getProductionPlanIds());
         if (!planIds.isEmpty()) {
-            updatePlanIssuedFlag(planIds, false);
+            // 鐢熶骇璁㈠崟鍒犻櫎--瀵瑰簲鐨勭敓浜ц鍒掔殑宸蹭笅鍙戞暟閲忚鍑忓幓
+            updatePlanIssuedFlag(planIds, productionOrder.getQuantity());
         }
     }
 
-    private void updatePlanIssuedFlag(List<Long> planIds, boolean issued) {
+    //鐢熶骇璁㈠崟鍒犻櫎锛岀敓浜ц鍒掔殑宸蹭笅鍙戞暟閲忓搴斿彉鏇�
+    private void updatePlanIssuedFlag(List<Long> planIds, BigDecimal remainingAssignedQuantity) {
         if (planIds == null || planIds.isEmpty()) {
             return;
         }
         List<ProductionPlan> plans = productionPlanMapper.selectBatchIds(planIds);
+        //涓嬪彂鏁伴噺鍑忓幓
+        List<ProductionPlan> updates = new ArrayList<>();
         for (ProductionPlan plan : plans) {
+            BigDecimal requiredQuantity = Optional.ofNullable(plan.getQtyRequired()).orElse(BigDecimal.ZERO);
+            if (requiredQuantity.compareTo(BigDecimal.ZERO) < 0) {
+                requiredQuantity = BigDecimal.ZERO;
+            }
+            BigDecimal remainingQuantity = resolveRemainingQuantity(plan);
+            BigDecimal historicalIssuedQuantity = requiredQuantity.subtract(remainingQuantity);
+            BigDecimal issuedQuantity = remainingAssignedQuantity.min(historicalIssuedQuantity);
+            remainingAssignedQuantity = remainingAssignedQuantity.subtract(issuedQuantity);
+            BigDecimal totalIssuedQuantity = historicalIssuedQuantity.subtract(issuedQuantity);
+            int planStatus = resolvePlanStatus(requiredQuantity, totalIssuedQuantity);
             ProductionPlan update = new ProductionPlan();
             update.setId(plan.getId());
-            update.setIssued(issued);
-            productionPlanMapper.updateById(update);
+            update.setStatus(planStatus);
+            update.setQuantityIssued(totalIssuedQuantity);
+            updates.add(update);
+        }
+        if (!updates.isEmpty()) {
+            productionPlanMapper.updateById(updates);
         }
     }
 
-    private void upsertOrderPick(ProductionOrder productionOrder) {
-        if (productionOrder == null || productionOrder.getId() == null) {
-            return;
-        }
-        // 璁㈠崟涓嬭揪鍚庤嚜鍔ㄧ敓鎴愪竴寮犲鏂欎富鍗曪紝鍚庣画棰嗘枡璁板綍閮芥寕鍦ㄨ繖寮犲崟涓娿��
-        ProductionOrderPick orderPick = productionOrderPickMapper.selectOne(
-                Wrappers.<ProductionOrderPick>lambdaQuery()
-                        .eq(ProductionOrderPick::getProductionOrderId, productionOrder.getId())
-                        .last("limit 1"));
-        if (orderPick == null) {
-            orderPick = new ProductionOrderPick();
-            orderPick.setProductionOrderId(productionOrder.getId());
-        }
-        orderPick.setProductModelId(productionOrder.getProductModelId() == null ? null : Math.toIntExact(productionOrder.getProductModelId()));
-        orderPick.setQuantity(defaultDecimal(productionOrder.getQuantity()));
-        orderPick.setRemark("涓嬪崟鑷姩鐢熸垚");
-        if (orderPick.getId() == null) {
-            productionOrderPickMapper.insert(orderPick);
-        } else {
-            productionOrderPickMapper.updateById(orderPick);
-        }
-    }
-
-    private BigDecimal resolveBomDemandQuantity(TechnologyBomStructure source, BigDecimal orderQuantity) {
-        // 宸ヨ壓 BOM 涓殑闇�姹傞噺鎸夆�滃崟浠堕渶姹� * 璁㈠崟鏁伴噺鈥濆睍寮�鎴愯鍗曠骇闇�姹傘��
-        BigDecimal baseQuantity = source.getDemandedQuantity() != null ? source.getDemandedQuantity() : source.getUnitQuantity();
-        baseQuantity = baseQuantity == null ? BigDecimal.ZERO : baseQuantity;
-        if (baseQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+    private BigDecimal resolveRemainingQuantity(ProductionPlan plan) {
+        if (plan == null) {
             return BigDecimal.ZERO;
         }
-        return baseQuantity.multiply(orderQuantity);
+        BigDecimal requiredQuantity = Optional.ofNullable(plan.getQtyRequired()).orElse(BigDecimal.ZERO);
+        if (requiredQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+            return BigDecimal.ZERO;
+        }
+        BigDecimal issuedQuantity = Optional.ofNullable(plan.getQuantityIssued()).orElse(BigDecimal.ZERO);
+        if (issuedQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+            return requiredQuantity;
+        }
+        if (issuedQuantity.compareTo(requiredQuantity) >= 0) {
+            return BigDecimal.ZERO;
+        }
+        return requiredQuantity.subtract(issuedQuantity);
+    }
+
+    private int resolvePlanStatus(BigDecimal requiredQuantity, BigDecimal issuedQuantity) {
+        if (requiredQuantity == null || requiredQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+            return 0;
+        }
+        if (issuedQuantity == null || issuedQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+            return 0;
+        }
+        return issuedQuantity.compareTo(requiredQuantity) < 0 ? 1 : 2;
     }
 
     private List<Long> parsePlanIds(String productionPlanIds) {
@@ -682,4 +659,78 @@
         vo.setDownloadURL(fileUtil.buildSignedDownloadUrl(vo));
         return vo;
     }
+
+    @Override
+    public List<ProductionOrderPickVo> pick(Long productionOrderId) {
+        if (productionOrderId == null) {
+            return Collections.emptyList();
+        }
+
+        ProductionOrderBom orderBom = productionOrderBomMapper.selectOne(
+                Wrappers.<ProductionOrderBom>lambdaQuery()
+                        .eq(ProductionOrderBom::getProductionOrderId, productionOrderId)
+                        .orderByDesc(ProductionOrderBom::getId)
+                        .last("limit 1"));
+        if (orderBom == null || orderBom.getId() == null) {
+            return Collections.emptyList();
+        }
+
+        List<ProductionBomStructureVo> bomStructureList = productionBomStructureMapper.pickByBomId(orderBom.getId());
+        if (bomStructureList == null || bomStructureList.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        List<Long> productModelIds = bomStructureList.stream()
+                .map(ProductionBomStructureVo::getProductModelId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+        Map<Long, BigDecimal> stockQuantityMap = new HashMap<>();
+        Map<Long, LinkedHashSet<String>> stockBatchNoMap = new HashMap<>();
+        if (!productModelIds.isEmpty()) {
+            List<StockInventory> stockList = stockInventoryMapper.selectList(
+                    Wrappers.<StockInventory>lambdaQuery()
+                            .in(StockInventory::getProductModelId, productModelIds));
+            for (StockInventory stockItem : stockList) {
+                if (stockItem == null || stockItem.getProductModelId() == null) {
+                    continue;
+                }
+                Long productModelId = stockItem.getProductModelId();
+                stockQuantityMap.merge(productModelId, defaultDecimal(stockItem.getQualitity()), BigDecimal::add);
+                String batchNo = stockItem.getBatchNo();
+                if (batchNo != null && !batchNo.trim().isEmpty()) {
+                    stockBatchNoMap.computeIfAbsent(productModelId, key -> new LinkedHashSet<>()).add(batchNo);
+                }
+            }
+        }
+
+        Map<String, ProductionOrderPickVo> mergedPickMap = new LinkedHashMap<>();
+        for (ProductionBomStructureVo structure : bomStructureList) {
+            if (structure == null || structure.getProductModelId() == null) {
+                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())));
+        }
+        return new ArrayList<>(mergedPickMap.values());
+    }
 }

--
Gitblit v1.9.3