Przeglądaj źródła

feat(family): S-cfc-58 加入家庭准入校验规则(姓名/生日/性别)

- createJoinRequest 增加 validateJoinRequiredInfo 门禁(规格 2026-11-07-family-join-required-info WI-2/WI-3)
- 真实姓名 trim 后 1-20 字;出生日期非空且 1900-01-01 ≤ birthday ≤ 今天(不设年龄上限);性别严格 male/female
- 校验失败直接抛错、不写 family_join_requests;无 DB 迁移
- FamilyJoinValidationRulesContractTest 14/14 GREEN(连带 joinGate/joinRequiredInfo 共 36 用例全绿)
iwt 6 dni temu
rodzic
commit
991532ba7e

+ 37 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/FamilyJoinRequestService.java

@@ -18,6 +18,7 @@ import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -109,6 +110,9 @@ public class FamilyJoinRequestService {
             throw new RuntimeException("用户不存在");
         }
 
+        // 准入校验:被邀请人必须已完善真实姓名/出生日期/性别(规格 2026-11-07-family-join-required-info WI-2/WI-3)
+        validateJoinRequiredInfo(currentUser);
+
         // 检查用户是否已属于该家庭
         if (currentUser.getFamilyId() != null && currentUser.getFamilyId().equals(family.getId())) {
             throw new RuntimeException("您已是该家庭成员");
@@ -519,6 +523,39 @@ public class FamilyJoinRequestService {
         }
     }
 
+    /**
+     * 加入家庭准入校验(规格 2026-11-07-family-join-required-info §4.1):
+     * 真实姓名 trim 后 1-20 字;出生日期非空且不晚于今天、不早于 1900-01-01(不设年龄上限);
+     * 性别严格 male/female(大小写敏感)。校验失败直接抛错,不写库。
+     */
+    private void validateJoinRequiredInfo(User u) {
+        String realName = u.getRealName() == null ? null : u.getRealName().trim();
+        if (realName == null || realName.isEmpty() || realName.length() > 20) {
+            throw new RuntimeException("请先完善真实姓名、出生日期与性别后再申请加入家庭");
+        }
+        if (u.getBirthday() == null) {
+            throw new RuntimeException("请先完善真实姓名、出生日期与性别后再申请加入家庭");
+        }
+        if (!"male".equals(u.getGender()) && !"female".equals(u.getGender())) {
+            throw new RuntimeException("请先完善真实姓名、出生日期与性别后再申请加入家庭");
+        }
+        // 按天比较:等于今天、等于 1900-01-01 均放行;不设年龄上限
+        Calendar today = Calendar.getInstance();
+        today.set(Calendar.HOUR_OF_DAY, 0);
+        today.set(Calendar.MINUTE, 0);
+        today.set(Calendar.SECOND, 0);
+        today.set(Calendar.MILLISECOND, 0);
+        if (u.getBirthday().after(today.getTime())) {
+            throw new RuntimeException("出生日期不能晚于今天");
+        }
+        Calendar earliest = Calendar.getInstance();
+        earliest.clear();
+        earliest.set(1900, Calendar.JANUARY, 1, 0, 0, 0);
+        if (u.getBirthday().before(earliest.getTime())) {
+            throw new RuntimeException("出生日期不合法");
+        }
+    }
+
     /**
      * User.familyRole 推导表(绝对辈分 + 性别):
      * ≥2 → 爷爷/奶奶(「姥爷/姥姥」无法由辈分推导,统一落奶奶/爷爷,用户可在「我的资料」修正)