Explorar el Código

fix(family): 修复邀请流程 - 保存familyRole、修复轮询逻辑

iwt hace 1 mes
padre
commit
e11174617d

+ 3 - 0
cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java

@@ -8301,5 +8301,8 @@ private void runMigration100() {
 		ensureColumn("family_relationships", "trust_score", "DECIMAL(5,2) DEFAULT 0 COMMENT '信任度(答卷人视角)'");
 		ensureColumn("family_relationships", "intimacy_score", "DECIMAL(5,2) DEFAULT 0 COMMENT '亲密度(答卷人视角)'");
 		ensureColumn("family_relationships", "communication_score", "DECIMAL(5,2) DEFAULT 0 COMMENT '沟通质量(答卷人视角)'");
+
+		// 迁移194: family_join_requests 添加 family_role 列(保存申请人角色)
+		ensureColumn("family_join_requests", "family_role", "VARCHAR(20) DEFAULT NULL COMMENT '申请人在家庭中的角色:爸爸/妈妈/爷爷/奶奶等'");
 	}
 }

+ 4 - 1
cfc-backend/src/main/java/com/etotem/cfc/controller/family/FamilyInviteController.java

@@ -111,6 +111,9 @@ public class FamilyInviteController {
 
         String inviteCode = body.get("inviteCode");
 
+        // 获取申请人角色
+        String familyRole = body.get("familyRole");
+
         // 兼容邀请令牌(token):通过 token 解析到 familyId
         if (inviteCode == null || inviteCode.trim().isEmpty()) {
             String token = body.get("token");
@@ -129,7 +132,7 @@ public class FamilyInviteController {
         }
 
         try {
-            com.etotem.cfc.entity.FamilyJoinRequest request = familyJoinRequestService.createJoinRequest(userId, inviteCode);
+            com.etotem.cfc.entity.FamilyJoinRequest request = familyJoinRequestService.createJoinRequest(userId, inviteCode, familyRole);
             Family family = familyMapper.selectById(request.getTargetFamilyId());
             Map<String, Object> result = new HashMap<>();
             result.put("requestId", request.getId());

+ 1 - 0
cfc-backend/src/main/java/com/etotem/cfc/dto/FamilyJoinRequestDTO.java

@@ -16,6 +16,7 @@ public class FamilyJoinRequestDTO implements Serializable {
     private String targetFamilyName;
     private String status; // pending / approved / rejected
     private String adminComment;
+    private String familyRole; // 申请人在家庭中的角色
     private String createdAt;
     private String updatedAt;
 }

+ 3 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/FamilyJoinRequest.java

@@ -38,6 +38,9 @@ public class FamilyJoinRequest implements Serializable {
     /** 审批备注 */
     private String comment;
 
+    /** 申请人在家庭中的角色:爸爸/妈妈/爷爷/奶奶等 */
+    private String familyRole;
+
     /** 创建时间 */
     private Date createdAt;
 

+ 10 - 3
cfc-backend/src/main/java/com/etotem/cfc/service/FamilyJoinRequestService.java

@@ -40,7 +40,7 @@ public class FamilyJoinRequestService {
     /**
      * 创建家庭加入请求(待审批)
      */
-    public FamilyJoinRequest createJoinRequest(Long userId, String inviteCode) {
+    public FamilyJoinRequest createJoinRequest(Long userId, String inviteCode, String familyRole) {
         Family family;
 
         // 支持传入 familyId(数字)作为 inviteCode
@@ -106,6 +106,7 @@ public class FamilyJoinRequestService {
         request.setTargetFamilyId(family.getId());
         request.setJoinMethod("by_code");
         request.setInviteRef(inviteCode.trim());
+        request.setFamilyRole(familyRole);
         request.setStatus("pending");
         request.setCreatedAt(new Date());
         request.setUpdatedAt(new Date());
@@ -151,6 +152,7 @@ public class FamilyJoinRequestService {
         } else {
             if (user.getFamilyId() == null || user.getFamilyId() == 0L || !user.getFamilyId().equals(family.getId())) {
                 user.setFamilyId(family.getId());
+                user.setFamilyRole(request.getFamilyRole());
                 user.setUpdatedAt(new Date());
                 userMapper.updateById(user);
             }
@@ -220,19 +222,22 @@ public class FamilyJoinRequestService {
             Family family = familyMapper.selectById(req.getTargetFamilyId());
             dto.setTargetFamilyName(family != null ? family.getName() : "");
             dto.setStatus(req.getStatus());
+            dto.setFamilyRole(req.getFamilyRole());
+            dto.setAdminComment(req.getComment());
             dto.setCreatedAt(req.getCreatedAt() != null ? req.getCreatedAt().toString() : "");
             return dto;
         }).collect(Collectors.toList());
     }
 
     /**
-     * 查询用户自己的待审批请求
+     * 查询用户自己的最近一次加入请求(不限状态,用于轮询审批结果)
      */
     public FamilyJoinRequestDTO getMyPendingRequest(Long userId) {
         FamilyJoinRequest req = familyJoinRequestMapper.selectOne(
                 new LambdaQueryWrapper<FamilyJoinRequest>()
                         .eq(FamilyJoinRequest::getRequesterUserId, userId)
-                        .eq(FamilyJoinRequest::getStatus, "pending")
+                        .orderByDesc(FamilyJoinRequest::getCreatedAt)
+                        .last("LIMIT 1")
         );
         if (req == null) {
             return null;
@@ -244,6 +249,8 @@ public class FamilyJoinRequestService {
         dto.setTargetFamilyName(family != null ? family.getName() : "");
         dto.setStatus(req.getStatus());
         dto.setInviteCode(req.getInviteRef());
+        dto.setFamilyRole(req.getFamilyRole());
+        dto.setAdminComment(req.getComment());
         dto.setCreatedAt(req.getCreatedAt() != null ? req.getCreatedAt().toString() : "");
         return dto;
     }

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-e526d86f197f37bf9b4cb24e73652f3d9d8cb3ab
+2f8287ea12178753d746b1dbf2c11f5aa0936184

+ 2 - 2
cfc-web/package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "cfc-web",
-  "version": "1.0.869",
+  "version": "1.0.870",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "cfc-web",
-      "version": "1.0.869",
+      "version": "1.0.870",
       "dependencies": {
         "@wangeditor/editor": "^5.1.23",
         "@wangeditor/editor-for-vue": "^1.0.2",