From 4bcd26a4975d6722bff65690e7a8331cd0afd520 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 31 三月 2026 17:46:19 +0800
Subject: [PATCH] yys 1.销售,采购台账产品反着来 2.产品图纸带到生产订单来

---
 src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java |   52 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java b/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
index 26715f3..066d886 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
@@ -11,25 +11,31 @@
 import com.ruoyi.basic.pojo.Product;
 import com.ruoyi.basic.pojo.ProductModel;
 import com.ruoyi.basic.service.IProductModelService;
+import com.ruoyi.common.enums.FileNameType;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.OrderUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.other.mapper.TempFileMapper;
+import com.ruoyi.other.service.impl.TempFileServiceImpl;
+import com.ruoyi.production.mapper.ProductProcessMapper;
+import com.ruoyi.production.pojo.ProductProcess;
+import com.ruoyi.sales.mapper.CommonFileMapper;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
 import lombok.AllArgsConstructor;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
-import java.util.AbstractMap;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -45,9 +51,13 @@
     private final ProductMapper productMapper;
     private final SalesLedgerProductMapper salesLedgerProductMapper;
     private ProductModelMapper productModelMapper;
+    private final CommonFileServiceImpl commonFileService;
+    private final ProductProcessMapper productProcessMapper;
+
+    private final TempFileServiceImpl tempFileService;
 
     @Override
-    public int addOrEditProductModel(ProductModelDto productModelDto) {
+    public int addOrEditProductModel(ProductModelDto productModelDto) throws IOException {
         if(StringUtils.isEmpty(productModelDto.getProductName())){
             throw new RuntimeException("浜у搧鍚嶇О涓嶈兘涓虹┖");
         }
@@ -63,16 +73,24 @@
             ProductModel productModel = new ProductModel();
             BeanUtils.copyProperties(productModelDto,productModel);
             productModel.setProductId(product.getId());
-            return productModelMapper.insert(productModel);
+            productModelMapper.insert(productModel);
+            if(CollectionUtils.isNotEmpty(productModelDto.getTempFileIds())){
+                commonFileService.migrateTempFilesToFormal(productModel.getId(), productModelDto.getTempFileIds());
+            }
+            return 1;
         } else {
             Product product1 = productMapper.selectById(productModelDto.getProductId());
             if(product1 != null){
                 product1.setProductName(productModelDto.getProductName());
                 productMapper.updateById(product1);
             }
-
+            commonFileService.deleteByBusinessIds(Collections.singletonList(productModelDto.getId()), FileNameType.PRODUCT_MODEL.getValue());
+            if(CollectionUtils.isNotEmpty(productModelDto.getTempFileIds())){
+                commonFileService.migrateTempFilesToFormal(productModelDto.getId(), productModelDto.getTempFileIds());
+            }
             return productModelMapper.updateById(productModelDto);
         }
+
     }
 
 
@@ -116,11 +134,6 @@
         try {
             ExcelUtil<ProductModelExcelCopyDto> productModelExcelUtil = new ExcelUtil<>(ProductModelExcelCopyDto.class);
             List<ProductModelExcelCopyDto> productModelList = productModelExcelUtil.importExcel(file.getInputStream());
-//            List<Product> productList = productMapper.selectList(new LambdaQueryWrapper<Product>()
-//                    .isNull(Product::getParentId));
-//            if(CollectionUtils.isEmpty(productList)) {
-//                throw new RuntimeException("璇峰厛娣诲姞鐖剁骇浜у搧");
-//            }
             if(CollectionUtils.isNotEmpty(productModelList)){
                 // 2. 鎸変骇鍝佸悕绉�,鍥剧焊缂栧彿鍒嗙粍
                 Map<Map.Entry<String, String>, List<ProductModelExcelCopyDto>> groupedByProductNameAndDrawingNumber =
@@ -184,15 +197,27 @@
      */
     private void processProductModel(List<ProductModelExcelCopyDto> dtoList,
                                      Long productId, String model, String drawingNumber) {
+        // 鏌ヨ鎵�鏈夊伐鑹鸿矾绾�
+        List<ProductProcess> productRoutes = productProcessMapper.selectList(new QueryWrapper<ProductProcess>());
+        if(CollectionUtils.isEmpty(productRoutes)){
+            throw new ServiceException("璇峰厛鍒涘缓浜у搧宸ヨ壓璺嚎");
+        }
         for (ProductModelExcelCopyDto dto : dtoList) {
             // 鏌ヨ鏉′欢锛氬瀷鍙�+鍥剧焊缂栧彿锛堟洿绮惧噯锛岀鍚堝垎缁勯�昏緫锛�
             ProductModel productModel = productModelMapper.selectOne(new LambdaQueryWrapper<ProductModel>()
                     .eq(ProductModel::getModel, model)
                     .last("limit 1"));
-
+            // 閫氳繃宸ヨ壓璺嚎鍚嶇О鍖归厤鏈�鏂颁竴鏉″伐鑹鸿矾绾�
+            ProductProcess productRoute = productRoutes.stream()
+                    .filter(route -> route.getName().equals(dto.getProcessRoute()))
+                    .max(Comparator.comparing(ProductProcess::getCreateTime))
+                    .orElse(null);
             if (productModel == null) {
                 productModel = new ProductModel();
                 BeanUtils.copyProperties(dto, productModel);
+                if (productRoute != null) {
+                    productModel.setRouteId(productRoute.getId());
+                }
                 // 鍏滃簳榛樿鍊硷紝閬垮厤绌哄��
                 if (productModel.getProductType() == null) {
                     productModel.setProductType(1);
@@ -200,6 +225,7 @@
                 productModel.setProductId(productId);
                 productModelMapper.insert(productModel);
             } else {
+                productModel.setRouteId(productRoute != null ? productRoute.getId() : null);
                 BeanUtils.copyProperties(dto, productModel);
                 productModel.setProductId(productId);
                 productModelMapper.updateById(productModel);

--
Gitblit v1.9.3