From ac2e2b5af3726ee64dc37c3ebf26989a0346f22a Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期六, 07 十一月 2026 19:16:05 +0800
Subject: [PATCH] feat(feedback): 优化报工审批流程并增加报工人校验

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/iqc/MesQcIqcServiceImpl.java |  104 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 93 insertions(+), 11 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/iqc/MesQcIqcServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/iqc/MesQcIqcServiceImpl.java
index b64b62f..a493534 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/iqc/MesQcIqcServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/iqc/MesQcIqcServiceImpl.java
@@ -27,6 +27,7 @@
 import cn.iocoder.yudao.module.mes.enums.qc.MesQcCheckResultEnum;
 import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi;
 import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi;
+import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO;
 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import jakarta.annotation.Resource;
 import org.springframework.context.annotation.Lazy;
@@ -39,9 +40,19 @@
 import java.util.*;
 
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
+import cn.iocoder.yudao.module.mes.controller.admin.qc.iqc.vo.MesQcIqcImportExcelVO;
+import cn.iocoder.yudao.module.mes.controller.admin.qc.iqc.vo.MesQcIqcImportRespVO;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.date.DateUtil;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * MES 鏉ユ枡妫�楠屽崟锛圛QC锛� Service 瀹炵幇绫�
@@ -102,6 +113,16 @@
                 .setCheckQuantity(createReqVO.getQualifiedQuantity().add(createReqVO.getUnqualifiedQuantity()))
                 .setSourceDocCode(sourceDocCode)
                 .setStatus(MesQcStatusEnum.DRAFT.getStatus());
+        // 妫�娴嬩汉鍛樸�佹娴嬫棩鏈熴�佹潵鏂欐棩鏈熸湭濉啓鏃朵娇鐢ㄩ粯璁ゅ�硷紝涓嶅奖鍝嶆祦绋�
+        if (iqc.getInspectorUserId() == null) {
+            iqc.setInspectorUserId(getLoginUserId());
+        }
+        if (iqc.getInspectDate() == null) {
+            iqc.setInspectDate(LocalDateTime.now());
+        }
+        if (iqc.getReceiveDate() == null) {
+            iqc.setReceiveDate(LocalDateTime.now());
+        }
         iqcMapper.insert(iqc);
 
         // 3. 浠庢ā鏉挎寚鏍囪嚜鍔ㄧ敓鎴愭楠岃
@@ -136,8 +157,10 @@
         if (reqVO.getItemId() != null) {
             mdmItemApi.getItem(reqVO.getItemId()).getCheckedData();
         }
-        // 鏍¢獙妫�娴嬩汉鍛樺瓨鍦�
-        adminUserApi.validateUser(reqVO.getInspectorUserId());
+        // 鏍¢獙妫�娴嬩汉鍛樺瓨鍦紙闈炲繀濉紝鏈~鍐欐椂鐢卞垱寤洪�昏緫榛樿褰撳墠鐧诲綍浜猴級
+        if (reqVO.getInspectorUserId() != null) {
+            adminUserApi.validateUser(reqVO.getInspectorUserId());
+        }
     }
 
     @Override
@@ -173,10 +196,7 @@
         if (unqualifiedQty == null || unqualifiedQty.compareTo(BigDecimal.ZERO) <= 0) {
             return;
         }
-        String ncrCode = "NCR" + java.time.LocalDateTime.now()
-                .format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
         MesQcNcrSaveReqVO saveReqVO = new MesQcNcrSaveReqVO();
-        saveReqVO.setCode(ncrCode);
         saveReqVO.setName("涓嶅悎鏍煎搧澶勭悊鍗�");
         saveReqVO.setQcType(MesQcTypeEnum.IQC.getType());
         saveReqVO.setQcId(iqc.getId());
@@ -197,8 +217,7 @@
             return;
         }
         if (ObjectUtil.hasNull(iqc.getSourceLineId(), iqc.getSourceDocId())) {
-            throw new IllegalArgumentException(
-                    "IQC 鍗昜" + iqc.getId() + "] sourceDocType 闈炵┖浣� sourceLineId 鎴� sourceDocId 涓虹┖");
+            throw exception(QC_IQC_SOURCE_DOC_PARAMS_MISSING);
         }
 
         // 鏍规嵁涓嶅悓鐨勬潵婧愬崟鎹被鍨嬶紝鍥炲啓涓嶅悓鐨勫崟鎹�
@@ -209,8 +228,7 @@
             outsourceReceiptService.updateOutsourceReceiptWhenIqcFinish(iqc.getSourceDocId(), iqc.getSourceLineId(),
                     iqc.getId(), iqc.getQualifiedQuantity(), iqc.getUnqualifiedQuantity());
         } else {
-            throw new IllegalArgumentException(
-                    "IQC 鍗昜" + iqc.getId() + "] sourceDocType=" + iqc.getSourceDocType() + " 鏃犳硶璇嗗埆锛屾棤娉曞洖鍐欐潵婧愬崟鎹�");
+            throw exception(QC_IQC_SOURCE_DOC_TYPE_UNKNOWN, iqc.getSourceDocType());
         }
     }
 
@@ -360,7 +378,8 @@
         try {
             templateItem = templateItemService.getRequiredTemplateByItemIdAndType(
                     line.getItemId(), MesQcTypeEnum.IQC.getType());
-        } catch (Exception e) {
+        } catch (cn.iocoder.yudao.framework.common.exception.ServiceException e) {
+            if (!java.util.Objects.equals(e.getCode(), QC_NO_TEMPLATE.getCode())) throw e;
             // 鑾峰彇鐗╂枡淇℃伅锛屾彁渚涙洿鏄庣‘鐨勯敊璇彁绀�
             String itemInfo = getItemInfo(line.getItemId());
             throw exception(QC_NO_TEMPLATE_FOR_ITEM, itemInfo);
@@ -368,7 +387,7 @@
         Long templateId = templateItem.getTemplateId();
 
         // 2. 鐢熸垚妫�楠屽崟缂栫爜
-        String code = "IQC" + System.currentTimeMillis();
+        String code = "IQC" + UUID.randomUUID().toString().replace("-", "");
 
         // 3. 鍒涘缓 IQC 涓昏〃锛堝緟妫�楠岀姸鎬侊紝鍒濆鍚堟牸鏁伴噺涓� 0锛�
         MesQcIqcDO iqc = new MesQcIqcDO();
@@ -413,4 +432,67 @@
         return "鐗╂枡ID:" + itemId;
     }
 
+
+    @Override
+    public MesQcIqcImportRespVO importIqcList(List<MesQcIqcImportExcelVO> importList, boolean updateSupport) {
+        if (CollUtil.isEmpty(importList)) {
+            throw exception(QC_IQC_IMPORT_LIST_IS_EMPTY);
+        }
+        MesQcIqcImportRespVO respVO = MesQcIqcImportRespVO.builder()
+                .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>())
+                .failureCodes(new LinkedHashMap<>()).build();
+        AtomicInteger index = new AtomicInteger(1);
+        importList.forEach(importItem -> {
+            int currentIndex = index.getAndIncrement();
+            String key = "绗� " + currentIndex + " 琛�";
+            if (StrUtil.isBlank(importItem.getItemCode())) {
+                respVO.getFailureCodes().put(key, "浜у搧鐗╂枡缂栫爜涓嶈兘涓虹┖");
+                return;
+            }
+            if (importItem.getInspectorUserId() == null) {
+                respVO.getFailureCodes().put(key, "妫�娴嬩汉鍛樹笉鑳戒负绌�");
+                return;
+            }
+            if (importItem.getInspectDate() == null) {
+                respVO.getFailureCodes().put(key, "妫�娴嬫棩鏈熶笉鑳戒负绌�");
+                return;
+            }
+            if (importItem.getReceiveDate() == null) {
+                respVO.getFailureCodes().put(key, "鏉ユ枡鏃ユ湡涓嶈兘涓虹┖");
+                return;
+            }
+            if (importItem.getReceivedQuantity() == null || importItem.getQualifiedQuantity() == null || importItem.getUnqualifiedQuantity() == null) {
+                respVO.getFailureCodes().put(key, "鏈鎺ユ敹鏁伴噺銆佸悎鏍煎搧鏁伴噺銆佷笉鍚堟牸鍝佹暟閲忓潎涓嶈兘涓虹┖");
+                return;
+            }
+            if (importItem.getQualifiedQuantity().add(importItem.getUnqualifiedQuantity()).compareTo(importItem.getReceivedQuantity()) != 0) {
+                respVO.getFailureCodes().put(key, "鍚堟牸鍝佹暟閲忎笌涓嶅悎鏍煎搧鏁伴噺涔嬪拰蹇呴』绛変簬鏈鎺ユ敹鏁伴噺");
+                return;
+            }
+            // 鏉ユ枡妫�楠屽崟鐨勭墿鏂欎互 MDM 涓哄噯锛屽鍏ユ寜 MDM 鐗╂枡缂栫爜瑙f瀽
+            MdmItemRespDTO item = mdmItemApi.getItemByCode(importItem.getItemCode()).getCheckedData();
+            if (item == null) {
+                respVO.getFailureCodes().put(key, "鐗╂枡涓嶅瓨鍦細" + importItem.getItemCode());
+                return;
+            }
+            try {
+                MesQcIqcSaveReqVO createReqVO = BeanUtils.toBean(importItem, MesQcIqcSaveReqVO.class);
+                createReqVO.setCode(generateImportCode("IQC", index));
+                createReqVO.setName(StrUtil.blankToDefault(importItem.getName(), "鏉ユ枡妫�楠屽崟"));
+                createReqVO.setItemId(item.getId());
+                Long id = createIqc(createReqVO);
+                MesQcIqcDO created = iqcMapper.selectById(id);
+                respVO.getCreateCodes().add(created != null && StrUtil.isNotBlank(created.getCode()) ? created.getCode() : key);
+            } catch (ServiceException e) {
+                respVO.getFailureCodes().put(key, e.getMessage());
+            }
+        });
+        return respVO;
+    }
+
+    private String generateImportCode(String prefix, AtomicInteger seq) {
+        return prefix + DateUtil.format(LocalDateTime.now(), "yyyyMMddHHmmss")
+                + String.format("%03d", seq.incrementAndGet());
+    }
+
 }

--
Gitblit v1.9.3