Răsfoiți Sursa

chore: auto bump version and changelog [skip ci]

iwt 1 lună în urmă
părinte
comite
3077747ce7

+ 33 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/AiGateway.java

@@ -181,6 +181,39 @@ public class AiGateway {
         }
     }
 
+    public Map<String, Object> generateQuestionnaire(Map<String, Object> inputs) {
+        if (!enabled || isCircuitOpen()) return null;
+
+        try {
+            ObjectNode body = objectMapper.createObjectNode();
+            body.put("member_name", inputs.getOrDefault("member_name", "").toString());
+            body.put("relationship_type", inputs.getOrDefault("relationship_type", "").toString());
+            if (inputs.containsKey("family_context")) {
+                body.set("family_context", objectMapper.valueToTree(inputs.get("family_context")));
+            }
+
+            HttpEntity<String> entity = new HttpEntity<>(body.toString(), createJsonHeaders());
+            String url = baseUrl + "/api/v1/questionnaire/generate";
+
+            ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
+
+            if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) {
+                JsonNode root = objectMapper.readTree(response.getBody());
+                Map<String, Object> result = new LinkedHashMap<>();
+                result.put("questionnaire_json", root.get("questionnaire_json").asText());
+                result.put("version", root.has("version") ? root.get("version").asText() : "");
+                consecutiveFailures.set(0);
+                log.debug("AiGateway generateQuestionnaire 成功");
+                return result;
+            }
+            return null;
+        } catch (Exception e) {
+            log.warn("AiGateway generateQuestionnaire 调用失败: {}", e.getMessage());
+            recordFailure();
+            return null;
+        }
+    }
+
     private List<Map<String, Object>> parseTasks(JsonNode tasksNode) {
         List<Map<String, Object>> tasks = new ArrayList<>();
         if (tasksNode != null && tasksNode.isArray()) {

+ 16 - 2
cfc-backend/src/main/java/com/etotem/cfc/service/RelationshipQuestionnaireService.java

@@ -40,6 +40,9 @@ public class RelationshipQuestionnaireService {
     @Resource
     private AIService aiService;
 
+    @Resource
+    private AiGateway aiGateway;
+
     /**
      * AI 生成关系问卷
      * 实际 AI 调用在 T15 实现,这里生成模拟问卷
@@ -60,8 +63,19 @@ public class RelationshipQuestionnaireService {
         // 生成版本号
         String version = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
 
-        // 模拟 AI 生成的问卷 JSON(实际在 T15 调用 Dify)
-        String aiJson = generateMockQuestionnaireJson(member);
+        // 优先 LangGraph 出题,失败 fallback mock
+        java.util.Map<String, Object> aiInputs = new java.util.HashMap<>();
+        aiInputs.put("member_name", member.getNickname());
+        aiInputs.put("relationship_type", member.getGeneration() != null && member.getGeneration() < 0 ? "child" : "parent");
+        java.util.Map<String, Object> aiResult = aiGateway.generateQuestionnaire(aiInputs);
+
+        String aiJson;
+        if (aiResult != null && aiResult.get("questionnaire_json") != null) {
+            aiJson = (String) aiResult.get("questionnaire_json");
+        } else {
+            aiJson = generateMockQuestionnaireJson(member);
+            log.warn("LangGraph 不可用,fallback mock 问卷: memberId={}", dto.getMemberId());
+        }
 
         // 保存快照
         RelationshipQuestionnaireSnapshot snapshot = new RelationshipQuestionnaireSnapshot();

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-a488a80123cc75e252912069ea443a1972d114af
+a1abe913cb4ee1a671842006a0f713fe4234808a

+ 2 - 2
cfc-web/package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "cfc-web",
-  "version": "1.0.785",
+  "version": "1.0.786",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "cfc-web",
-      "version": "1.0.785",
+      "version": "1.0.786",
       "dependencies": {
         "@wangeditor/editor": "^5.1.23",
         "@wangeditor/editor-for-vue": "^1.0.2",