|
|
@@ -5,6 +5,7 @@ import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.dto.EnergySandboxDTO;
|
|
|
import com.etotem.cfc.dto.MemberEnergyDTO;
|
|
|
import com.etotem.cfc.dto.UnlockGateDTO;
|
|
|
+import com.etotem.cfc.entity.EnergyDimensionConfig;
|
|
|
import com.etotem.cfc.entity.EnergyLog;
|
|
|
import com.etotem.cfc.entity.UnlockGate;
|
|
|
import com.etotem.cfc.entity.User;
|
|
|
@@ -282,6 +283,94 @@ public class EnergyController {
|
|
|
return Result.success("配置成功");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 家长端只读查看五维(身/心/智/行/富)定义与权重(SC-P-19 / energy.dimension.view)。
|
|
|
+ *
|
|
|
+ * <p>只读:仅读配置,不触发任何 Mapper 写操作(写配置走 admin.dimension.config / S-cfc-199)。
|
|
|
+ * 配置未同步或部分同步时按默认口径兜底并给出说明;已同步配置的权重合计 ≠100% 时返回 400。
|
|
|
+ * 显式指定非本家庭成员 memberId 时按 SC-X-19 隔离口径 403。</p>
|
|
|
+ */
|
|
|
+ @Operation(summary = "只读查看五维能量定义与权重(配置未同步时兜底)")
|
|
|
+ @PostMapping("/config")
|
|
|
+ public Result<Map<String, Object>> getDimensionConfigView(
|
|
|
+ @RequestBody(required = false) Map<String, Object> params,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
+ @RequestAttribute(value = "currentMemberId", required = false) Long currentMemberId) {
|
|
|
+
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
+ Long memberId = params != null
|
|
|
+ ? ParamUtils.getLong(params.get("memberId"), currentMemberId) : currentMemberId;
|
|
|
+ // SC-X-19 横向越权:显式指定非本家庭成员一律 403;本人/未指定放行
|
|
|
+ if (memberId != null && currentMemberId != null && !memberId.equals(currentMemberId)
|
|
|
+ && !energyService.isMemberInFamily(memberId, familyId)) {
|
|
|
+ return Result.forbidden("无权访问该成员的能量配置");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 五维默认口径(设计 §1.1:身/心/智/行/富;等权兜底合计 100%)
|
|
|
+ String[] codes = {"body", "mind", "wisdom", "action", "wealth"};
|
|
|
+ String[] names = {"身", "心", "智", "行", "富"};
|
|
|
+ String[] definitions = {
|
|
|
+ "身体维度:体质、精力、运动与生活习惯等身心健康基础",
|
|
|
+ "心理维度:情绪、性格、抗压与自我认知等心理状态",
|
|
|
+ "智力维度:学习、思维、认知与知识吸收等能力",
|
|
|
+ "行动维度:执行力、目标管理、坚持与自律等行为习惯",
|
|
|
+ "财富维度:财商、资源管理与价值观等财富素养"
|
|
|
+ };
|
|
|
+
|
|
|
+ List<EnergyDimensionConfig> configs = energyService.getDimensionConfigs();
|
|
|
+ Map<String, EnergyDimensionConfig> configByCode = new LinkedHashMap<String, EnergyDimensionConfig>();
|
|
|
+ double weightSum = 0.0;
|
|
|
+ boolean hasConfig = configs != null && !configs.isEmpty();
|
|
|
+ if (hasConfig) {
|
|
|
+ for (EnergyDimensionConfig config : configs) {
|
|
|
+ if (config == null || config.getDimension() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String code = config.getDimension().trim().toLowerCase(Locale.ROOT);
|
|
|
+ configByCode.put(code, config);
|
|
|
+ weightSum += dimensionWeightPercent(config.getWeight());
|
|
|
+ }
|
|
|
+ // TC-P-19-E:已同步配置权重合计必须 =100%,否则 400 拒绝,不静默展示非法权重
|
|
|
+ if (configByCode.isEmpty() || Math.abs(weightSum - 100.0) > 1e-6) {
|
|
|
+ return Result.badRequest("权重合计需为 100%");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean fallback = !hasConfig || configByCode.size() < codes.length;
|
|
|
+ Map<String, Object> data = new LinkedHashMap<String, Object>();
|
|
|
+ for (int i = 0; i < codes.length; i++) {
|
|
|
+ String code = codes[i];
|
|
|
+ EnergyDimensionConfig config = configByCode.get(code);
|
|
|
+ Map<String, Object> dim = new LinkedHashMap<String, Object>();
|
|
|
+ dim.put("code", code);
|
|
|
+ dim.put("name", names[i]);
|
|
|
+ dim.put("weight", config != null && config.getWeight() != null
|
|
|
+ ? config.getWeight() : (hasConfig ? 0 : 20));
|
|
|
+ String definition = config != null && config.getDefinition() != null
|
|
|
+ && !config.getDefinition().trim().isEmpty() ? config.getDefinition() : definitions[i];
|
|
|
+ dim.put("definition", definition);
|
|
|
+ data.put(code, dim);
|
|
|
+ }
|
|
|
+ data.put("fallback", fallback);
|
|
|
+ data.put("synced", !fallback);
|
|
|
+ if (fallback) {
|
|
|
+ data.put("notice", "部分维度配置未同步,已按默认口径兜底展示");
|
|
|
+ return Result.success("五维配置部分未同步,已使用兜底默认值", data);
|
|
|
+ }
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** ratio(0~1) 或百分比(0~100) 统一折算为百分比口径(与配置契约一致)。 */
|
|
|
+ private static double dimensionWeightPercent(Integer weight) {
|
|
|
+ if (weight == null) {
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+ double value = weight.doubleValue();
|
|
|
+ return value > 0.0 && value <= 1.0 ? value * 100.0 : value;
|
|
|
+ }
|
|
|
+
|
|
|
@Operation(summary = "获取五维分数历史")
|
|
|
@PostMapping("/score-history")
|
|
|
public Result<List<com.etotem.cfc.entity.FiveDimensionScore>> getScoreHistory(
|