From b31810d67d517b42c9f335d88affe0e9cc074ad7 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 04 十一月 2026 16:44:51 +0800
Subject: [PATCH] fix(mes): 出货检验质检方案为空,未绑定模板时按产品类别兜底

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/template/MesQcTemplateItemController.java |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/template/MesQcTemplateItemController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/template/MesQcTemplateItemController.java
index cdd5397..b2e1a2f 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/template/MesQcTemplateItemController.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/template/MesQcTemplateItemController.java
@@ -28,6 +28,7 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
@@ -91,16 +92,25 @@
     }
 
     @GetMapping("/list-by-item-and-type")
-    @Operation(summary = "鏍规嵁鐗╂枡鎴栧伐鍗�/浠诲姟鍜屾娴嬬绫昏幏鍙栧彲鐢ㄨ川妫�鏂规")
+    @Operation(summary = "鏍规嵁鐗╂枡鎴栧伐鍗�/浠诲姟鍜屾娴嬬绫昏幏鍙栧彲鐢ㄨ川妫�鏂规锛堟湭鎸囧畾鐗╂枡/宸ュ崟/浠诲姟鏃惰繑鍥炶妫�娴嬬绫讳笅鍏ㄩ儴鍚敤鏂规锛�")
     @PreAuthorize("@ss.hasPermission('mes:qc-template:query')")
     public CommonResult<List<MesQcTemplateItemOptionRespVO>> getTemplateItemOptionList(
             @RequestParam(value = "qcType", required = false) Integer qcType,
             @RequestParam(value = "itemId", required = false) Long itemId,
             @RequestParam(value = "workOrderId", required = false) Long workOrderId,
             @RequestParam(value = "taskId", required = false) Long taskId) {
+        // 鏈寚瀹氱墿鏂�/宸ュ崟/浠诲姟鏃讹紝鎸夋娴嬬绫昏繑鍥炲叏閮ㄥ惎鐢ㄧ殑璐ㄦ鏂规锛堜笉闄愬埗浜у搧鐗╂枡鍏宠仈锛�
+        if (itemId == null && workOrderId == null && taskId == null && qcType != null) {
+            return success(buildEnabledTemplateOptions(qcType));
+        }
         List<MesQcTemplateItemDO> list = templateItemService.getTemplateItemList(
                 itemId, qcType, workOrderId, taskId);
         if (CollUtil.isEmpty(list)) {
+            // 璇ョ墿鏂欐湭缁戝畾鏂规鏃讹紝鍥為��涓鸿妫�娴嬬绫讳笅鐨勫叏閮ㄥ惎鐢ㄦ柟妗堬紝渚涚敤鎴锋墜鍔ㄩ�夋嫨锛�
+            // 鍚﹀垯鏃犵粦瀹氱殑鐗╂枡锛堝涓囬�氬嚭璐ф楠岀殑缁濆ぇ澶氭暟浜у搧锛変笅鎷夋姘歌繙涓虹┖锛屽崟鎹棤娉曠紪鍒�
+            if (qcType != null && (itemId != null || workOrderId != null || taskId != null)) {
+                return success(buildEnabledTemplateOptions(qcType));
+            }
             return success(Collections.emptyList());
         }
         Map<Long, MesQcTemplateDO> templateMap = templateService.getTemplateMap(
@@ -115,6 +125,17 @@
         return success(result);
     }
 
+    /**
+     * 鏋勫缓銆岃妫�娴嬬绫讳笅鍏ㄩ儴鍚敤鏂规銆嶇殑閫夐」鍒楄〃
+     */
+    private List<MesQcTemplateItemOptionRespVO> buildEnabledTemplateOptions(Integer qcType) {
+        return templateService.getEnabledTemplateListByType(qcType).stream()
+                .map(template -> new MesQcTemplateItemOptionRespVO()
+                        .setTemplateId(template.getId()).setTemplateCode(template.getCode())
+                        .setTemplateName(template.getName()))
+                .collect(Collectors.toList());
+    }
+
     // ==================== 鎷兼帴 VO ====================
 
     private List<MesQcTemplateItemRespVO> buildItemRespVOList(List<MesQcTemplateItemDO> list) {

--
Gitblit v1.9.3