|
|
@@ -1130,13 +1130,11 @@ public class EnergyService {
|
|
|
dto.setEmotionStressCoping(safeScore(dan.getStressCopingScore()));
|
|
|
dto.setEmotionSelfAwareness(safeScore(dan.getSelfAwarenessScore()));
|
|
|
|
|
|
- // 自驱力(3维)+ 自我概念(1维)— 从 structuredAnalysis JSON 解析
|
|
|
+ // 自驱力(3维)+ 自我概念(1维)— 从 structuredAnalysis JSON 嵌套 extra 解析
|
|
|
Map<String, Object> analysis = parseStructuredAnalysis(dan.getStructuredAnalysis());
|
|
|
if (analysis != null) {
|
|
|
- dto.setDriveAutonomy(getIntFromAnalysis(analysis, "selfDriving_autonomy"));
|
|
|
- dto.setDriveCompetence(getIntFromAnalysis(analysis, "selfDriving_competence"));
|
|
|
- dto.setDriveRelatedness(getIntFromAnalysis(analysis, "selfDriving_relatedness"));
|
|
|
- dto.setSelfConceptOverall(getIntFromAnalysis(analysis, "selfConcept_overall"));
|
|
|
+ parseSelfDrivingFromAnalysis(dto, analysis);
|
|
|
+ parseSelfConceptFromAnalysis(dto, analysis);
|
|
|
}
|
|
|
}
|
|
|
// 旧字段兼容
|
|
|
@@ -1170,13 +1168,17 @@ public class EnergyService {
|
|
|
dto.setWisdomGrowthMindset(0);
|
|
|
}
|
|
|
|
|
|
- /** 智·成长型思维 — 孩子版:从 DAN structuredAnalysis 解析 */
|
|
|
+ /** 智·成长型思维 — 孩子版:从 DAN structuredAnalysis extra.growthMindset 解析 */
|
|
|
private void setWisdomSubDimensionsForChild(MemberEnergyDTO dto, FamilyMember child) {
|
|
|
DanAssessmentResult dan = findLatestDanResult(child.getId());
|
|
|
if (dan != null) {
|
|
|
Map<String, Object> analysis = parseStructuredAnalysis(dan.getStructuredAnalysis());
|
|
|
if (analysis != null) {
|
|
|
- dto.setWisdomGrowthMindset(getIntFromAnalysis(analysis, "growthMindset_overall"));
|
|
|
+ Map<String, Object> extra = (Map<String, Object>) analysis.get("extra");
|
|
|
+ Map<String, Object> gm = (Map<String, Object>) getNestedMap(extra, "growthMindset");
|
|
|
+ if (gm != null) {
|
|
|
+ dto.setWisdomGrowthMindset(getIntFromNestedMap(gm, "成长型思维", "growthMindset"));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1191,15 +1193,61 @@ public class EnergyService {
|
|
|
dto.setWealthChildLegacy(0);
|
|
|
}
|
|
|
|
|
|
- /** 从 structuredAnalysis JSON 中提取整数分值 */
|
|
|
- private Integer getIntFromAnalysis(Map<String, Object> analysis, String key) {
|
|
|
- if (analysis == null) return 0;
|
|
|
- Object val = analysis.get(key);
|
|
|
+ /** 从 structuredAnalysis 解析自驱力3维(extra.selfDriving 嵌套 Map,中文 key) */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private void parseSelfDrivingFromAnalysis(MemberEnergyDTO dto, Map<String, Object> analysis) {
|
|
|
+ if (analysis == null) return;
|
|
|
+ Map<String, Object> extra = (Map<String, Object>) analysis.get("extra");
|
|
|
+ if (extra == null) return;
|
|
|
+ Map<String, Object> sd = (Map<String, Object>) extra.get("selfDriving");
|
|
|
+ if (sd == null) return;
|
|
|
+ dto.setDriveAutonomy(getIntFromNestedMap(sd, "自主性", "selfDriving_autonomy"));
|
|
|
+ dto.setDriveCompetence(getIntFromNestedMap(sd, "胜任感", "selfDriving_competence"));
|
|
|
+ dto.setDriveRelatedness(getIntFromNestedMap(sd, "归属感", "selfDriving_relatedness"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 从 structuredAnalysis 解析综合自我概念(extra.selfConcept 各维均值) */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private void parseSelfConceptFromAnalysis(MemberEnergyDTO dto, Map<String, Object> analysis) {
|
|
|
+ if (analysis == null) return;
|
|
|
+ Map<String, Object> extra = (Map<String, Object>) analysis.get("extra");
|
|
|
+ if (extra == null) return;
|
|
|
+ Map<String, Object> sc = (Map<String, Object>) extra.get("selfConcept");
|
|
|
+ if (sc == null || sc.isEmpty()) return;
|
|
|
+ // 取所有值的均值作为综合自我概念分
|
|
|
+ int sum = 0, count = 0;
|
|
|
+ for (Object val : sc.values()) {
|
|
|
+ Integer v = parseNumber(val);
|
|
|
+ if (v != null) { sum += v; count++; }
|
|
|
+ }
|
|
|
+ dto.setSelfConceptOverall(count > 0 ? sum / count : 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 安全获取嵌套 map */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private Map<String, Object> getNestedMap(Map<String, Object> parent, String key) {
|
|
|
+ if (parent == null) return null;
|
|
|
+ Object val = parent.get(key);
|
|
|
+ return val instanceof Map ? (Map<String, Object>) val : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 从嵌套 map 中提取整数分值(优先中文 key,回退英文 key) */
|
|
|
+ private Integer getIntFromNestedMap(Map<String, Object> map, String chineseKey, String englishKey) {
|
|
|
+ if (map == null) return 0;
|
|
|
+ // 先试中文 key
|
|
|
+ Object val = map.get(chineseKey);
|
|
|
+ if (val == null) val = map.get(englishKey);
|
|
|
+ return parseNumber(val);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 将 Object 解析为整数 */
|
|
|
+ private Integer parseNumber(Object val) {
|
|
|
+ if (val == null) return null;
|
|
|
if (val instanceof Number) return ((Number) val).intValue();
|
|
|
if (val instanceof String) {
|
|
|
- try { return Integer.parseInt((String) val); } catch (NumberFormatException e) { return 0; }
|
|
|
+ try { return Integer.parseInt(((String) val).trim()); } catch (NumberFormatException e) { return null; }
|
|
|
}
|
|
|
- return 0;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/** 解析 structuredAnalysis JSON(使用 fastjson) */
|