Browse Source

feat(self-check): AIChat sendMessage 支持 selfCheckId 注入上下文(P1-2)

iwt 2 months ago
parent
commit
d24e5f0de0

+ 20 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/ai/AIChatController.java

@@ -62,6 +62,12 @@ public class AIChatController {
     @Resource
     @Resource
     private com.etotem.cfc.service.PortraitService portraitService;
     private com.etotem.cfc.service.PortraitService portraitService;
 
 
+    @Resource
+    private com.etotem.cfc.mapper.FiveDimensionSelfCheckMapper selfCheckMapper;
+
+    @Resource
+    private com.fasterxml.jackson.databind.ObjectMapper objectMapper;
+
     @Operation(summary = "发送聊天消息(支持传入reportId以解读报告)")
     @Operation(summary = "发送聊天消息(支持传入reportId以解读报告)")
     @PostMapping("/chat/send")
     @PostMapping("/chat/send")
     public Result<Map<String, Object>> sendMessage(
     public Result<Map<String, Object>> sendMessage(
@@ -71,6 +77,7 @@ public class AIChatController {
         String conversationId = params.get("conversationId");
         String conversationId = params.get("conversationId");
         String reportIdStr = params.get("reportId");
         String reportIdStr = params.get("reportId");
         String surveyIdStr = params.get("surveyId");
         String surveyIdStr = params.get("surveyId");
+        String selfCheckIdStr = params.get("selfCheckId");
 
 
         if (query == null || query.trim().isEmpty()) {
         if (query == null || query.trim().isEmpty()) {
             return Result.error("消息不能为空");
             return Result.error("消息不能为空");
@@ -121,6 +128,19 @@ public class AIChatController {
             inputs.put("portrait_prompt", chatPortrait);
             inputs.put("portrait_prompt", chatPortrait);
         }
         }
 
 
+        // 注入自检上下文(P1-2)
+        if (selfCheckIdStr != null && !selfCheckIdStr.trim().isEmpty()) {
+            try {
+                Long selfCheckId = Long.valueOf(selfCheckIdStr);
+                com.etotem.cfc.entity.FiveDimensionSelfCheck selfCheck = selfCheckMapper.selectById(selfCheckId);
+                if (selfCheck != null) {
+                    inputs.put("self_check_result", objectMapper.writeValueAsString(selfCheck));
+                }
+            } catch (Exception e) {
+                log.warn("注入自检上下文失败: {}", e.getMessage());
+            }
+        }
+
         // AI记忆层注入(会话摘要+关键事实)
         // AI记忆层注入(会话摘要+关键事实)
         inputs = aiService.enrichInputsWithMemory(userId, conversationId, inputs);
         inputs = aiService.enrichInputsWithMemory(userId, conversationId, inputs);