|
|
@@ -0,0 +1,96 @@
|
|
|
+package com.etotem.cfc.controller.ai;
|
|
|
+
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.ButlerSession;
|
|
|
+import com.etotem.cfc.service.ButlerSessionService;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Tag(name = "AI管家", description = "AI管家会话管理接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/ai/butler")
|
|
|
+public class ButlerController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ButlerSessionService butlerSessionService;
|
|
|
+
|
|
|
+ @Operation(summary = "创建新会话")
|
|
|
+ @PostMapping("/sessions/create")
|
|
|
+ public Result<Map<String, Object>> createSession(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, String> params) {
|
|
|
+ String title = params.getOrDefault("title", "新会话");
|
|
|
+ String context = params.get("context");
|
|
|
+ Long sessionId = butlerSessionService.createSession(userId, title, context);
|
|
|
+ return Result.success(Collections.singletonMap("sessionId", sessionId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "更新会话Dify conversationId")
|
|
|
+ @PostMapping("/sessions/update-conversation")
|
|
|
+ public Result<Void> updateConversationId(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> params) {
|
|
|
+ Long sessionId = Long.valueOf(params.get("sessionId").toString());
|
|
|
+ String conversationId = (String) params.get("conversationId");
|
|
|
+ ButlerSession session = butlerSessionService.getSession(sessionId, userId);
|
|
|
+ if (session == null) {
|
|
|
+ return Result.error("会话不存在或无权访问");
|
|
|
+ }
|
|
|
+ butlerSessionService.updateConversationId(sessionId, conversationId);
|
|
|
+ return Result.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "归档会话")
|
|
|
+ @PostMapping("/sessions/archive")
|
|
|
+ public Result<Void> archiveSession(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> params) {
|
|
|
+ Long sessionId = Long.valueOf(params.get("sessionId").toString());
|
|
|
+ butlerSessionService.archiveSession(sessionId, userId);
|
|
|
+ return Result.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "获取会话列表")
|
|
|
+ @PostMapping("/sessions/list")
|
|
|
+ public Result<Page<ButlerSession>> listSessions(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> params) {
|
|
|
+ Integer page = params.get("page") != null ? Integer.valueOf(params.get("page").toString()) : 1;
|
|
|
+ Integer size = params.get("size") != null ? Integer.valueOf(params.get("size").toString()) : 20;
|
|
|
+ String status = (String) params.get("status");
|
|
|
+ Page<ButlerSession> sessions = butlerSessionService.getSessionsByUser(userId, page, size, status);
|
|
|
+ return Result.success(sessions);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "获取会话详情")
|
|
|
+ @PostMapping("/sessions/detail")
|
|
|
+ public Result<ButlerSession> sessionDetail(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> params) {
|
|
|
+ Long sessionId = Long.valueOf(params.get("sessionId").toString());
|
|
|
+ ButlerSession session = butlerSessionService.getSession(sessionId, userId);
|
|
|
+ if (session == null) {
|
|
|
+ return Result.error("会话不存在或无权访问");
|
|
|
+ }
|
|
|
+ return Result.success(session);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "删除会话")
|
|
|
+ @PostMapping("/sessions/delete")
|
|
|
+ public Result<Void> deleteSession(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> params) {
|
|
|
+ Long sessionId = Long.valueOf(params.get("sessionId").toString());
|
|
|
+ boolean deleted = butlerSessionService.deleteSession(sessionId, userId);
|
|
|
+ if (!deleted) {
|
|
|
+ return Result.error("会话不存在或无权删除");
|
|
|
+ }
|
|
|
+ return Result.success(null);
|
|
|
+ }
|
|
|
+}
|