|
@@ -6,6 +6,7 @@ import com.etotem.cfc.dto.FamilyMemberVO;
|
|
|
import com.etotem.cfc.dto.SwitchMemberVO;
|
|
import com.etotem.cfc.dto.SwitchMemberVO;
|
|
|
import com.etotem.cfc.entity.Family;
|
|
import com.etotem.cfc.entity.Family;
|
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
|
|
|
+import com.etotem.cfc.entity.FamilyRelationship;
|
|
|
import com.etotem.cfc.entity.FamilyMemberAttributes;
|
|
import com.etotem.cfc.entity.FamilyMemberAttributes;
|
|
|
import com.etotem.cfc.entity.RelationshipType;
|
|
import com.etotem.cfc.entity.RelationshipType;
|
|
|
import com.etotem.cfc.entity.User;
|
|
import com.etotem.cfc.entity.User;
|
|
@@ -53,6 +54,9 @@ public class FamilyMemberService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private SystemConfigService systemConfigService;
|
|
private SystemConfigService systemConfigService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FamilyRelationshipService familyRelationshipService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 添加家庭成员
|
|
* 添加家庭成员
|
|
|
*/
|
|
*/
|
|
@@ -154,6 +158,9 @@ public class FamilyMemberService {
|
|
|
// children 表已废除,无需同步。角色信息通过 computeEffectiveRole() 自动计算。
|
|
// children 表已废除,无需同步。角色信息通过 computeEffectiveRole() 自动计算。
|
|
|
// 若需要 child 专属初始化(如游戏数据),后续在 computeEffectiveRole() 返回 child 时处理。
|
|
// 若需要 child 专属初始化(如游戏数据),后续在 computeEffectiveRole() 返回 child 时处理。
|
|
|
|
|
|
|
|
|
|
+ // 为新成员创建与所有现有成员的双向关系
|
|
|
|
|
+ familyRelationshipService.createRelationsForNewMember(familyId, member.getId(), genLevel.getOffset());
|
|
|
|
|
+
|
|
|
return toFamilyMemberVO(member, relType);
|
|
return toFamilyMemberVO(member, relType);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -206,9 +213,26 @@ public class FamilyMemberService {
|
|
|
if (fm.getBirthday() != null) {
|
|
if (fm.getBirthday() != null) {
|
|
|
vo.setAge(calculateAge(fm.getBirthday()));
|
|
vo.setAge(calculateAge(fm.getBirthday()));
|
|
|
}
|
|
}
|
|
|
- // 计算视角相关的关系标签
|
|
|
|
|
|
|
+ // 计算视角相关的关系标签(优先使用关系表)
|
|
|
if (viewerMember != null) {
|
|
if (viewerMember != null) {
|
|
|
- vo.setRelativeLabel(computeRelativeLabel(viewerMember, fm, familyMembers));
|
|
|
|
|
|
|
+ Integer genValue = null;
|
|
|
|
|
+ if (familyRelationshipService != null && viewerMember.getId() != null) {
|
|
|
|
|
+ List<FamilyRelationship> rels = familyRelationshipService.getRelationsForMember(viewerMember.getId());
|
|
|
|
|
+ if (rels != null) {
|
|
|
|
|
+ for (FamilyRelationship rel : rels) {
|
|
|
|
|
+ if (rel.getToMemberId().equals(fm.getId())) {
|
|
|
|
|
+ genValue = rel.getGenerationValue();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (genValue != null) {
|
|
|
|
|
+ vo.setGenerationValue(genValue);
|
|
|
|
|
+ vo.setRelativeLabel(familyRelationshipService.computeRelationshipLabel(genValue, fm.getGender()));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ vo.setRelativeLabel(computeRelativeLabel(viewerMember, fm, familyMembers));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
result.add(vo);
|
|
result.add(vo);
|
|
|
}
|
|
}
|
|
@@ -260,6 +284,8 @@ public class FamilyMemberService {
|
|
|
// 从 family_members 踢出
|
|
// 从 family_members 踢出
|
|
|
FamilyMember member = familyMemberMapper.selectById(memberId);
|
|
FamilyMember member = familyMemberMapper.selectById(memberId);
|
|
|
if (member != null && member.getFamilyId().equals(operator.getFamilyId())) {
|
|
if (member != null && member.getFamilyId().equals(operator.getFamilyId())) {
|
|
|
|
|
+ // 先清理关系记录
|
|
|
|
|
+ familyRelationshipService.deleteRelationsForMember(memberId);
|
|
|
familyMemberMapper.deleteById(memberId);
|
|
familyMemberMapper.deleteById(memberId);
|
|
|
// 如果关联了 User,清除其 familyId
|
|
// 如果关联了 User,清除其 familyId
|
|
|
if (member.getUserId() != null) {
|
|
if (member.getUserId() != null) {
|
|
@@ -281,6 +307,22 @@ public class FamilyMemberService {
|
|
|
throw new RuntimeException("成员不存在");
|
|
throw new RuntimeException("成员不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判断成员是否可编辑
|
|
|
|
|
+ * 规则:有关联 userId 或有 phone 且 phone 能匹配到 User 的成员不可编辑
|
|
|
|
|
+ */
|
|
|
|
|
+ public boolean isEditable(Long memberId) {
|
|
|
|
|
+ FamilyMember member = familyMemberMapper.selectById(memberId);
|
|
|
|
|
+ if (member == null) return false;
|
|
|
|
|
+ if (member.getUserId() != null) return false;
|
|
|
|
|
+ if (member.getPhone() != null && !member.getPhone().isEmpty()) {
|
|
|
|
|
+ User linked = userMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<User>().eq(User::getPhone, member.getPhone()));
|
|
|
|
|
+ if (linked != null) return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 更新成员信息
|
|
* 更新成员信息
|
|
|
*/
|
|
*/
|
|
@@ -296,6 +338,11 @@ public class FamilyMemberService {
|
|
|
throw new RuntimeException("成员不存在或不属于您的家庭");
|
|
throw new RuntimeException("成员不存在或不属于您的家庭");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 检查编辑权限
|
|
|
|
|
+ if (!isEditable(memberId)) {
|
|
|
|
|
+ throw new RuntimeException("该成员关联了登录账号,不可编辑");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (dto.getNickname() != null && !dto.getNickname().trim().isEmpty()) {
|
|
if (dto.getNickname() != null && !dto.getNickname().trim().isEmpty()) {
|
|
|
member.setNickname(dto.getNickname().trim());
|
|
member.setNickname(dto.getNickname().trim());
|
|
|
}
|
|
}
|