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

refactor(family): 年龄优先判定孩子角色

computeEffectiveRole()改为以birthday年龄为主判定标准,生成年/children不再优先依赖generation字段

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Sisyphus 1 месяц назад
Родитель
Сommit
a36a584a6f

+ 8 - 7
cfc-backend/src/main/java/com/etotem/cfc/service/FamilyMemberService.java

@@ -391,18 +391,19 @@ public class FamilyMemberService {
 
     /**
      * 计算成员的实际角色(effective role)
-     * 基于 generation:>=0 → parent, <0 → child;无 generation 则按年龄 fallback
+     * 优先使用年龄判定(birthday → age < childThreshold → child),
+     * 无生日数据时回退到 generation 判定
      */
     private String computeEffectiveRole(FamilyMember member) {
-        // 基于 generation 计算:generation >= 0 = parent, generation < 0 = child
-        if (member.getGeneration() != null) {
-            return member.getGeneration() >= 0 ? "parent" : "child";
-        }
-        // 兼容旧数据(无 generation):按年龄 fallback
+        // 优先按年龄判定(生日优先于 generation)
         if (member.getBirthday() != null) {
             int age = calculateAge(member.getBirthday());
             int childThreshold = systemConfigService.getChildAgeThreshold();
-            if (age < childThreshold) return "child";
+            return age < childThreshold ? "child" : "parent";
+        }
+        // 无生日数据:按 generation 回退(generation >= 0 = parent, < 0 = child)
+        if (member.getGeneration() != null) {
+            return member.getGeneration() >= 0 ? "parent" : "child";
         }
         return "parent";
     }