Ver código fonte

fix(backend): 家庭收益成员贡献榜使用真实家庭成员

- 注入 UserMapper 替代硬编码 familyId=1 与 isFamilyAdmin=true
- getFamilyId() 通过 userMapper.selectById 查询用户真实 familyId
- isFamilyAdmin() 检查 user.isFamilyAdmin 字段
- 修复成员贡献榜展示非本家庭用户的问题

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
E2E Test Bot 4 dias atrás
pai
commit
2e6e3f27d1

+ 11 - 6
cfc-backend/src/main/java/com/etotem/cfc/controller/FamilyEarningsController.java

@@ -3,6 +3,8 @@ package com.etotem.cfc.controller;
 import com.etotem.cfc.common.Result;
 import com.etotem.cfc.dto.FamilyEarningsSummaryDTO;
 import com.etotem.cfc.entity.FamilyEarningsRecord;
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.mapper.UserMapper;
 import com.etotem.cfc.service.FamilyEarningsService;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestAttribute;
@@ -21,6 +23,9 @@ public class FamilyEarningsController {
     @Resource
     private FamilyEarningsService familyEarningsService;
     
+    @Resource
+    private UserMapper userMapper;
+    
     /**
      * 获取家庭收益总览
      */
@@ -115,17 +120,17 @@ public class FamilyEarningsController {
      * 获取用户的家庭ID
      */
     private Long getFamilyId(Long userId) {
-        // 通过userId查询familyId
-        // 实际项目中需要实现这个方法
-        return 1L; // 示例值,需要替换为实际查询逻辑
+        if (userId == null) return null;
+        User user = userMapper.selectById(userId);
+        return user != null ? user.getFamilyId() : null;
     }
     
     /**
      * 检查用户是否是家庭管理员
      */
     private boolean isFamilyAdmin(Long userId) {
-        // 通过userId查询用户信息,检查isFamilyAdmin字段
-        // 实际项目中需要实现这个方法
-        return true; // 示例值,需要替换为实际查询逻辑
+        if (userId == null) return false;
+        User user = userMapper.selectById(userId);
+        return user != null && user.getIsFamilyAdmin() != null && user.getIsFamilyAdmin();
     }
 }