根因: - 文件**:`openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java:2340` → `updateGroupId()` 方法 - 全链路 6 环分析**: - | 环节 | 状态 | 说明 | - |------|------|------| - | ①前端 | ✅ 正常 | `combination()` 发送 `{requestId, groupId}` 到后端 | - | ②Controller | ✅ 正常 | `PUT /doctor-station/advice/update-groupid` 接收参数 | - | ③Service | 🔧 已修改 | **问题所在** — 原代码把所有 requestId 都当 MedicationRequest 处理 | - | ④Mapper/DB | ❌ 遗漏 | 当诊疗医嘱(ID属于 `wor_service_request`)的 requestId 被当作 MedicationRequest 保存时,`saveOrUpdateBatch` 尝试 INSERT 新记录,`medication_id` NOT NULL 约束失败 | 修复: - 修改 `updateGroupId` 方法,按医嘱实际所属表分别更新: - 1. **拆组(groupId=null)**:对三个表(MedicationRequest、ServiceRequest、DeviceRequest)都执行 `group_id` 置空 - 2. **组合(groupId!=null)**:先查 `MedicationRequest` → 再查 `ServiceRequest` → 最后查 `DeviceRequest`,找到所属表后用 `UpdateWrapper` 精准更新 `group_id`(DeviceRequest 用 `group_no`,String 类型) - ### 验证结果 - ✅ `mvn compile -pl openhis-application -am` 编译通过 - ✅ 修改范围仅限一个方法,不影响其他模块 - ✅ 拆组和组合两个方向都走全链路验证
This commit is contained in:
@@ -2343,21 +2343,52 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
.map(UpdateGroupDto::getRequestId).collect(Collectors.toList());
|
||||
|
||||
if (!idsToSetNull.isEmpty()) {
|
||||
// 创建更新条件
|
||||
UpdateWrapper<MedicationRequest> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.set("group_id", null).in("id", idsToSetNull);
|
||||
// 对三个表都执行 group_id/group_no 置空(哪个表有该 id 就更新哪个)
|
||||
UpdateWrapper<MedicationRequest> medUpdateWrapper = new UpdateWrapper<>();
|
||||
medUpdateWrapper.set("group_id", null).in("id", idsToSetNull);
|
||||
iMedicationRequestService.update(medUpdateWrapper);
|
||||
|
||||
// 执行更新
|
||||
iMedicationRequestService.update(updateWrapper);
|
||||
UpdateWrapper<ServiceRequest> srvUpdateWrapper = new UpdateWrapper<>();
|
||||
srvUpdateWrapper.set("group_id", null).in("id", idsToSetNull);
|
||||
iServiceRequestService.update(srvUpdateWrapper);
|
||||
|
||||
// DeviceRequest 使用 group_no(String 类型)
|
||||
UpdateWrapper<DeviceRequest> devUpdateWrapper = new UpdateWrapper<>();
|
||||
devUpdateWrapper.set("group_no", null).in("id", idsToSetNull);
|
||||
iDeviceRequestService.update(devUpdateWrapper);
|
||||
}
|
||||
|
||||
// 处理非null的情况
|
||||
List<MedicationRequest> medicationRequestList = groupList.stream().filter(dto -> dto.getGroupId() != null)
|
||||
.map(dto -> new MedicationRequest().setId(dto.getRequestId()).setGroupId(dto.getGroupId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!medicationRequestList.isEmpty()) {
|
||||
iMedicationRequestService.saveOrUpdateBatch(medicationRequestList);
|
||||
// 处理 groupId 非 null 的情况:按实际所属表分别更新
|
||||
List<UpdateGroupDto> nonNullGroupList = groupList.stream()
|
||||
.filter(dto -> dto.getGroupId() != null).collect(Collectors.toList());
|
||||
if (!nonNullGroupList.isEmpty()) {
|
||||
for (UpdateGroupDto dto : nonNullGroupList) {
|
||||
Long reqId = dto.getRequestId();
|
||||
Long grpId = dto.getGroupId();
|
||||
// 先尝试药品表(med_medication_request → group_id)
|
||||
MedicationRequest medReq = iMedicationRequestService.getById(reqId);
|
||||
if (medReq != null) {
|
||||
UpdateWrapper<MedicationRequest> uw = new UpdateWrapper<>();
|
||||
uw.set("group_id", grpId).eq("id", reqId);
|
||||
iMedicationRequestService.update(uw);
|
||||
continue;
|
||||
}
|
||||
// 再尝试诊疗表(wor_service_request → group_id)
|
||||
ServiceRequest srvReq = iServiceRequestService.getById(reqId);
|
||||
if (srvReq != null) {
|
||||
UpdateWrapper<ServiceRequest> uw = new UpdateWrapper<>();
|
||||
uw.set("group_id", grpId).eq("id", reqId);
|
||||
iServiceRequestService.update(uw);
|
||||
continue;
|
||||
}
|
||||
// 最后尝试耗材表(wor_device_request → group_no, String 类型)
|
||||
DeviceRequest devReq = iDeviceRequestService.getById(reqId);
|
||||
if (devReq != null) {
|
||||
UpdateWrapper<DeviceRequest> uw = new UpdateWrapper<>();
|
||||
uw.set("group_no", grpId != null ? grpId.toString() : null).eq("id", reqId);
|
||||
iDeviceRequestService.update(uw);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user