fix(#668): 中医处方签发 groupingBy null key 崩溃修复 — 过滤 null groupId 后再分组,无 groupId 的处方各自生成处方号

This commit is contained in:
2026-06-10 16:58:07 +08:00
parent 20af7351a0
commit fd83ac9621

View File

@@ -459,22 +459,38 @@ public class DoctorStationChineseMedicalAppServiceImpl implements IDoctorStation
}
if (is_sign) {
// groupId分组
Map<Long, List<AdviceSaveDto>> groupMap
= insertOrUpdateList.stream().collect(Collectors.groupingBy(AdviceSaveDto::getGroupId));
// 为每个分组生成唯一的处方号
groupMap.forEach((groupId, groupList) -> {
// 先查询当前groupId是否已经被签发生成过处方号
List<MedicationRequest> list = iMedicationRequestService
.list(new LambdaQueryWrapper<MedicationRequest>().eq(MedicationRequest::getGroupId, groupId));
if (!list.isEmpty() && StringUtils.isNotEmpty(list.get(0).getPrescriptionNo())) {
groupList.forEach(dto -> dto.setPrescriptionNo(list.get(0).getPrescriptionNo()));
} else {
String prescriptionNo
= assignSeqUtil.getSeq(AssignSeqEnum.PRESCRIPTION_CHINESE_HERBAL_MEDICINE.getPrefix(), 8);
groupList.forEach(dto -> dto.setPrescriptionNo(prescriptionNo));
// groupId 的按组生成处方号groupingBy 不接受 null key先过滤
insertOrUpdateList.stream()
.filter(e -> e.getGroupId() != null)
.collect(Collectors.groupingBy(AdviceSaveDto::getGroupId))
.forEach((groupId, groupList) -> {
List<MedicationRequest> list = iMedicationRequestService
.list(new LambdaQueryWrapper<MedicationRequest>()
.eq(MedicationRequest::getGroupId, groupId));
if (!list.isEmpty() && StringUtils.isNotEmpty(list.get(0).getPrescriptionNo())) {
groupList.forEach(dto -> dto.setPrescriptionNo(list.get(0).getPrescriptionNo()));
} else {
String prescriptionNo = assignSeqUtil.getSeq(
AssignSeqEnum.PRESCRIPTION_CHINESE_HERBAL_MEDICINE.getPrefix(), 8);
groupList.forEach(dto -> dto.setPrescriptionNo(prescriptionNo));
}
});
// 无 groupId 的各自生成处方号
for (AdviceSaveDto dto : insertOrUpdateList) {
if (dto.getGroupId() != null) {
continue;
}
});
if (dto.getRequestId() != null) {
MedicationRequest existing = iMedicationRequestService.getById(dto.getRequestId());
if (existing != null && StringUtils.isNotEmpty(existing.getPrescriptionNo())) {
dto.setPrescriptionNo(existing.getPrescriptionNo());
continue;
}
}
dto.setPrescriptionNo(assignSeqUtil.getSeq(
AssignSeqEnum.PRESCRIPTION_CHINESE_HERBAL_MEDICINE.getPrefix(), 8));
}
}
// 医嘱签发编码