diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/appservice/impl/RequestFormManageAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/appservice/impl/RequestFormManageAppServiceImpl.java index 4dd649fad..ad87b75c4 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/appservice/impl/RequestFormManageAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/appservice/impl/RequestFormManageAppServiceImpl.java @@ -76,6 +76,10 @@ public class RequestFormManageAppServiceImpl implements IRequestFormManageAppSer @Override @Transactional(rollbackFor = Exception.class) public R saveRequestForm(RequestFormSaveDto requestFormSaveDto, String typeCode) { + // 申请单ID(前端空字符串可能反序列化为0L,需同时判0) + Long requestFormId = requestFormSaveDto.getRequestFormId(); + boolean isEdit = requestFormId != null && requestFormId != 0L; + // 诊疗执行科室配置校验(必须在任何数据库操作之前) List activityOrganizationConfig = requestFormManageAppMapper.getActivityOrganizationConfig(typeCode); @@ -83,12 +87,23 @@ public class RequestFormManageAppServiceImpl implements IRequestFormManageAppSer throw new ServiceException("请先配置当前时间段的执行科室"); } + // 逐个校验activityList中的项目是否都配置了执行科室,避免部分通过后在循环中抛异常导致事务复杂化 + List activityList = requestFormSaveDto.getActivityList(); + if (activityList != null && !activityList.isEmpty()) { + for (ActivitySaveDto activitySaveDto : activityList) { + Long positionId = activityOrganizationConfig.stream() + .filter(dto -> activitySaveDto.getAdviceDefinitionId().equals(dto.getActivityDefinitionId())) + .map(ActivityOrganizationConfigDto::getOrganizationId).findFirst().orElse(null); + if (positionId == null) { + throw new ServiceException(activitySaveDto.getAdviceDefinitionName() + "未配置当前时间段的执行科室"); + } + } + } + // 诊疗处方号 String prescriptionNo; - // 申请单ID - Long requestFormId = requestFormSaveDto.getRequestFormId(); // 编辑场景 - if (requestFormId != null) { + if (isEdit) { RequestForm requestFormInfo = iRequestFormService.getById(requestFormId); prescriptionNo = requestFormInfo.getPrescriptionNo(); // 该申请单存在的待发送医嘱个数 @@ -132,7 +147,7 @@ public class RequestFormManageAppServiceImpl implements IRequestFormManageAppSer iRequestFormService.saveOrUpdate(requestForm); // 编辑场景时,先删除掉原有诊疗项目及账单再新增 - if (requestFormId != null) { + if (isEdit) { List serviceRequestIds = iServiceRequestService .list(new LambdaQueryWrapper().eq(ServiceRequest::getPrescriptionNo, prescriptionNo)) .stream().map(ServiceRequest::getId).collect(Collectors.toList()); @@ -146,8 +161,6 @@ public class RequestFormManageAppServiceImpl implements IRequestFormManageAppSer ServiceRequest serviceRequest; ChargeItem chargeItem; - // 诊疗集合 - List activityList = requestFormSaveDto.getActivityList(); log.info("保存申请单,typeCode={}, activityListSize={}, encounterId={}", typeCode, activityList != null ? activityList.size() : 0, encounterId); for (ActivitySaveDto activitySaveDto : activityList) {