From 8c65f898ed6e5b0c7a94c792c4562f6ec831dccd Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期六, 07 十一月 2026 08:50:53 +0800
Subject: [PATCH] feat: 完善质检、生产、销售、财务与人事模块并接入审批流程

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/attachment/MesQcAttachmentController.java |   61 +++++++++++++++++++++++++++++-
 1 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/attachment/MesQcAttachmentController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/attachment/MesQcAttachmentController.java
index a00331b..05ebd97 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/attachment/MesQcAttachmentController.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/attachment/MesQcAttachmentController.java
@@ -2,6 +2,7 @@
 
 import cn.iocoder.yudao.framework.common.exception.ServiceException;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
 import cn.iocoder.yudao.module.mes.service.qc.iqc.MesQcIqcService;
 import cn.iocoder.yudao.module.mes.service.qc.ipqc.MesQcIpqcService;
 import cn.iocoder.yudao.module.mes.service.qc.oqc.MesQcOqcService;
@@ -31,7 +32,6 @@
     @Resource private MesQcIpqcService ipqcService;
     @Resource private MesQcOqcService oqcService;
     @Resource private MesQcRqcService rqcService;
-    @Resource private cn.iocoder.yudao.module.mes.controller.admin.qc.patrol.PatrolMapper patrolMapper;
     @Resource private StorageAttachmentApi storageApi;
     @Resource private org.springframework.jdbc.core.JdbcTemplate jdbcTemplate;
 
@@ -83,6 +83,57 @@
         return success(true);
     }
 
+    // ==================== 杩囩▼妫�楠屻�屾楠岃銆嶉檮浠� ====================
+
+    /** 杩囩▼妫�楠岃闄勪欢锛歳ecordId 涓烘楠岀粨鏋滄槑缁� ID锛屾瘡琛岀嫭绔嬩笂浼� */
+    @GetMapping("/ipqc-detail/list")
+    @PreAuthorize("@ss.hasPermission('mes:qc-ipqc:query')")
+    public CommonResult<List<StorageBlobRespDTO>> listIpqcDetail(@RequestParam @NotNull Long detailId) {
+        validateIpqcDetail(detailId);
+        var files = storageApi.listAttachments(IPQC_DETAIL_RECORD_TYPE, detailId);
+        return success(files == null ? List.of() : files);
+    }
+
+    @PostMapping("/ipqc-detail/save")
+    @PreAuthorize("@ss.hasPermission('mes:qc-ipqc:update')")
+    @Transactional(rollbackFor = Exception.class)
+    public CommonResult<Boolean> saveIpqcDetail(@Valid @RequestBody IpqcDetailSaveReq req) {
+        validateIpqcDetail(req.getDetailId());
+        storageApi.bindAttachments("file", IPQC_DETAIL_RECORD_TYPE, req.getDetailId(),
+                req.getBlobIds().stream().distinct().toList());
+        return success(true);
+    }
+
+    @DeleteMapping("/ipqc-detail/remove")
+    @PreAuthorize("@ss.hasPermission('mes:qc-ipqc:update')")
+    @Transactional(rollbackFor = Exception.class)
+    public CommonResult<Boolean> removeIpqcDetail(@RequestParam @NotNull Long detailId,
+                                                  @RequestParam @NotNull Long blobId) {
+        validateIpqcDetail(detailId);
+        storageApi.removeReference("file", IPQC_DETAIL_RECORD_TYPE, detailId, blobId);
+        return success(true);
+    }
+
+    private static final String IPQC_DETAIL_RECORD_TYPE = "mes_qc_ipqc_detail_attachment";
+
+    /** 鏍¢獙鏄庣粏瀛樺湪涓斿睘浜庤繃绋嬫楠岀粨鏋� */
+    private void validateIpqcDetail(Long detailId) {
+        var ids = jdbcTemplate.queryForList(
+                "SELECT d.id FROM mes_qc_indicator_result_detail d "
+                        + "JOIN mes_qc_indicator_result r ON r.id = d.result_id "
+                        + "WHERE d.id = ? AND r.qc_type = ? AND d.deleted = 0 AND r.deleted = 0",
+                Long.class, detailId, cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum.IPQC.getType());
+        if (ids.isEmpty()) {
+            throw new ServiceException(400, "杩囩▼妫�楠岃涓嶅瓨鍦ㄦ垨涓嶅睘浜庤繃绋嬫楠屽崟锛屾棤娉曚笂浼犻檮浠�");
+        }
+    }
+
+    @Data public static class IpqcDetailSaveReq {
+        @NotNull private Long detailId;
+        /** 鍏佽绌哄垪琛細琛ㄧず娓呯┖璇ヨ闄勪欢 */
+        @NotNull @Size(max = 50) private List<@NotNull Long> blobIds;
+    }
+
     private String recordType(String type) {
         return switch (type) {
             case "iqc", "ipqc", "oqc", "rqc", "patrol" -> "mes_qc_" + type + "_attachment";
@@ -109,7 +160,13 @@
             case "ipqc" -> ipqcService.validateIpqcExists(id).getStatus();
             case "oqc" -> oqcService.validateOqcExists(id).getStatus();
             case "rqc" -> rqcService.validateRqcExists(id).getStatus();
-            case "patrol" -> { if (patrolMapper.selectById(id) == null) throw new ServiceException(400, "宸℃璁板綍涓嶅瓨鍦�"); yield 0; }
+            case "patrol" -> {
+                var ids = jdbcTemplate.queryForList(
+                        "SELECT id FROM mes_qc_patrol WHERE id = ? AND tenant_id = ? AND deleted = 0",
+                        Long.class, id, TenantContextHolder.getRequiredTenantId());
+                if (ids.isEmpty()) throw new ServiceException(400, "宸℃璁板綍涓嶅瓨鍦�");
+                yield 0;
+            }
             default -> throw new ServiceException(400, "璐ㄦ绫诲瀷鏃犳晥");
         };
     }

--
Gitblit v1.9.3