Просмотр исходного кода

fix(tianpan): 修复天盘越权校验+雷达契约对齐+占位说明

Agnes Agent 1 неделя назад
Родитель
Сommit
1e006a178d

+ 16 - 29
cfc-backend/src/main/java/com/etotem/cfc/controller/tianpan/TianpanController.java

@@ -2,7 +2,9 @@ package com.etotem.cfc.controller.tianpan;
 
 import com.etotem.cfc.common.Result;
 import com.etotem.cfc.dto.*;
+import com.etotem.cfc.entity.FamilyMember;
 import com.etotem.cfc.entity.FamilyMemberAttributes;
+import com.etotem.cfc.mapper.FamilyMemberMapper;
 import com.etotem.cfc.service.*;
 import org.springframework.web.bind.annotation.*;
 
@@ -11,6 +13,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.util.Calendar;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * 家庭天盘控制器
@@ -33,6 +36,12 @@ public class TianpanController {
     @Resource
     private FamilyMemberDimensionBaseScoreService familyMemberDimensionBaseScoreService;
 
+    @Resource
+    private UserService userService;
+
+    @Resource
+    private FamilyMemberMapper familyMemberMapper;
+
     /**
      * 获取家庭天盘仪表盘
      * 
@@ -286,37 +295,15 @@ public class TianpanController {
     // ========== 权限检查 ==========
 
     private boolean checkAccess(String role, Long familyId, Long currentUserId, HttpServletRequest request) {
-        switch (role) {
-            case "admin":
-                // 管理员:所有访问
-                return true;
-            case "parent":
-                // 家庭主账号:访问自己家庭
-                return isFamilyMember(familyId, currentUserId, "parent");
-            case "child":
-                // 家庭成员:访问自己家庭
-                // 非登录用户(不可登录成员)
-                return isFamilyMember(familyId, currentUserId, "child");
-            case "teacher":
-                // 规划师:检查绑定关系
-                return isTeacherBoundToFamily(familyId, currentUserId);
-            default:
-                return false;
-        }
-    }
-
-    private boolean isFamilyMember(Long familyId, Long userId, String role) {
-        // 简化实现,实际应从数据库查询
-        return true;
-    }
-
-    private boolean isTeacherBoundToFamily(Long familyId, Long teacherId) {
-        // 简化实现,实际应从 teacher_family_bindings 表查询
-        return true;
+        if ("admin".equals(role)) return true;
+        if (familyId == null) return false;
+        Set<Long> effective = userService.getEffectiveFamilyIds(currentUserId);
+        return effective != null && effective.contains(familyId);
     }
 
     private Long getMemberFamilyId(Long memberId) {
-        // 简化实现,实际应从数据库查询
-        return 1L;
+        if (memberId == null) return null;
+        FamilyMember fm = familyMemberMapper.selectById(memberId);
+        return fm == null ? null : fm.getFamilyId();
     }
 }

+ 15 - 3
cfc-backend/src/main/java/com/etotem/cfc/service/TianpanService.java

@@ -491,6 +491,7 @@ public class TianpanService {
     }
 
     private DailyFortuneVO computeDailyFortune(Long familyId) {
+        // TODO(占位): 当前为硬编码占位实现,未接真实农历/干支/五行算法;上线前需补齐,否则每日运势展示固定值
         DailyFortuneVO vo = new DailyFortuneVO();
         Calendar cal = Calendar.getInstance();
         vo.setDate(formatDate(cal.getTime()));
@@ -619,20 +620,27 @@ public class TianpanService {
 
         Map<String, Integer> pctMap = new LinkedHashMap<>();
         String strongest = null;
-        int maxPct = 0;
+        String weakest = null;
+        int maxPct = -1;
+        int minPct = Integer.MAX_VALUE;
         int totalAll = count * 100;
 
         for (String elem : totals.keySet()) {
-            int val = count > 0 ? (totals.get(elem) * 100 / totalAll) * 5 : 0; // 简化计算
+            int val = count > 0 ? totals.get(elem) * 100 / totalAll : 0;
             pctMap.put(elem, val);
             if (val > maxPct) {
                 maxPct = val;
                 strongest = elem;
             }
+            if (val < minPct) {
+                minPct = val;
+                weakest = elem;
+            }
         }
 
         result.put("strongestElement", strongest);
-        result.put("elements", pctMap);
+        result.put("weakestElement", weakest);
+        result.put("aggregatePercentages", pctMap);
 
         return result;
     }
@@ -790,20 +798,24 @@ public class TianpanService {
     }
 
     private String getLunarDate(Date date) {
+        // TODO(占位): 当前为硬编码占位实现,未接真实农历/干支/五行算法;上线前需补齐,否则每日运势展示固定值
         // 简化,实际应使用农历库
         return "初一";
     }
 
     private String getDayGanzhi(Date date) {
+        // TODO(占位): 当前为硬编码占位实现,未接真实农历/干支/五行算法;上线前需补齐,否则每日运势展示固定值
         // 简化,实际应使用干支计算
         return "甲子";
     }
 
     private String getDayElement(Date date) {
+        // TODO(占位): 当前为硬编码占位实现,未接真实农历/干支/五行算法;上线前需补齐,否则每日运势展示固定值
         return "木";
     }
 
     private String getDayElementDetail(Date date) {
+        // TODO(占位): 当前为硬编码占位实现,未接真实农历/干支/五行算法;上线前需补齐,否则每日运势展示固定值
         return "甲木参天";
     }