|
|
@@ -35,6 +35,14 @@ public class FamilyRelationshipService {
|
|
|
createRelationsForNewMember(familyId, newMemberId, newMemberGeneration, null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 为新成员创建与所有现有成员的双向关系(兼容旧调用:无同辈类型、无锚点)
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void createRelationsForNewMember(Long familyId, Long newMemberId, Integer newMemberGeneration, String peerType) {
|
|
|
+ createRelationsForNewMember(familyId, newMemberId, newMemberGeneration, peerType, null);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 为新成员创建与所有现有成员的双向关系
|
|
|
* 算法:
|
|
|
@@ -43,12 +51,15 @@ public class FamilyRelationshipService {
|
|
|
* newMember → existingMi: generation = newMemberGeneration - Mi.generation
|
|
|
* - 如果 existingMi.generation == null, 默认 0
|
|
|
* - relationType 判定(双向各写一行,取值相同):
|
|
|
- * 同辈且 peerType=spouse → spouse
|
|
|
- * 同辈且 peerType=sibling → sibling
|
|
|
- * 其他 → lineal(默认)
|
|
|
+ * 同辈 且 peerType=spouse 且 existingMember 是锚点成员 → spouse
|
|
|
+ * 同辈 且 peerType 非空 且 非锚点成员 → sibling
|
|
|
+ * 其他(peerType 为空 / 跨辈分) → lineal(默认)
|
|
|
+ * <p>锚点成员(anchorMemberId)= 指定「辈分/同辈类型」时参照的那个人(审批人 / 关联成员)。
|
|
|
+ * 配偶关系只存在于「新成员 ↔ 锚点成员」一对;家庭里其他同辈成员与新成员一律为 sibling,
|
|
|
+ * 否则「妻子/丈夫」称谓会被错误套到所有同辈成员上。</p>
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void createRelationsForNewMember(Long familyId, Long newMemberId, Integer newMemberGeneration, String peerType) {
|
|
|
+ public void createRelationsForNewMember(Long familyId, Long newMemberId, Integer newMemberGeneration, String peerType, Long anchorMemberId) {
|
|
|
// 获取除新成员外的所有现有成员
|
|
|
List<FamilyMember> existing = familyMemberMapper.selectList(
|
|
|
new LambdaQueryWrapper<FamilyMember>()
|
|
|
@@ -67,11 +78,13 @@ public class FamilyRelationshipService {
|
|
|
int exGen = existingMember.getGeneration() != null ? existingMember.getGeneration() : 0;
|
|
|
int newGen = newMemberGeneration != null ? newMemberGeneration : 0;
|
|
|
|
|
|
- // 关系类型:双向取值相同
|
|
|
+ // 关系类型:双向取值相同;配偶仅对锚点成员生效
|
|
|
String relationType = "lineal";
|
|
|
- if (exGen == newGen && "spouse".equals(peerType)) {
|
|
|
+ boolean sameGen = exGen == newGen;
|
|
|
+ boolean isAnchor = anchorMemberId != null && anchorMemberId.equals(existingMember.getId());
|
|
|
+ if (sameGen && "spouse".equals(peerType) && isAnchor) {
|
|
|
relationType = "spouse";
|
|
|
- } else if (exGen == newGen && "sibling".equals(peerType)) {
|
|
|
+ } else if (sameGen && peerType != null && !peerType.trim().isEmpty()) {
|
|
|
relationType = "sibling";
|
|
|
}
|
|
|
|