diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/doctorstation/appservice/impl/DoctorStationChineseMedicalAppServiceImpl.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/doctorstation/appservice/impl/DoctorStationChineseMedicalAppServiceImpl.java index 2f93fc86d..3ea899b35 100755 --- a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/doctorstation/appservice/impl/DoctorStationChineseMedicalAppServiceImpl.java +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/doctorstation/appservice/impl/DoctorStationChineseMedicalAppServiceImpl.java @@ -459,22 +459,38 @@ public class DoctorStationChineseMedicalAppServiceImpl implements IDoctorStation } if (is_sign) { - // 按groupId分组 - Map> groupMap - = insertOrUpdateList.stream().collect(Collectors.groupingBy(AdviceSaveDto::getGroupId)); - // 为每个分组生成唯一的处方号 - groupMap.forEach((groupId, groupList) -> { - // 先查询当前groupId是否已经被签发生成过处方号 - List list = iMedicationRequestService - .list(new LambdaQueryWrapper().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 list = iMedicationRequestService + .list(new LambdaQueryWrapper() + .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)); + } } // 医嘱签发编码