From cf3482e6a4d40713cc09d107f11092c8db2e245a Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期三, 27 五月 2026 17:18:40 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_天津_阳光彩印' into dev_天津_阳光彩印

---
 src/main/java/com/ruoyi/production/service/impl/ProductionPrintOrderServiceImpl.java |  136 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 123 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 0b5008a..a859165 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionPrintOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionPrintOrderServiceImpl.java
@@ -1,26 +1,36 @@
 package com.ruoyi.production.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
+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;
+import com.ruoyi.basic.excel.ProductionPrintOrderExcel;
 import com.ruoyi.basic.service.CustomerFollowUpFileService;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.dto.SimplePersonDto;
-import com.ruoyi.production.dto.ProcessContentDto;
-import com.ruoyi.production.dto.ProcessRouteAnticlockwiseDto;
-import com.ruoyi.production.dto.ProductionPrintOrderDto;
-import com.ruoyi.production.dto.SaveProductionPrintOrderDto;
-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.dto.*;
+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;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -37,13 +47,35 @@
 
     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 -> {
@@ -51,19 +83,25 @@
                 processContentDto.setId(IdUtil.simpleUUID());
             }
         });
+        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());
             pdto.setProcessRouteName(it.getProcessName());
             pdto.setProcessRouteOpenNum(it.getOpenCount());
             pdto.setProcessRouteNum(it.getProcessPositive());
-            pdto.setProcessRouteAddNum(it.getProcessPositive());
+            pdto.setProcessRouteAddNum(it.getAllowanceQty());
 //            pdto.setProcessRouteRequire(); 宸ヨ壓瑕佹眰
-            pdto.setProductModelId(dto.getProductModelId());
-            pdto.setUserIds(it.getReportWorkerList().stream().map(SimplePersonDto::getUserName).collect(Collectors.joining(",")));
+            pdto.setProductModelId(Long.valueOf(materialInfoDtoFirst.getProductModelId()));
+            pdto.setUserIds(it.getReportWorkerList().stream().map(SimplePersonDto::getUserId).map(String::valueOf).collect(Collectors.joining(",")));
+            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());
 
@@ -74,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
@@ -91,6 +141,66 @@
 
         return productionPrintOrderDto;
     }
+
+    @Override
+    public List<ProductionPrintOrder> getListByOrders(List<Long> orderIds) {
+        if(CollUtil.isEmpty(orderIds)){
+            return new ArrayList<>();
+        }
+        LambdaQueryWrapper<ProductionPrintOrder> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.in(ProductionPrintOrder::getProductOrderId, orderIds);
+        List<ProductionPrintOrder> productionPrintOrders = productionPrintOrderMapper.selectList(queryWrapper);
+        // 鍘婚櫎閲嶅鐨刼rderIds鐨勮褰曞彧淇濈暀id鏈�澶х殑涓�涓�
+        return productionPrintOrders.stream().collect(Collectors.collectingAndThen(
+            Collectors.toMap(
+                ProductionPrintOrder::getProductOrderId,
+                productionPrintOrder -> productionPrintOrder,
+                (existing, replacement) -> existing.getId() > replacement.getId() ? existing : replacement
+            ),
+            map -> new ArrayList<>(map.values())
+        ));
+    }
+
+    @Override
+    public byte[] exportPrintExcelByWordId(@Nullable Long orderId) {
+        ProductionPrintOrderDto printOrderDto = this.getByProductWordId(orderId);
+        List<MaterialInfoDto> materialInfo = printOrderDto.getMaterialInfo();
+        Assert.isTrue(CollUtil.isNotEmpty(materialInfo),"鏈湁鏉愭枡淇℃伅锛岃娣诲姞鏀逛俊鎭�!");
+        MaterialInfoDto materialInfoDto = materialInfo.get(0);
+        ExportProductionPrintOrderDto exportProductionPrintOrderDto = BeanUtil.copyProperties(printOrderDto, ExportProductionPrintOrderDto.class);
+        exportProductionPrintOrderDto.setNumSuffix(materialInfoDto.getNumSuffix());
+        exportProductionPrintOrderDto.setUnitSuffix(materialInfoDto.getUnitSuffix());
+        exportProductionPrintOrderDto.setPriceSuffix(materialInfoDto.getPriceSuffix());
+        StringUtils.fillStringNull(exportProductionPrintOrderDto);
+        // 鏃ユ湡淇涓� 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();
+        List<String> introductionLetterItem = StrUtil.split(introductionLetter, ",");
+        exportProductionPrintOrderDto.setIntroductionLetter1(introductionLetterItem.contains("浠嬬粛淇�")?"R" : "拢");
+        exportProductionPrintOrderDto.setIntroductionLetter2(introductionLetterItem.contains("鍟嗘爣娉ㄥ唽")?"R" : "拢");
+        exportProductionPrintOrderDto.setIntroductionLetter3(introductionLetterItem.contains("濮斿嵃鍗�")?"R" : "拢");
+        exportProductionPrintOrderDto.setIntroductionLetter4(introductionLetterItem.contains("涔﹀彿")?"R" : "拢");
+
+        // 鍒囨枡鍥剧ず
+        exportProductionPrintOrderDto.setCuttingDiagramCheckout1("骞冲紶".equals(exportProductionPrintOrderDto.getCuttingDiagramCheckout())?"R" : "拢");
+        exportProductionPrintOrderDto.setCuttingDiagramCheckout2("鍗风瓛".equals(exportProductionPrintOrderDto.getCuttingDiagramCheckout())?"R" : "拢");
+
+        // 璇诲彇鍥剧墖淇℃伅
+        if(exportProductionPrintOrderDto.getCuttingFileVo() != null){
+            byte[] bytes = FileUtil.readBytes(exportProductionPrintOrderDto.getCuttingFileVo().getFileUrl());
+            exportProductionPrintOrderDto.setCuttingImage(bytes);
+        }
+        // cutNum 涓哄皬鐩掓暟閲�+涓洅鏁伴噺
+        exportProductionPrintOrderDto.setCutNum(String.valueOf(NumberUtil.add(exportProductionPrintOrderDto.getSmallBoxQty(),exportProductionPrintOrderDto.getMediumBoxQty())));
+
+        byte[] printOrderTemplate = productionPrintOrderExcel.createPrintOrderTemplate(exportProductionPrintOrderDto, this.getClass().getResourceAsStream("/static/printOrderTemp.xlsx"));
+        return printOrderTemplate;
+    }
+
+
 }
 
 

--
Gitblit v1.9.3