|
@@ -2,6 +2,7 @@ package com.etotem.cfc.controller;
|
|
|
|
|
|
|
|
import com.etotem.cfc.common.Result;
|
|
import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.service.PurchaseService;
|
|
import com.etotem.cfc.service.PurchaseService;
|
|
|
|
|
+import com.etotem.cfc.service.DanReportUploadService;
|
|
|
import com.etotem.cfc.dto.HealthAnalysisResult;
|
|
import com.etotem.cfc.dto.HealthAnalysisResult;
|
|
|
import com.etotem.cfc.dto.MemberMatchResult;
|
|
import com.etotem.cfc.dto.MemberMatchResult;
|
|
|
import com.etotem.cfc.dto.ParsedDiseaseRisk;
|
|
import com.etotem.cfc.dto.ParsedDiseaseRisk;
|
|
@@ -20,6 +21,7 @@ import com.etotem.cfc.entity.HealthGutFlora;
|
|
|
import com.etotem.cfc.entity.HealthIndicator;
|
|
import com.etotem.cfc.entity.HealthIndicator;
|
|
|
import com.etotem.cfc.entity.HealthReport;
|
|
import com.etotem.cfc.entity.HealthReport;
|
|
|
import com.etotem.cfc.entity.HealthReportDraft;
|
|
import com.etotem.cfc.entity.HealthReportDraft;
|
|
|
|
|
+import com.etotem.cfc.entity.DanReportUpload;
|
|
|
import com.etotem.cfc.entity.ReportTransferRequest;
|
|
import com.etotem.cfc.entity.ReportTransferRequest;
|
|
|
import com.etotem.cfc.entity.NutritionDeficiencyRecord;
|
|
import com.etotem.cfc.entity.NutritionDeficiencyRecord;
|
|
|
import com.etotem.cfc.entity.NutritionIndicatorMapping;
|
|
import com.etotem.cfc.entity.NutritionIndicatorMapping;
|
|
@@ -143,6 +145,9 @@ public class HealthReportController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private ReportMemberPermissionService reportMemberPermissionService;
|
|
private ReportMemberPermissionService reportMemberPermissionService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private DanReportUploadService danReportUploadService;
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private FoodRecommendService foodRecommendService;
|
|
private FoodRecommendService foodRecommendService;
|
|
|
|
|
|
|
@@ -317,6 +322,7 @@ public class HealthReportController {
|
|
|
int size = params.get("size") != null ? Integer.parseInt(params.get("size").toString()) : 0;
|
|
int size = params.get("size") != null ? Integer.parseInt(params.get("size").toString()) : 0;
|
|
|
Long memberId = ParamUtils.getLong(params.get("memberId"));
|
|
Long memberId = ParamUtils.getLong(params.get("memberId"));
|
|
|
List<HealthReport> reports;
|
|
List<HealthReport> reports;
|
|
|
|
|
+ java.util.Set<Long> visibleForDan = null;
|
|
|
if (memberId != null) {
|
|
if (memberId != null) {
|
|
|
// 成员级权限:管理员 / 本人 / 被授权成员可见,否则返回空列表
|
|
// 成员级权限:管理员 / 本人 / 被授权成员可见,否则返回空列表
|
|
|
if (familyId == null || !reportMemberPermissionService.canViewMemberReports(userId, memberId, familyId)) {
|
|
if (familyId == null || !reportMemberPermissionService.canViewMemberReports(userId, memberId, familyId)) {
|
|
@@ -340,15 +346,75 @@ public class HealthReportController {
|
|
|
reports.add(r);
|
|
reports.add(r);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // DAN 报告按可见成员过滤(family_members.id 语义)
|
|
|
|
|
+ visibleForDan = visible;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// 无家庭信息时返回空列表,避免前端报错
|
|
// 无家庭信息时返回空列表,避免前端报错
|
|
|
return Result.success(new ArrayList<>());
|
|
return Result.success(new ArrayList<>());
|
|
|
}
|
|
}
|
|
|
|
|
+ // 合并 DAN 报告(已确认入库的)到列表,保证报告列表页能看到 DAN 报告
|
|
|
|
|
+ List<HealthReport> merged = mergeDanReports(reports, memberId, familyId, visibleForDan, userId);
|
|
|
|
|
+
|
|
|
if (size > 0) {
|
|
if (size > 0) {
|
|
|
- return Result.success(limitLatest(reports, size));
|
|
|
|
|
|
|
+ return Result.success(limitLatest(merged, size));
|
|
|
}
|
|
}
|
|
|
- return Result.success(reports);
|
|
|
|
|
|
|
+ return Result.success(merged);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 合并 DAN 报告到健康报告列表(转成 HealthReport 兼容结构,reportType='dan')
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<HealthReport> mergeDanReports(List<HealthReport> reports, Long memberId, Long familyId,
|
|
|
|
|
+ java.util.Set<Long> visibleForDan, Long userId) {
|
|
|
|
|
+ List<DanReportUpload> danList = danReportUploadService.listConfirmedForReportList(memberId, familyId, visibleForDan);
|
|
|
|
|
+ if (danList.isEmpty()) {
|
|
|
|
|
+ return reports == null ? new ArrayList<>() : reports;
|
|
|
|
|
+ }
|
|
|
|
|
+ java.util.Map<Long, Long> idToMemberId = new java.util.HashMap<>();
|
|
|
|
|
+ for (DanReportUpload u : danList) {
|
|
|
|
|
+ if (u.getFamilyMemberId() != null) {
|
|
|
|
|
+ idToMemberId.put(u.getId(), u.getFamilyMemberId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ List<HealthReport> result = reports == null ? new ArrayList<>() : new ArrayList<>(reports);
|
|
|
|
|
+ // 成员昵称缓存(personName 展示)
|
|
|
|
|
+ java.util.Map<Long, String> memberNameCache = new java.util.HashMap<>();
|
|
|
|
|
+ for (DanReportUpload u : danList) {
|
|
|
|
|
+ HealthReport hr = new HealthReport();
|
|
|
|
|
+ hr.setId(u.getId());
|
|
|
|
|
+ hr.setReportType("dan");
|
|
|
|
|
+ hr.setFamilyId(u.getFamilyId());
|
|
|
|
|
+ hr.setSubjectId(u.getFamilyMemberId());
|
|
|
|
|
+ hr.setUserId(u.getUploaderUserId());
|
|
|
|
|
+ hr.setCreatedAt(u.getUploadedAt() != null ? u.getUploadedAt() : u.getConfirmedAt());
|
|
|
|
|
+ hr.setReportDate(u.getConfirmedAt() != null ? u.getConfirmedAt() : u.getUploadedAt());
|
|
|
|
|
+ if (u.getFamilyMemberId() != null) {
|
|
|
|
|
+ String name = memberNameCache.get(u.getFamilyMemberId());
|
|
|
|
|
+ if (name == null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ com.etotem.cfc.entity.FamilyMember fm = familyMemberMapper.selectById(u.getFamilyMemberId());
|
|
|
|
|
+ name = fm != null ? (fm.getNickname() != null ? fm.getNickname() : ("成员" + fm.getId())) : null;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ name = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (name == null) name = "";
|
|
|
|
|
+ memberNameCache.put(u.getFamilyMemberId(), name);
|
|
|
|
|
+ }
|
|
|
|
|
+ hr.setPersonName(name);
|
|
|
|
|
+ }
|
|
|
|
|
+ hr.setStatus("active");
|
|
|
|
|
+ result.add(hr);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 按上传时间倒序(DAN 与健康报告统一排序)
|
|
|
|
|
+ result.sort((a, b) -> {
|
|
|
|
|
+ java.util.Date da = a.getCreatedAt();
|
|
|
|
|
+ java.util.Date db = b.getCreatedAt();
|
|
|
|
|
+ if (da == null) return 1;
|
|
|
|
|
+ if (db == null) return -1;
|
|
|
|
|
+ return db.compareTo(da);
|
|
|
|
|
+ });
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|