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/oqc/MesQcOqcServiceImpl.java |  124 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 112 insertions(+), 12 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/oqc/MesQcOqcServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/oqc/MesQcOqcServiceImpl.java
index 57b4dd2..6240055 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/oqc/MesQcOqcServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/oqc/MesQcOqcServiceImpl.java
@@ -25,6 +25,7 @@
 import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesLineDO;
 import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi;
 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;
@@ -38,7 +39,20 @@
 import java.util.Objects;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
+import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcImportExcelVO;
+import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcImportRespVO;
+import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO;
+import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.hutool.core.collection.CollUtil;
+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 瀹炵幇绫�
@@ -48,6 +62,9 @@
 @Service
 @Validated
 public class MesQcOqcServiceImpl implements MesQcOqcService {
+
+    @Resource
+    private MesMdItemService itemService;
 
     @Resource
     private MesQcOqcMapper oqcMapper;
@@ -98,6 +115,16 @@
                 .setTemplateId(templateId)
                 .setSourceDocCode(sourceDocCode)
                 .setStatus(MesQcStatusEnum.DRAFT.getStatus());
+        // 妫�娴嬩汉鍛樸�佹娴嬫棩鏈熴�佸嚭璐ф棩鏈熸湭濉啓鏃朵娇鐢ㄩ粯璁ゅ�硷紝涓嶅奖鍝嶆祦绋�
+        if (oqc.getInspectorUserId() == null) {
+            oqc.setInspectorUserId(getLoginUserId());
+        }
+        if (oqc.getInspectDate() == null) {
+            oqc.setInspectDate(LocalDateTime.now());
+        }
+        if (oqc.getOutDate() == null) {
+            oqc.setOutDate(LocalDateTime.now());
+        }
         oqcMapper.insert(oqc);
 
         // 3. 浠庢ā鏉挎寚鏍囪嚜鍔ㄧ敓鎴愭楠岃
@@ -126,7 +153,10 @@
         // 鏍¢獙鐗╂枡銆佹娴嬩汉鍛樺瓨鍦�
         // 娉細鐗╂枡 ID 鏉ヨ嚜 MDM锛屽鎴� ID 鏉ヨ嚜 CRM
         mdmItemApi.validateItemExists(reqVO.getItemId());
-        adminUserApi.validateUser(reqVO.getInspectorUserId());
+        // 鏍¢獙妫�娴嬩汉鍛樺瓨鍦紙闈炲繀濉紝鏈~鍐欐椂鐢卞垱寤洪�昏緫榛樿褰撳墠鐧诲綍浜猴級
+        if (reqVO.getInspectorUserId() != null) {
+            adminUserApi.validateUser(reqVO.getInspectorUserId());
+        }
     }
 
     @Override
@@ -163,10 +193,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.OQC.getType());
         saveReqVO.setQcId(oqc.getId());
@@ -190,16 +217,14 @@
             return;
         }
         if (oqc.getSourceLineId() == null) {
-            throw new IllegalArgumentException(
-                    "OQC 鍗昜" + oqc.getId() + "] sourceDocType 闈炵┖浣� sourceLineId 涓虹┖");
+            throw exception(QC_OQC_SOURCE_LINE_REQUIRED);
         }
 
         if (Objects.equals(oqc.getSourceDocType(), MesBizTypeConstants.WM_PRODUCT_SALES)) {
             productSalesLineService.updateProductSalesLineWhenOqcFinish(
                     oqc.getSourceLineId(), oqc.getId(), oqc.getCheckResult());
         } else {
-            throw new IllegalArgumentException(
-                    "OQC 鍗昜" + oqc.getId() + "] sourceDocType=" + oqc.getSourceDocType() + " 鏃犳硶璇嗗埆锛屾棤娉曞洖鍐欐潵婧愬崟鎹�");
+            throw exception(QC_OQC_SOURCE_DOC_TYPE_UNKNOWN, oqc.getSourceDocType());
         }
     }
 
@@ -267,7 +292,7 @@
             return null;
         }
         // 鏈煡鏉ユ簮绫诲瀷搴旀姤閿欙紝鑰屼笉鏄潤榛樺拷鐣�
-        throw exception(QC_OQC_SOURCE_DOC_TYPE_UNKNOWN);
+        throw exception(QC_OQC_SOURCE_DOC_TYPE_UNKNOWN, sourceDocType);
     }
 
     @Override
@@ -330,15 +355,16 @@
         try {
             templateItem = templateItemService.getRequiredTemplateByItemIdAndType(
                     line.getItemId(), MesQcTypeEnum.OQC.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);
+            throw exception(QC_OQC_NO_TEMPLATE_FOR_ITEM, itemInfo);
         }
         Long templateId = templateItem.getTemplateId();
 
         // 2. 鐢熸垚妫�楠屽崟缂栫爜
-        String code = "OQC" + System.currentTimeMillis();
+        String code = "OQC" + java.util.UUID.randomUUID().toString().replace("-", "");
 
         // 3. 鍒涘缓 OQC 涓昏〃锛堝緟妫�楠岀姸鎬侊紝鍒濆鏁伴噺涓� 0锛�
         MesQcOqcDO oqc = new MesQcOqcDO();
@@ -384,4 +410,78 @@
         return "鐗╂枡ID:" + itemId;
     }
 
+
+    @Override
+    public MesQcOqcImportRespVO importOqcList(List<MesQcOqcImportExcelVO> importList, boolean updateSupport) {
+        if (CollUtil.isEmpty(importList)) {
+            throw exception(QC_OQC_IMPORT_LIST_IS_EMPTY);
+        }
+        MesQcOqcImportRespVO respVO = MesQcOqcImportRespVO.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.getClientName())) {
+                respVO.getFailureCodes().put(key, "瀹㈡埛鍚嶇О涓嶈兘涓虹┖");
+                return;
+            }
+            if (StrUtil.isBlank(importItem.getItemCode())) {
+                respVO.getFailureCodes().put(key, "浜у搧鐗╂枡缂栫爜涓嶈兘涓虹┖");
+                return;
+            }
+            if (importItem.getOutQuantity() == null || importItem.getCheckQuantity() == null
+                    || importItem.getQualifiedQuantity() == null || importItem.getUnqualifiedQuantity() == null) {
+                respVO.getFailureCodes().put(key, "鍑鸿揣鏁伴噺銆佹娴嬫暟閲忋�佸悎鏍煎搧鏁伴噺銆佷笉鍚堟牸鍝佹暟閲忓潎涓嶈兘涓虹┖");
+                return;
+            }
+            if (importItem.getCheckQuantity().compareTo(importItem.getQualifiedQuantity().add(importItem.getUnqualifiedQuantity())) != 0) {
+                respVO.getFailureCodes().put(key, "妫�娴嬫暟閲忓繀椤荤瓑浜庡悎鏍煎搧鏁伴噺涓庝笉鍚堟牸鍝佹暟閲忎箣鍜�");
+                return;
+            }
+            if (importItem.getInspectorUserId() == null) {
+                respVO.getFailureCodes().put(key, "妫�娴嬩汉鍛樹笉鑳戒负绌�");
+                return;
+            }
+            if (importItem.getOutDate() == null) {
+                respVO.getFailureCodes().put(key, "鍑鸿揣鏃ユ湡涓嶈兘涓虹┖");
+                return;
+            }
+            if (importItem.getInspectDate() == null) {
+                respVO.getFailureCodes().put(key, "妫�娴嬫棩鏈熶笉鑳戒负绌�");
+                return;
+            }
+            cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO customer = customerApi.getCustomerByName(importItem.getClientName());
+            if (customer == null) {
+                respVO.getFailureCodes().put(key, "瀹㈡埛涓嶅瓨鍦細" + importItem.getClientName());
+                return;
+            }
+            // 鍑鸿揣妫�楠屽崟鐨勭墿鏂欎互 MDM 涓哄噯锛屽鍏ユ寜 MDM 鐗╂枡缂栫爜瑙f瀽
+            MdmItemRespDTO item = mdmItemApi.getItemByCode(importItem.getItemCode()).getCheckedData();
+            if (item == null) {
+                respVO.getFailureCodes().put(key, "鐗╂枡涓嶅瓨鍦細" + importItem.getItemCode());
+                return;
+            }
+            try {
+                MesQcOqcSaveReqVO createReqVO = BeanUtils.toBean(importItem, MesQcOqcSaveReqVO.class);
+                createReqVO.setCode(generateImportCode("OQC", index));
+                createReqVO.setName(StrUtil.blankToDefault(importItem.getName(), "鍑鸿揣妫�楠屽崟"));
+                createReqVO.setClientId(customer.getId());
+                createReqVO.setItemId(item.getId());
+                Long id = createOqc(createReqVO);
+                MesQcOqcDO created = oqcMapper.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