|
@@ -23,6 +23,7 @@ import com.etotem.cfc.mapper.HealthReportMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.security.access.AccessDeniedException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
@@ -35,6 +36,7 @@ import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
import com.etotem.cfc.util.SortUtil;
|
|
import com.etotem.cfc.util.SortUtil;
|
|
|
import com.etotem.cfc.util.FamilyNamingSupport;
|
|
import com.etotem.cfc.util.FamilyNamingSupport;
|
|
|
|
|
+import com.etotem.cfc.util.UserUtil;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class FamilyMemberService {
|
|
public class FamilyMemberService {
|
|
@@ -80,6 +82,9 @@ public class FamilyMemberService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private FamilyFoodOverviewService familyFoodOverviewService;
|
|
private FamilyFoodOverviewService familyFoodOverviewService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ReportMemberPermissionService reportMemberPermissionService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 校验成员是否属于指定家庭(用于避免跨家庭读写成员数据)
|
|
* 校验成员是否属于指定家庭(用于避免跨家庭读写成员数据)
|
|
|
*/
|
|
*/
|
|
@@ -1034,6 +1039,8 @@ vo.setIsSelf(viewerMember != null && viewerMember.getId().equals(fm.getId()));
|
|
|
member.setIsSpouse(isSpouse);
|
|
member.setIsSpouse(isSpouse);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 孩子身份标记(仅家庭管理员可设置;落库到 users 表对应记录)
|
|
|
|
|
+ applyIsChildFlag(userId, user.getFamilyId(), member.getUserId(), dto.getIsChild());
|
|
|
member.setUpdatedAt(new Date());
|
|
member.setUpdatedAt(new Date());
|
|
|
familyMemberMapper.updateById(member);
|
|
familyMemberMapper.updateById(member);
|
|
|
logMemberAction(member.getFamilyId(), member.getId(), "update", oldNickname, member.getNickname(), userId);
|
|
logMemberAction(member.getFamilyId(), member.getId(), "update", oldNickname, member.getNickname(), userId);
|
|
@@ -1060,6 +1067,37 @@ vo.setIsSelf(viewerMember != null && viewerMember.getId().equals(fm.getId()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设置成员的孩子身份标记(users.is_child),落库到对应的 User 记录。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>权限:仅家庭管理员可操作(复用 {@link ReportMemberPermissionService#isFamilyAdmin});
|
|
|
|
|
+ * 非管理员抛出 {@link AccessDeniedException},由 controller 层转为 403。</p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param operatorUserId 操作者 userId
|
|
|
|
|
+ * @param familyId 操作者所属家庭(目标成员必须同属该家庭)
|
|
|
|
|
+ * @param targetUserId 目标成员关联的 userId(family_members.user_id;家庭主账号场景即主账号 userId;null=无关联账号无法设置)
|
|
|
|
|
+ * @param isChild 期望值: 1=孩子, 0=非孩子;null=不修改
|
|
|
|
|
+ */
|
|
|
|
|
+ void applyIsChildFlag(Long operatorUserId, Long familyId, Long targetUserId, Integer isChild) {
|
|
|
|
|
+ if (isChild == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!reportMemberPermissionService.isFamilyAdmin(operatorUserId, familyId)) {
|
|
|
|
|
+ throw new AccessDeniedException("仅家庭管理员可设置孩子身份");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (targetUserId == null) {
|
|
|
|
|
+ throw new RuntimeException("该成员未关联登录账号,无法设置孩子身份");
|
|
|
|
|
+ }
|
|
|
|
|
+ User target = userMapper.selectById(targetUserId);
|
|
|
|
|
+ if (target == null || familyId == null || !familyId.equals(target.getFamilyId())) {
|
|
|
|
|
+ throw new RuntimeException("成员不存在或不属于您的家庭");
|
|
|
|
|
+ }
|
|
|
|
|
+ target.setIsChild(isChild == 1);
|
|
|
|
|
+ target.setUpdatedAt(new Date());
|
|
|
|
|
+ userMapper.updateById(target);
|
|
|
|
|
+ log.info("已设置成员孩子身份: userId={}, isChild={}, 操作者={}", targetUserId, isChild, operatorUserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 修改家庭名称(仅家庭管理员:家庭创建者或成员记录 is_admin=1)。
|
|
* 修改家庭名称(仅家庭管理员:家庭创建者或成员记录 is_admin=1)。
|
|
|
* 返回更新后的家庭名称。
|
|
* 返回更新后的家庭名称。
|
|
@@ -1138,6 +1176,8 @@ vo.setIsSelf(viewerMember != null && viewerMember.getId().equals(fm.getId()));
|
|
|
throw new IllegalArgumentException("出生日期格式错误,应为yyyy-MM-dd");
|
|
throw new IllegalArgumentException("出生日期格式错误,应为yyyy-MM-dd");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 孩子身份标记(仅家庭管理员可设置;主账号即 memberId 对应的 User 记录)
|
|
|
|
|
+ applyIsChildFlag(operator.getId(), operator.getFamilyId(), memberId, dto.getIsChild());
|
|
|
parent.setUpdatedAt(new Date());
|
|
parent.setUpdatedAt(new Date());
|
|
|
userMapper.updateById(parent);
|
|
userMapper.updateById(parent);
|
|
|
logMemberAction(parent.getFamilyId(), parent.getId(), "update", oldNickname, parent.getNickname(), operator.getId());
|
|
logMemberAction(parent.getFamilyId(), parent.getId(), "update", oldNickname, parent.getNickname(), operator.getId());
|