From ff361539e3ffd6e62100e392ddda2f4ab9dfee62 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 27 五月 2026 13:15:42 +0800
Subject: [PATCH] 工序调整, 报工反改订单数量,判断是最后一道工序才修改订单完成数量

---
 src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java |   82 ++++++++++++++++++++++++++++++----------
 1 files changed, 61 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java
index 5e26bdd..60b3dc2 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java
@@ -11,11 +11,11 @@
 import com.ruoyi.basic.service.IProductModelService;
 import com.ruoyi.basic.service.IProductService;
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.DictUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.production.dto.ProductProcessDto;
 import com.ruoyi.production.dto.ProductProcessImportDto;
-import com.ruoyi.production.enums.ProductProcessEnum;
 import com.ruoyi.production.mapper.ProcessRouteItemMapper;
 import com.ruoyi.production.mapper.ProductProcessMapper;
 import com.ruoyi.production.mapper.ProductProcessRouteItemMapper;
@@ -25,7 +25,6 @@
 import com.ruoyi.production.service.ProductProcessService;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysUserMapper;
-import com.ruoyi.project.system.service.ISysUserService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -37,6 +36,7 @@
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service
@@ -84,17 +84,18 @@
             throw new ServiceException("鏂板澶辫触,璁″垝宸ユ椂涓嶈兘涓虹┖");
         }
         // 鍒ゆ柇浜у搧鏄惁瀛樺湪
-        if (ObjectUtils.isEmpty(productProcessDto.getProductModelId())) {
-            throw new ServiceException("鏂板澶辫触,閮ㄤ欢涓嶈兘涓虹┖");
-        }
-        ProductModel productModel = productModelService.getById(productProcessDto.getProductModelId());
-        if (productModel == null) {
-            throw new ServiceException("鏂板澶辫触,璇ラ儴浠朵笉瀛樺湪");
-        }
+//        if (ObjectUtils.isEmpty(productProcessDto.getProductModelId())) {
+//            throw new ServiceException("鏂板澶辫触,閮ㄤ欢涓嶈兘涓虹┖");
+//        }
+//        ProductModel productModel = productModelService.getById(productProcessDto.getProductModelId());
+//        if (productModel == null) {
+//            throw new ServiceException("鏂板澶辫触,璇ラ儴浠朵笉瀛樺湪");
+//        }
+//        validateDuplicateTypeForSameProduct(productModel.getId(), productProcessDto.getType(), null);
 
         ProductProcess productProcess = new ProductProcess();
         BeanUtils.copyProperties(productProcessDto, productProcess);
-        productProcess.setProductModelId(productModel.getId());
+//        productProcess.setProductModelId(productModel.getId());
 
         validatePlanner(productProcessDto.getPlannerId(), productProcessDto.getPlannerName(), null);
 
@@ -109,6 +110,9 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void update(ProductProcessDto productProcessDto) {
+        if (ObjectUtils.isEmpty(productProcessDto.getId())) {
+            throw new ServiceException("淇敼澶辫触锛屽伐搴廔D涓嶈兘涓虹┖");
+        }
         if (ObjectUtils.isEmpty(productProcessDto.getName())) {
             throw new ServiceException("閮ㄤ欢鍚嶇О涓嶈兘涓虹┖");
         }
@@ -121,13 +125,21 @@
             }
         }
 
-        // 鍒ゆ柇鍏宠仈浜у搧鏄惁瀛樺湪
-        if (ObjectUtils.isNotEmpty(productProcessDto.getProductModelId())) {
-            ProductModel productModel = productModelService.getById(productProcessDto.getProductModelId());
-            if (productModel == null) {
-                throw new ServiceException("淇敼澶辫触锛屽叧鑱旈儴浠朵笉瀛樺湪");
-            }
+        ProductProcess oldProductProcess = this.getById(productProcessDto.getId());
+        if (oldProductProcess == null) {
+            throw new ServiceException("淇敼澶辫触锛屽伐搴忎笉瀛樺湪");
         }
+//        Long finalProductModelId = ObjectUtils.isNotEmpty(productProcessDto.getProductModelId())
+//                ? productProcessDto.getProductModelId() : oldProductProcess.getProductModelId();
+//        Integer finalType = ObjectUtils.isNotEmpty(productProcessDto.getType())
+//                ? productProcessDto.getType() : oldProductProcess.getType();
+//
+        // 鍒ゆ柇鍏宠仈浜у搧鏄惁瀛樺湪
+//        ProductModel productModel = productModelService.getById(finalProductModelId);
+//        if (productModel == null) {
+//            throw new ServiceException("淇敼澶辫触锛屽叧鑱旈儴浠朵笉瀛樺湪");
+//        }
+//        validateDuplicateTypeForSameProduct(productModel.getId(), finalType, productProcessDto.getId());
 
         // 鏍¢獙璁″垝浜哄憳
         validatePlanner(productProcessDto.getPlannerId(), productProcessDto.getPlannerName(), null);
@@ -175,10 +187,10 @@
                 if (ObjectUtils.isEmpty(importDto.getProductProcessType())) {
                     throw new ServiceException("绗�" + rowNum + "琛岋細閮ㄤ欢銆�" + importDto.getName() + "銆戠殑绫诲瀷涓嶈兘涓虹┖");
                 }
-                ProductProcessEnum enumByInfo = ProductProcessEnum.getEnumByInfo(importDto.getProductProcessType());
-                if (ObjectUtils.isEmpty(enumByInfo)) {
+                String dictValue = DictUtils.getDictValue("product_process_type", importDto.getProductProcessType());
+                if (StringUtils.isEmpty(dictValue)) {
                     throw new ServiceException("绗�" + rowNum + "琛岋細閮ㄤ欢銆�" + importDto.getName() + "銆戠殑绫诲瀷銆�"
-                            + importDto.getProductProcessType() + "銆戜笉瀛樺湪锛岃濉啓姝g‘鐨勭被鍨嬶細鍔犲伐銆佸埉鏉垮喎鑺埗浣溿�佺璺粍瀵广�佺綈浣撹繛鎺ュ強璋冭瘯銆佹祴璇曟墦鍘嬨�佸叾浠�");
+                            + importDto.getProductProcessType() + "銆戜笉瀛樺湪锛岃濉啓姝g‘鐨勭被鍨嬶細" + DictUtils.getDictLabels("product_process_type"));
                 }
                 // 妫�楠岃鍒掑伐鏃�
                 if (importDto.getSalaryQuota() == null || importDto.getSalaryQuota().compareTo(BigDecimal.ZERO) < 0) {
@@ -195,10 +207,10 @@
                 ProductProcess productProcess = new ProductProcess();
                 BeanUtils.copyProperties(importDto, productProcess);
                 productProcess.setProductModelId(productModel.getId());
-                productProcess.setType(enumByInfo.getCode());
+                productProcess.setType(Integer.valueOf(dictValue));
                 if (sysUser != null) {
                     productProcess.setPlannerId(sysUser.getUserId());
-                    productProcess.setPlannerName(sysUser.getUserName());
+                    productProcess.setPlannerName(sysUser.getNickName());
                 }
                 productProcessList.add(productProcess);
             }
@@ -232,6 +244,34 @@
         }
     }
 
+    /**
+     * 鏍¢獙鍚屼竴浜у搧涓嬪伐搴忕被鍨嬩笉鑳介噸澶�
+     */
+    private void validateDuplicateTypeForSameProduct(Long productModelId, Integer type, Long excludeId) {
+        if (productModelId == null || type == null) {
+            return;
+        }
+        ProductModel currentModel = productModelService.getById(productModelId);
+        if (currentModel == null || currentModel.getProductId() == null) {
+            return;
+        }
+        List<ProductModel> productModels = productModelService.list(
+                Wrappers.<ProductModel>lambdaQuery().eq(ProductModel::getProductId, currentModel.getProductId()));
+        if (CollectionUtils.isEmpty(productModels)) {
+            return;
+        }
+        List<Long> productModelIds = productModels.stream().map(ProductModel::getId).collect(Collectors.toList());
+        LambdaQueryWrapper<ProductProcess> queryWrapper = Wrappers.<ProductProcess>lambdaQuery()
+                .in(ProductProcess::getProductModelId, productModelIds)
+                .eq(ProductProcess::getType, type);
+        if (excludeId != null) {
+            queryWrapper.ne(ProductProcess::getId, excludeId);
+        }
+        if (this.count(queryWrapper) > 0) {
+            throw new ServiceException("鎿嶄綔澶辫触锛屽悓涓�浜у搧涓嶈兘瀛樺湪閲嶅鐨勯儴浠剁被鍨�");
+        }
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void batchDelete(List<Integer> ids) {

--
Gitblit v1.9.3