From 2c51e2bac7e271f6bd1a7da060e4ffd327d5a8d2 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期二, 28 四月 2026 18:06:06 +0800
Subject: [PATCH] feat(production): 更新生产核算逻辑以支持设备和工时计算

---
 src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
index 343f790..58f14d8 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
@@ -17,9 +17,11 @@
 import com.ruoyi.production.service.ProductOrderService;
 import com.ruoyi.production.service.ProductProcessService;
 import com.ruoyi.production.service.ProductWorkOrderService;
+import com.ruoyi.production.service.ProductionPrintOrderService;
 import com.ruoyi.quality.mapper.QualityInspectMapper;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -29,6 +31,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -37,6 +40,10 @@
 
     private final ProductWorkOrderService productWorkOrderService;
     private final ProductProcessService productProcessService;
+
+    @Autowired
+    @Lazy
+    private ProductionPrintOrderService  productionPrintOrderService;
     @Autowired
     private ProductOrderMapper productOrderMapper;
     @Autowired
@@ -64,7 +71,21 @@
 
     @Override
     public IPage<ProductOrderDto> pageProductOrder(Page page, ProductOrderDto productOrder) {
-        return productOrderMapper.pageProductOrder(page, productOrder);
+        IPage<ProductOrderDto> productOrderDtoIPage = productOrderMapper.pageProductOrder(page, productOrder);
+        // 濉厖鍗板埛鍗曚俊鎭�
+        List<ProductOrderDto> records = productOrderDtoIPage.getRecords();
+        if (CollUtil.isNotEmpty(records)) {
+            List<Long> orderIds = records.stream().map(ProductOrderDto::getId).collect(Collectors.toList());
+            Map<Long, ProductionPrintOrder> collect = productionPrintOrderService.getListByOrders(orderIds).stream().collect(Collectors.toMap(ProductionPrintOrder::getProductOrderId, Function.identity()));
+            records.forEach(record -> {
+                ProductionPrintOrder productionPrintOrder = collect.get(record.getId());
+                if (productionPrintOrder != null) {
+                    productionPrintOrder.convertProductOrderDto(record);
+                }
+            });
+        }
+
+        return productOrderDtoIPage;
     }
 
     @Override
@@ -103,7 +124,7 @@
                 productWorkOrder.setProductOrderId(productOrder.getId());
                 ProductOrder order = productOrderMapper.selectById(productOrder.getId());
                 productWorkOrder.setPlanQuantity(order.getQuantity());
-                productWorkOrder.setWorkOrderNo(productWorkOrderService.generateProductWorkOrder(null, productProcessMap.getOrDefault(productProcessRouteItem.getProcessId(), new ProductProcess()).getName(), productOrder.getNpsNo()));
+                productWorkOrder.setWorkOrderNo(productWorkOrderService.generateProductWorkOrder( productProcessMap.getOrDefault(productProcessRouteItem.getProcessId(), new ProductProcess()).getName(), productOrder.getNpsNo()));
                 productWorkOrder.setStatus(1);
                 productWorkOrderMapper.insert(productWorkOrder);
             }
@@ -192,8 +213,8 @@
         return "SC" + datePrefix + formatOrderSequence(datePrefix);
     }
 
-    public String generateNextOrderByContractNo(String datePrefix, String contractNo) {
-        return contractNo + formatOrderSequence(datePrefix);
+    public String generateNextOrderByContractNo(String contractNo) {
+        return contractNo + formatOrderSequenceByContractNo(contractNo);
     }
 
     private String formatOrderSequence(String datePrefix) {
@@ -212,4 +233,12 @@
         return String.format("%04d", sequence);
     }
 
+
+    private String formatOrderSequenceByContractNo(String contractNo) {
+        LambdaQueryWrapper<ProductOrder> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.likeRight(ProductOrder::getNpsNo, contractNo);
+        Long count = productOrderMapper.selectCount(queryWrapper);
+        return String.format("%04d", count+1);
+    }
+
 }

--
Gitblit v1.9.3