From d9a5ba1de2fce6bd8c50dace505e4bf7864043ba Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 22 十月 2026 15:01:07 +0800
Subject: [PATCH] feat(mdm): 新增智能体通用业务导入功能

---
 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/agent/SystemAgentImportBridgeController.java |   37 ++++++++++++++++++++++++++++++-------
 1 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/agent/SystemAgentImportBridgeController.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/agent/SystemAgentImportBridgeController.java
index bbba5e3..0f8c195 100644
--- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/agent/SystemAgentImportBridgeController.java
+++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/agent/SystemAgentImportBridgeController.java
@@ -31,33 +31,56 @@
 
     private static final Set<String> ACTIONS = Set.of("material_import.prepare", "material_import.read",
             "material_import.review", "material_import.preflight", "material_import.commit",
-            "material_import.read_receipt");
+            "material_import.read_receipt",
+            "conversation.create", "conversation.read", "conversation.message",
+            "conversation.action", "conversation.report");
+
+    /** module_id 鈫� 涓氬姟瀵煎叆鏉冮檺锛汸ython 浠ユā鍧� ID 浣滀负鎺堟潈 resource銆� */
+    private static final Map<String, String> MODULE_PERMISSIONS = Map.of(
+            "mdm.item", SystemAgentBridgeGuard.PERMISSION_ITEM_IMPORT,
+            "srm.supplier", "srm:supplier:create",
+            "mes.bom", "mes:md-item:create",
+            "mes.qc-template", "mes:qc-template:create",
+            "mes.mps", "mes:pro-mps:create",
+            "mes.route", "mes:pro-route:create");
 
     @Resource
     private SystemAgentImportBridgeService bridgeService;
     @Resource
     private SystemAgentBridgeGuard bridgeGuard;
 
+    private static final String IMPORT_PERMISSIONS_EXPR =
+            "@ss.hasAnyPermissions('mdm:item:import','srm:supplier:create','mes:md-item:create',"
+                    + "'mes:qc-template:create','mes:pro-mps:create','mes:pro-route:create')";
+
     @PostMapping("/import-sessions")
-    @PreAuthorize("@ss.hasPermission('mdm:item:import')")
+    @PreAuthorize(IMPORT_PERMISSIONS_EXPR)
     public CommonResult<Long> createSession() {
         return success(bridgeService.createSession());
     }
 
     @PostMapping("/import-sessions/{sessionId}/attachments")
-    @PreAuthorize("@ss.hasPermission('mdm:item:import')")
+    @PreAuthorize(IMPORT_PERMISSIONS_EXPR)
     public CommonResult<Long> bindAttachment(@PathVariable Long sessionId, @Valid @RequestBody BindRequest request) {
         return success(bridgeService.bindAttachment(sessionId, request.getBlobId()));
     }
 
     @PostMapping("/authorize")
-    @PreAuthorize("@ss.hasPermission('mdm:item:import')")
+    @PreAuthorize(IMPORT_PERMISSIONS_EXPR)
     public CommonResult<Map<String, String>> authorize(
             @RequestHeader(value = "X-Agent-Service-Token", required = false) String serviceToken,
             @Valid @RequestBody AuthorizeRequest request) {
-        AgentPrincipal principal = bridgeGuard.require(serviceToken, SystemAgentBridgeGuard.PERMISSION_ITEM_IMPORT);
         if (!ACTIONS.contains(request.getAction())) {
             throw new AgentBridgeException(HttpStatus.FORBIDDEN, "ACTION_FORBIDDEN", "涓嶆敮鎸佺殑鏅鸿兘浣撴搷浣�");
+        }
+        AgentPrincipal principal;
+        if (request.getAction().startsWith("conversation.")) {
+            String permission = MODULE_PERMISSIONS.get(request.getResource());
+            principal = permission == null
+                    ? bridgeGuard.requireAny(serviceToken)
+                    : bridgeGuard.require(serviceToken, permission);
+        } else {
+            principal = bridgeGuard.require(serviceToken, SystemAgentBridgeGuard.PERMISSION_ITEM_IMPORT);
         }
         if (requiresAttachmentOwnership(request.getAction())) {
             bridgeService.requireOwnedAttachmentRef(parseId(request.getResource()));
@@ -69,11 +92,11 @@
     }
 
     @GetMapping("/attachments/{attachmentId}")
-    @PreAuthorize("@ss.hasPermission('mdm:item:import')")
+    @PreAuthorize(IMPORT_PERMISSIONS_EXPR)
     public ResponseEntity<FileSystemResource> downloadAttachment(
             @RequestHeader(value = "X-Agent-Service-Token", required = false) String serviceToken,
             @PathVariable Long attachmentId) {
-        bridgeGuard.require(serviceToken, SystemAgentBridgeGuard.PERMISSION_ITEM_IMPORT);
+        bridgeGuard.requireAny(serviceToken);
         SystemAgentAttachmentRef ref = bridgeService.requireOwnedAttachmentRef(attachmentId);
         return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM)
                 .contentLength(ref.byteSize())

--
Gitblit v1.9.3