From be72b1465011f2d481d545f4687a0ea2f15a1d35 Mon Sep 17 00:00:00 2001 From: SerenNoble Date: Sun, 28 Jun 2026 17:22:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=B6=E9=95=BF=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E5=88=87=E6=8D=A2/=E6=81=A2=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E8=A7=92=E8=89=B2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 UserPersonaController: - POST /persona/switch {agentId} 调用 setManual,标 manual=1,自动任务不再覆盖 - POST /persona/auto 调用 resetAuto,恢复自动匹配 均需 sys:role:normal 权限,按当前登录用户 SecurityUser.getUser().getId() 取 userId Co-Authored-By: Claude --- .../controller/UserPersonaController.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/agent/controller/UserPersonaController.java diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/UserPersonaController.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/UserPersonaController.java new file mode 100644 index 000000000..6eff80109 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/UserPersonaController.java @@ -0,0 +1,44 @@ +package xiaozhi.modules.agent.controller; + +import java.util.Map; + +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import lombok.AllArgsConstructor; +import xiaozhi.common.utils.Result; +import xiaozhi.modules.agent.service.UserPersonaAssignmentService; +import xiaozhi.modules.security.user.SecurityUser; + +@RestController +@RequestMapping("/persona") +@AllArgsConstructor +public class UserPersonaController { + + private final UserPersonaAssignmentService userPersonaAssignmentService; + + /** 家长手动切换角色(立即生效,标 manual=1,自动任务不再覆盖) */ + @PostMapping("/switch") + @RequiresPermissions("sys:role:normal") + public Result switchPersona(@RequestBody Map body) { + String agentId = body.get("agentId"); + if (agentId == null || agentId.isBlank()) { + return new Result().error("agentId 不能为空"); + } + Long userId = SecurityUser.getUser().getId(); + userPersonaAssignmentService.setManual(userId, agentId); + return new Result(); + } + + /** 恢复自动匹配(manual=0) */ + @PostMapping("/auto") + @RequiresPermissions("sys:role:normal") + public Result resetAuto() { + Long userId = SecurityUser.getUser().getId(); + userPersonaAssignmentService.resetAuto(userId); + return new Result(); + } +}