|
@@ -1282,10 +1282,12 @@ public class HealthReportService {
|
|
|
public void bindReportToMember(Long reportId, Long subjectId) {
|
|
public void bindReportToMember(Long reportId, Long subjectId) {
|
|
|
// 使用 JdbcTemplate 直接 UPDATE,避免 MyBatis-Plus NOT_NULL 策略导致 NULL 值不更新
|
|
// 使用 JdbcTemplate 直接 UPDATE,避免 MyBatis-Plus NOT_NULL 策略导致 NULL 值不更新
|
|
|
String sql = "UPDATE health_reports SET subject_id = ? WHERE id = ?";
|
|
String sql = "UPDATE health_reports SET subject_id = ? WHERE id = ?";
|
|
|
|
|
+ Long previousSubjectId = null;
|
|
|
// A方案:写库前归一化为 family_members.id 口径
|
|
// A方案:写库前归一化为 family_members.id 口径
|
|
|
if (subjectId != null && subjectId > 0) {
|
|
if (subjectId != null && subjectId > 0) {
|
|
|
HealthReport rep = healthReportMapper.selectById(reportId);
|
|
HealthReport rep = healthReportMapper.selectById(reportId);
|
|
|
if (rep != null) {
|
|
if (rep != null) {
|
|
|
|
|
+ previousSubjectId = rep.getSubjectId();
|
|
|
Long resolved = resolveSubjectToMemberId(subjectId, rep.getFamilyId());
|
|
Long resolved = resolveSubjectToMemberId(subjectId, rep.getFamilyId());
|
|
|
if (resolved != null && !resolved.equals(subjectId)) {
|
|
if (resolved != null && !resolved.equals(subjectId)) {
|
|
|
log.info("subjectId归一化 reportId={}, {} -> {}", reportId, subjectId, resolved);
|
|
log.info("subjectId归一化 reportId={}, {} -> {}", reportId, subjectId, resolved);
|
|
@@ -1296,8 +1298,25 @@ public class HealthReportService {
|
|
|
int updatedRows = jdbcTemplate.update(sql, subjectId, reportId);
|
|
int updatedRows = jdbcTemplate.update(sql, subjectId, reportId);
|
|
|
if (updatedRows == 0) {
|
|
if (updatedRows == 0) {
|
|
|
log.warn("reportId={}, subjectId={} 更新失败 - 报告不存在", reportId, subjectId);
|
|
log.warn("reportId={}, subjectId={} 更新失败 - 报告不存在", reportId, subjectId);
|
|
|
- } else {
|
|
|
|
|
- log.info("已绑定报告 {} 到被检测人 {}", reportId, subjectId);
|
|
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("已绑定报告 {} 到被检测人 {}", reportId, subjectId);
|
|
|
|
|
+
|
|
|
|
|
+ // G3(DS-2026-10-25-01):上传时未选成员 → NormalizeIndicatorPipeline 因 subjectId==null 静默跳过,
|
|
|
|
|
+ // 仅 UPDATE subject_id 不会补写时序,用户会看到「绑了成员却没有历史」。
|
|
|
|
|
+ // 只在「此前无归属」时补跑(即 G3 缺口),失败不阻断绑定;processReport 底层 upsert 幂等。
|
|
|
|
|
+ if (previousSubjectId == null && subjectId != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ HealthReport rep = healthReportMapper.selectById(reportId);
|
|
|
|
|
+ if (rep != null && rep.getSubjectId() != null && rep.getPayloadJson() != null) {
|
|
|
|
|
+ ParsedReportPayload.Payload payload =
|
|
|
|
|
+ objectMapper.readValue(rep.getPayloadJson(), ParsedReportPayload.Payload.class);
|
|
|
|
|
+ normalizeIndicatorPipeline.processReport(rep, payload);
|
|
|
|
|
+ log.info("绑定成员后补写时序 reportId={}, subjectId={}", reportId, subjectId);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("绑定成员后补写时序失败 reportId={}: {}", reportId, e.getMessage());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|