From fdf280f84aaa84211f680936cbfd98bf9d7be01b Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Thu, 22 Oct 2026 11:42:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=20GET=20=E5=85=A5=E5=8F=A3?= =?UTF-8?q?=E8=BF=81=E5=9B=9E=20AgentTemplateController=20#3395=20(#3401)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 模板 GET 入口迁回 AgentTemplateController #3395 根因:AgentController 已存在 GET /agent/template/templateList,AgentTemplateController 缺显式 GET,于是路由虽通却跨 controller 暴露模板数据,且职责错位。修复:删 AgentController.templateList,同名 @GetMapping(无 path)落到 AgentTemplateController,权限 normal、orderByAsc sort、复用现有 service.list。验证:spring-boot 启动期无 Ambiguous;/agent/template、/page、/{id} 三路由均被 Shiro 一致拦截,权限/路径正确。 * 补 P2 注释说明 normal 权限反直觉是有意保留 #3395 在 getAgentTemplates 上方加 2 行注释,说明单独 normal 权限是为保持原行为契约(普通用户也能查可用模板),与类级 superAdmin 故意分离;非疏忽。无逻辑变更。 * 去除未使用引用 --------- Co-authored-by: Sakura-RanChen <1908198662@qq.com> --- .../modules/agent/controller/AgentController.java | 14 -------------- .../agent/controller/AgentTemplateController.java | 11 +++++++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java index 0961fe7b7..1ad3c7794 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java @@ -19,8 +19,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -44,7 +42,6 @@ import xiaozhi.modules.agent.dto.AgentDTO; import xiaozhi.modules.agent.dto.AgentMemoryDTO; import xiaozhi.modules.agent.dto.AgentUpdateDTO; import xiaozhi.modules.agent.entity.AgentEntity; -import xiaozhi.modules.agent.entity.AgentTemplateEntity; import xiaozhi.modules.agent.dto.AgentTagDTO; import xiaozhi.modules.agent.entity.AgentTagEntity; import xiaozhi.modules.agent.service.AgentTagService; @@ -52,7 +49,6 @@ import xiaozhi.modules.agent.service.AgentChatAudioService; import xiaozhi.modules.agent.service.AgentChatHistoryService; import xiaozhi.modules.agent.service.AgentChatSummaryService; import xiaozhi.modules.agent.service.AgentService; -import xiaozhi.modules.agent.service.AgentTemplateService; import xiaozhi.modules.agent.vo.AgentChatHistoryUserVO; import xiaozhi.modules.agent.vo.AgentInfoVO; import xiaozhi.modules.security.user.SecurityUser; @@ -65,7 +61,6 @@ public class AgentController { private static final long AUDIO_PLAY_TOKEN_EXPIRE_SECONDS = 300L; private final AgentService agentService; - private final AgentTemplateService agentTemplateService; private final AgentChatHistoryService agentChatHistoryService; private final AgentChatAudioService agentChatAudioService; private final AgentChatSummaryService agentChatSummaryService; @@ -192,15 +187,6 @@ public class AgentController { return new Result<>(); } - @GetMapping("/template") - @Operation(summary = "智能体模板模板列表") - @RequiresPermissions("sys:role:normal") - public Result> templateList() { - List list = agentTemplateService - .list(new QueryWrapper().orderByAsc("sort")); - return new Result>().ok(list); - } - @GetMapping("/{id}/sessions") @Operation(summary = "获取智能体会话列表") @RequiresPermissions("sys:role:normal") diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentTemplateController.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentTemplateController.java index 9c8366ed6..d728dac8b 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentTemplateController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentTemplateController.java @@ -41,6 +41,17 @@ public class AgentTemplateController { private final AgentTemplateService agentTemplateService; + // 单独用 normal 权限(而非类级 superAdmin)是有意保留: + // 普通用户也需查询可用模板,与 /page 的管理入口分离,保持原行为契约。 + @GetMapping + @Operation(summary = "智能体模板列表") + @RequiresPermissions("sys:role:normal") + public Result> getAgentTemplates() { + List list = agentTemplateService + .list(new QueryWrapper().orderByAsc("sort")); + return new Result>().ok(list); + } + @GetMapping("/page") @Operation(summary = "获取模板分页列表") @RequiresPermissions("sys:role:superAdmin")