From aeb7d490c7fa55ae4861a43d256a5a9cf649d39c Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期三, 27 五月 2026 14:15:35 +0800
Subject: [PATCH] feat(ProductionPrintOrder) 工序改为9位

---
 src/main/java/com/ruoyi/production/service/impl/ProductionPrintOrderServiceImpl.java |   67 +++++++++++++++++++++++++++------
 1 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionPrintOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionPrintOrderServiceImpl.java
index 31219ca..a859165 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionPrintOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionPrintOrderServiceImpl.java
@@ -7,6 +7,7 @@
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -15,10 +16,11 @@
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.dto.SimplePersonDto;
 import com.ruoyi.production.dto.*;
-import com.ruoyi.production.mapper.ProductOrderMapper;
-import com.ruoyi.production.mapper.ProductionPrintOrderMapper;
-import com.ruoyi.production.pojo.ProductOrder;
-import com.ruoyi.production.pojo.ProductionPrintOrder;
+import com.ruoyi.production.mapper.*;
+import com.ruoyi.production.pojo.*;
+import com.ruoyi.production.service.ProductBomService;
+import com.ruoyi.production.service.ProductProcessRouteService;
+import com.ruoyi.production.service.ProductProcessService;
 import com.ruoyi.production.service.ProductionPrintOrderService;
 import lombok.RequiredArgsConstructor;
 import org.jetbrains.annotations.Nullable;
@@ -28,6 +30,7 @@
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -45,13 +48,34 @@
     private final ProductOrderMapper productOrderMapper;
     private final ProcessRouteServiceImpl processRouteService;
     private final ProductionPrintOrderExcel productionPrintOrderExcel;
+    private final ProductWorkOrderMapper productWorkOrderMapper;
+    private final ProductProcessRouteService productProcessRouteService;
+    private final ProductBomService productBomService;
 
     private final CustomerFollowUpFileService customerFollowUpFileService;
+    private final ProductProcessMapper productProcessMapper;
+    private final ProductProcessService productProcessService;
+
     @Override
     @Transactional
     public void save(SaveProductionPrintOrderDto dto) {
+        Assert.isFalse(CollUtil.isEmpty(dto.getProcessContent()),"鎯呰嚦灏戞坊鍔犱竴鏉″伐搴忎俊鎭�");
         ProductionPrintOrder productionPrintOrder = BeanUtil.copyProperties(dto, ProductionPrintOrder.class);
-
+        if(dto.getProductOrderId() != null){
+            // 鍏堝垹闄ょ敓浜у伐鍗曟暟鎹�
+            LambdaQueryWrapper<ProductWorkOrder> l1 = new LambdaQueryWrapper<>();
+            l1.eq(ProductWorkOrder::getProductOrderId,dto.getProductOrderId());
+            productWorkOrderMapper.delete(l1);
+            LambdaQueryWrapper<ProductProcessRoute> l2 = new LambdaQueryWrapper<>();
+            l2.eq(ProductProcessRoute::getProductOrderId,dto.getProductOrderId());
+            List<ProductProcessRoute> needDeleteRoute = productProcessRouteService.list(l2);
+            List<Long> needDeleteRouteIds = needDeleteRoute.stream().map(ProductProcessRoute::getId).collect(Collectors.toList());
+            if(CollUtil.isNotEmpty(needDeleteRouteIds)){
+                productProcessRouteService.removeBatchByIds(needDeleteRouteIds);
+                List<Integer> needDeleteBom = needDeleteRoute.stream().map(ProductProcessRoute::getBomId).collect(Collectors.toList());
+                productProcessRouteService.removeByIds(needDeleteBom);
+            }
+        }
         List<ProcessContentDto> processContentDtoList = productionPrintOrder.getProcessContent();
         // 缁欐病鏈塱d鐨勪俊鎭缃畊uid
         processContentDtoList.forEach(processContentDto -> {
@@ -61,6 +85,9 @@
         });
         MaterialInfoDto materialInfoDtoFirst = dto.getMaterialInfo().get(0);
         // 璋冪敤宸ュ簭鏂瑰 鍑芥暟
+        // 鏌ヨ宸ュ簭淇℃伅
+        List<Long> processIds = dto.getProcessContent().stream().map(ProcessContentDto::getProcessId).collect(Collectors.toList());
+        Map<Long, ProductProcess> productProcessMap = productProcessService.listByIds(processIds).stream().collect(Collectors.toMap(ProductProcess::getId, productProcess -> productProcess));
         List<ProcessRouteAnticlockwiseDto> processRouteAnticlockwiseDtos = processContentDtoList.stream().map(it -> {
             ProcessRouteAnticlockwiseDto pdto = new ProcessRouteAnticlockwiseDto();
             pdto.setProcessId(it.getProcessId());
@@ -74,6 +101,7 @@
             pdto.setUserNames(it.getReportWorkerList().stream().map(SimplePersonDto::getUserName).collect(Collectors.joining(",")));
             pdto.setDeviceId(it.getDeviceId());
             pdto.setUuid(it.getId());
+            pdto.setProductProcess(productProcessMap.get(it.getProcessId()));
             return pdto;
         }).collect(Collectors.toList());
 
@@ -84,7 +112,19 @@
         productOrder.setId(dto.getProductOrderId());
         productOrder.setRemark(remark);
         productOrderMapper.updateById(productOrder);
-        int i = dto.getId() == null ? productionPrintOrderMapper.insert(productionPrintOrder) : productionPrintOrderMapper.updateById(productionPrintOrder);
+
+        LambdaQueryWrapper<ProductionPrintOrder> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(ProductionPrintOrder::getProductOrderId,dto.getProductOrderId());
+        queryWrapper.last("limit 1");
+        ProductionPrintOrder ifExitPrint = productionPrintOrderMapper.selectOne(queryWrapper);
+        if (ifExitPrint == null) {
+            productionPrintOrder.setId(null);
+            productionPrintOrderMapper.insert(productionPrintOrder);
+        }else {
+            productionPrintOrder.setId(ifExitPrint.getId());
+            productionPrintOrderMapper.updateById(productionPrintOrder);
+        }
+
     }
 
     @Override
@@ -122,7 +162,7 @@
     }
 
     @Override
-    public void exportPrintExcelByWordId(@Nullable Long orderId) {
+    public byte[] exportPrintExcelByWordId(@Nullable Long orderId) {
         ProductionPrintOrderDto printOrderDto = this.getByProductWordId(orderId);
         List<MaterialInfoDto> materialInfo = printOrderDto.getMaterialInfo();
         Assert.isTrue(CollUtil.isNotEmpty(materialInfo),"鏈湁鏉愭枡淇℃伅锛岃娣诲姞鏀逛俊鎭�!");
@@ -132,9 +172,9 @@
         exportProductionPrintOrderDto.setUnitSuffix(materialInfoDto.getUnitSuffix());
         exportProductionPrintOrderDto.setPriceSuffix(materialInfoDto.getPriceSuffix());
         StringUtils.fillStringNull(exportProductionPrintOrderDto);
-        // 鏃ユ湡淇涓� yyyy骞� MM 鏈� mm 鏃�
-        exportProductionPrintOrderDto.setPrintOrderTimeStr(DateUtil.format(exportProductionPrintOrderDto.getPrintOrderTime(),"yyyy骞� MM 鏈� mm 鏃�"));
-        exportProductionPrintOrderDto.setFinishTimeStr(DateUtil.format(exportProductionPrintOrderDto.getFinishTime(),"yyyy骞� MM 鏈� mm 鏃�"));
+        // 鏃ユ湡淇涓� yyyy骞� MM 鏈� mm 鏃yyy-MM-dd
+        exportProductionPrintOrderDto.setPrintOrderTimeStr(DateUtil.format(exportProductionPrintOrderDto.getPrintOrderTime(),"yyyy骞� MM 鏈� dd 鏃�"));
+        exportProductionPrintOrderDto.setFinishTimeStr(DateUtil.format(exportProductionPrintOrderDto.getFinishTime(),"yyyy骞� MM 鏈� dd 鏃�"));
 
         // 浠嬬粛淇� 鍕鹃�夋
         String introductionLetter = exportProductionPrintOrderDto.getIntroductionLetter();
@@ -153,10 +193,11 @@
             byte[] bytes = FileUtil.readBytes(exportProductionPrintOrderDto.getCuttingFileVo().getFileUrl());
             exportProductionPrintOrderDto.setCuttingImage(bytes);
         }
+        // cutNum 涓哄皬鐩掓暟閲�+涓洅鏁伴噺
+        exportProductionPrintOrderDto.setCutNum(String.valueOf(NumberUtil.add(exportProductionPrintOrderDto.getSmallBoxQty(),exportProductionPrintOrderDto.getMediumBoxQty())));
 
-        productionPrintOrderExcel.createPrintOrderTemplate(exportProductionPrintOrderDto, IoUtil.toStream(new File("/Users/ONEX/Downloads/printOrderTemp.xlsx")));
-
-
+        byte[] printOrderTemplate = productionPrintOrderExcel.createPrintOrderTemplate(exportProductionPrintOrderDto, this.getClass().getResourceAsStream("/static/printOrderTemp.xlsx"));
+        return printOrderTemplate;
     }
 
 

--
Gitblit v1.9.3