From 56b8d0e98d3a2de729c926e16ca79e945022b0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B3=E7=BE=BD?= <关羽@gentronhealth.com> Date: Thu, 14 May 2026 02:11:27 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#475:=20=E3=80=90=E4=BD=8F=E9=99=A2?= =?UTF-8?q?=E5=8C=BB=E7=94=9F=E5=B7=A5=E4=BD=9C=E7=AB=99=E3=80=91=E5=BC=80?= =?UTF-8?q?=E7=AB=8B=E6=A3=80=E6=9F=A5=E7=94=B3=E8=AF=B7=E5=8D=95=E6=8A=A5?= =?UTF-8?q?=E9=94=99"=E8=AF=B7=E5=85=88=E9=85=8D=E7=BD=AE=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E6=97=B6=E9=97=B4=E6=AE=B5=E7=9A=84=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E7=A7=91=E5=AE=A4"=E5=90=8E=EF=BC=8C=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BB=8D=E7=94=9F=E6=88=90=E7=94=B3=E8=AF=B7=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将requestFormId判空改为requestFormId != null && requestFormId != 0L,防止前端空字符串反序列化为0L误入编辑场景 - 在循环中逐个校验activityList中的项目是否都配置了执行科室,将所有校验前置到任何数据库操作之前,避免部分通过后在save中途抛异常 - 统一使用isEdit标志变量替代重复的null检查 Co-Authored-By: Claude Opus 4.7 --- .../impl/RequestFormManageAppServiceImpl.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) 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) {