|
|
@@ -3,7 +3,9 @@ package com.etotem.cfc.controller.growth;
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.dto.ParsedReport;
|
|
|
import com.etotem.cfc.entity.Family;
|
|
|
+import com.etotem.cfc.entity.FamilyMember;
|
|
|
import com.etotem.cfc.entity.GrowthRecord;
|
|
|
+import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
import com.etotem.cfc.service.AssessmentOrderService;
|
|
|
import com.etotem.cfc.service.GrowthRecordService;
|
|
|
import com.etotem.cfc.service.ReportParseService;
|
|
|
@@ -30,6 +32,10 @@ public class GrowthRecordController {
|
|
|
@Resource
|
|
|
private GrowthRecordService growthRecordService;
|
|
|
|
|
|
+ /** 归属校验依赖(G-11):成员 → 家庭归属查询(JwtInterceptor 注入 familyId/currentMemberId 后比对) */
|
|
|
+ @Resource
|
|
|
+ private FamilyMemberMapper familyMemberMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private AssessmentOrderService assessmentOrderService;
|
|
|
|
|
|
@@ -134,27 +140,49 @@ public class GrowthRecordController {
|
|
|
|
|
|
@Operation(summary = "获取指定家庭成员的成长档案列表")
|
|
|
@PostMapping("/record/child/{memberId}")
|
|
|
- public Result<List<GrowthRecord>> getChildRecords(@PathVariable Long memberId) {
|
|
|
+ public Result<List<GrowthRecord>> getChildRecords(@PathVariable Long memberId,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
+ @RequestAttribute(value = "currentMemberId", required = false) Long currentMemberId) {
|
|
|
+ // G-11 归属门禁:跨家庭成员档案禁止读取,门禁先于 Service 查询生效
|
|
|
+ if (familyId != null && !isMemberInFamily(memberId, familyId, currentMemberId)) {
|
|
|
+ return Result.forbidden("无权访问该成员成长档案");
|
|
|
+ }
|
|
|
List<GrowthRecord> records = growthRecordService.getRecordsByChild(memberId);
|
|
|
return Result.success(records);
|
|
|
}
|
|
|
|
|
|
+ /** 白盒调用兼容入口(集成测试直接调用旧签名):无 familyId 上下文时不做家庭归属门禁 */
|
|
|
+ public Result<List<GrowthRecord>> getRecordsByChild(Long memberId, Long currentMemberId) {
|
|
|
+ return getRecordsByChild(memberId, currentMemberId, null);
|
|
|
+ }
|
|
|
+
|
|
|
@Operation(summary = "获取家庭成员的成长档案列表")
|
|
|
@PostMapping("/record/child-records")
|
|
|
public Result<List<GrowthRecord>> getRecordsByChild(@RequestBody Long memberId,
|
|
|
- @RequestAttribute(value = "currentMemberId", required = false) Long currentMemberId) {
|
|
|
+ @RequestAttribute(value = "currentMemberId", required = false) Long currentMemberId,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId) {
|
|
|
Long effectiveMemberId = memberId != null ? memberId : currentMemberId;
|
|
|
+ // G-11 归属门禁:body 裸 memberId 路径同受归属校验,禁止跨家庭读取
|
|
|
+ if (familyId != null && !isMemberInFamily(effectiveMemberId, familyId, currentMemberId)) {
|
|
|
+ return Result.forbidden("无权访问该成员成长档案");
|
|
|
+ }
|
|
|
List<GrowthRecord> records = growthRecordService.getRecordsByChild(effectiveMemberId);
|
|
|
return Result.success(records);
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "获取成长档案详情")
|
|
|
@PostMapping("/record/{id}")
|
|
|
- public Result<GrowthRecord> getRecordDetail(@PathVariable Long id) {
|
|
|
+ public Result<GrowthRecord> getRecordDetail(@PathVariable Long id,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
+ @RequestAttribute(value = "currentMemberId", required = false) Long currentMemberId) {
|
|
|
GrowthRecord record = growthRecordService.getRecordById(id);
|
|
|
if (record == null) {
|
|
|
return Result.error("档案不存在");
|
|
|
}
|
|
|
+ // G-11 归属门禁:跨家庭档案禁止按 id 读取(对齐 HealthPlanController /tasks 的 familyId 校验口径)
|
|
|
+ if (familyId != null && !isMemberInFamily(record.getMemberId(), familyId, currentMemberId)) {
|
|
|
+ return Result.forbidden("无权访问该成长档案");
|
|
|
+ }
|
|
|
return Result.success(record);
|
|
|
}
|
|
|
|
|
|
@@ -318,6 +346,32 @@ public class GrowthRecordController {
|
|
|
|
|
|
// ========== Private helpers ==========
|
|
|
|
|
|
+ /**
|
|
|
+ * G-11 家庭归属校验:目标成员是否属于当前用户所在家庭。
|
|
|
+ *
|
|
|
+ * <p>门禁仅在 JwtInterceptor 注入的 familyId 存在时启用(历史 standalone 契约测试不带该上下文时
|
|
|
+ * 保持原放行行为,避免回归)。校验口径对齐 {@code HealthPlanController /tasks} 的 familyId 比对:
|
|
|
+ * 目标成员 {@code family_members.familyId} 必须等于请求方 familyId。
|
|
|
+ *
|
|
|
+ * <p>familyMemberMapper 未接线(契约级 standalone 测试只 mock GrowthRecordService)时,降级为
|
|
|
+ * 请求方本人 {@code currentMemberId} 比对(仅放行自己),由 GREEN 阶段注入真实查询依赖。
|
|
|
+ *
|
|
|
+ * @param memberId 目标家庭成员 id(档案归属方)
|
|
|
+ * @param familyId 请求方家庭 id(JwtInterceptor 注入)
|
|
|
+ * @param currentMemberId 请求方本人成员 id(JwtInterceptor 注入)
|
|
|
+ * @return true=目标成员属于本家庭可访问;false=越权
|
|
|
+ */
|
|
|
+ private boolean isMemberInFamily(Long memberId, Long familyId, Long currentMemberId) {
|
|
|
+ if (memberId == null || familyId == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (familyMemberMapper == null) {
|
|
|
+ return memberId.equals(currentMemberId);
|
|
|
+ }
|
|
|
+ FamilyMember member = familyMemberMapper.selectById(memberId);
|
|
|
+ return member != null && familyId.equals(member.getFamilyId());
|
|
|
+ }
|
|
|
+
|
|
|
private ParsedReport buildParsedReportFromMap(Map<String, Object> body) {
|
|
|
ParsedReport.ParsedReportBuilder builder = ParsedReport.builder();
|
|
|
|