|
@@ -3,12 +3,14 @@ package com.etotem.cfc.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
|
|
|
+import com.etotem.cfc.entity.FiveDimensionSelfCheck;
|
|
|
import com.etotem.cfc.entity.HealthPlan;
|
|
import com.etotem.cfc.entity.HealthPlan;
|
|
|
import com.etotem.cfc.entity.Task;
|
|
import com.etotem.cfc.entity.Task;
|
|
|
import com.etotem.cfc.entity.Family;
|
|
import com.etotem.cfc.entity.Family;
|
|
|
import com.etotem.cfc.entity.User;
|
|
import com.etotem.cfc.entity.User;
|
|
|
import com.etotem.cfc.mapper.FamilyMapper;
|
|
import com.etotem.cfc.mapper.FamilyMapper;
|
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.FiveDimensionSelfCheckMapper;
|
|
|
import com.etotem.cfc.mapper.HealthPlanMapper;
|
|
import com.etotem.cfc.mapper.HealthPlanMapper;
|
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
@@ -24,6 +26,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
@@ -53,6 +56,12 @@ public class HealthPlanServiceImpl implements HealthPlanService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private FamilyMemberMapper familyMemberMapper;
|
|
private FamilyMemberMapper familyMemberMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FiveDimensionSelfCheckMapper selfCheckMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private com.etotem.cfc.service.AiGateway aiGateway;
|
|
|
|
|
+
|
|
|
@Value("${langgraph.base-url:}")
|
|
@Value("${langgraph.base-url:}")
|
|
|
private String langgraphBaseUrl;
|
|
private String langgraphBaseUrl;
|
|
|
|
|
|
|
@@ -754,6 +763,50 @@ public class HealthPlanServiceImpl implements HealthPlanService {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Long generateFromSelfCheck(Long userId, Long checkId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ FiveDimensionSelfCheck check;
|
|
|
|
|
+ if (checkId != null) {
|
|
|
|
|
+ check = selfCheckMapper.selectById(checkId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ check = selfCheckMapper.selectOne(
|
|
|
|
|
+ new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<FiveDimensionSelfCheck>()
|
|
|
|
|
+ .eq(FiveDimensionSelfCheck::getUserId, userId)
|
|
|
|
|
+ .orderByDesc(FiveDimensionSelfCheck::getCreatedAt)
|
|
|
|
|
+ .last("LIMIT 1"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (check == null) return null;
|
|
|
|
|
+ Map<String, Integer> scores = objectMapper.readValue(check.getScoresJson(),
|
|
|
|
|
+ new com.fasterxml.jackson.core.type.TypeReference<Map<String, Integer>>() {});
|
|
|
|
|
+ List<String> lowDims = new ArrayList<>();
|
|
|
|
|
+ for (Map.Entry<String, Integer> e : scores.entrySet()) {
|
|
|
|
|
+ if (e.getValue() != null && e.getValue() <= 6) lowDims.add(e.getKey());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (lowDims.isEmpty()) return null;
|
|
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
|
|
+ if (user == null || user.getFamilyId() == null) return null;
|
|
|
|
|
+ Map<String, Object> inputs = new LinkedHashMap<>();
|
|
|
|
|
+ inputs.put("familyId", user.getFamilyId());
|
|
|
|
|
+ inputs.put("dimensions", String.join(",", lowDims));
|
|
|
|
|
+ inputs.put("goal", "基于五维自检结果,针对低分维度制定改善计划");
|
|
|
|
|
+ String planContent = aiGateway.generateHealthPlan(inputs);
|
|
|
|
|
+ if (planContent == null) return null;
|
|
|
|
|
+ HealthPlan plan = new HealthPlan();
|
|
|
|
|
+ plan.setFamilyId(user.getFamilyId());
|
|
|
|
|
+ plan.setDimensions(String.join(",", lowDims));
|
|
|
|
|
+ plan.setGoal("五维自检自动生成");
|
|
|
|
|
+ plan.setPlanContent(planContent);
|
|
|
|
|
+ plan.setStatus("draft");
|
|
|
|
|
+ plan.setCreatedAt(new Date());
|
|
|
|
|
+ healthPlanMapper.insert(plan);
|
|
|
|
|
+ return plan.getId();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("generateFromSelfCheck 失败: {}", e.getMessage());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Long autoGenerateAndPublish(Long familyId, Long memberId, String reportType) {
|
|
public Long autoGenerateAndPublish(Long familyId, Long memberId, String reportType) {
|
|
|
if (familyId == null || memberId == null) {
|
|
if (familyId == null || memberId == null) {
|