From b0bbbf71d1e6ecdbe4abbcc39127f5aac6502f1e Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 20 五月 2026 16:39:25 +0800
Subject: [PATCH] feat(production): 添加产品主记录审核功能

---
 src/main/java/com/ruoyi/production/service/impl/ProductionPrintOrderServiceImpl.java |   57 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 44 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..c97b22b 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,10 @@
 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.ProductionPrintOrderService;
 import lombok.RequiredArgsConstructor;
 import org.jetbrains.annotations.Nullable;
@@ -45,13 +46,30 @@
     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;
     @Override
     @Transactional
     public void save(SaveProductionPrintOrderDto dto) {
         ProductionPrintOrder productionPrintOrder = BeanUtil.copyProperties(dto, ProductionPrintOrder.class);
-
+        if(dto.getId() != 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 -> {
@@ -84,7 +102,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 +152,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 +162,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 +183,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