|
|
@@ -335,11 +335,56 @@ public class EnergyService {
|
|
|
if (healthScore != null) {
|
|
|
return healthScore;
|
|
|
}
|
|
|
- // 2. 降级:运动/户外类任务完成率
|
|
|
+ // 2. 7维健康维度评分加权(T4: 7-Dim→Body Energy)
|
|
|
+ int sevenDimScore = calcSevenDimBodyScore(child.getId());
|
|
|
+ if (sevenDimScore > 0) {
|
|
|
+ return sevenDimScore;
|
|
|
+ }
|
|
|
+ // 3. 降级:运动/户外类任务完成率
|
|
|
return calcTaskCompletionRate(child.getId(), "child",
|
|
|
Arrays.asList("运动", "体育", "户外", "健康"), 365);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 7维健康维度评分加权 → body 能量 (T4/T12)
|
|
|
+ * 从 health_dimension_scores 表读取成员最新的所有维度评分,
|
|
|
+ * 按设计权重加权计算 0-100 分的综合 body 能量。
|
|
|
+ * 各维度权重参考 specs/2026-06-26-health-dimensions-design-spec.md:
|
|
|
+ * 肠胃(20%) 营养(18%) 运动(15%) 睡眠(15%) 生长(12%) 免疫(10%) 视力(10%)
|
|
|
+ */
|
|
|
+ private int calcSevenDimBodyScore(Long memberId) {
|
|
|
+ try {
|
|
|
+ List<HealthDimensionScore> scores = healthDimensionScoreService.getLatestScores(memberId);
|
|
|
+ if (scores == null || scores.isEmpty()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ double weightedSum = 0;
|
|
|
+ double totalWeight = 0;
|
|
|
+ java.util.Map<String, Double> weights = new java.util.HashMap<>();
|
|
|
+ weights.put("gut", 0.20);
|
|
|
+ weights.put("nutrition", 0.18);
|
|
|
+ weights.put("exercise", 0.15);
|
|
|
+ weights.put("sleep", 0.15);
|
|
|
+ weights.put("growth", 0.12);
|
|
|
+ weights.put("immunity", 0.10);
|
|
|
+ weights.put("vision", 0.10);
|
|
|
+ for (HealthDimensionScore s : scores) {
|
|
|
+ Double w = weights.get(s.getDimension());
|
|
|
+ if (w != null && s.getScore() != null) {
|
|
|
+ weightedSum += s.getScore() * w;
|
|
|
+ totalWeight += w;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (totalWeight == 0) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return (int) Math.round(weightedSum / totalWeight);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("7维健康维度评分加权失败, memberId={}: {}", memberId, e.getMessage());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/** 孩子 心 — DAN EMI 70% + 先天 30% + 行为修正 */
|
|
|
private int calcChildMind(FamilyMember child) {
|
|
|
Long childId = child.getId();
|