From b27a84793806f6c9ce6d2f11833e276217fc04d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B3=E7=BE=BD?= <关羽@gentronhealth.com> Date: Sun, 10 May 2026 12:27:51 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#504:=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-=E4=B8=B4?= =?UTF-8?q?=E5=BA=8A=E5=8C=BB=E5=98=B1=E3=80=91=E6=8A=A4=E5=A3=AB=E9=80=80?= =?UTF-8?q?=E5=9B=9E=E8=8D=AF=E5=93=81=E5=8C=BB=E5=98=B1=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E5=8C=BB=E7=94=9F=E4=BF=AE=E6=94=B9=E5=B9=B6=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E6=8F=90=E7=A4=BA"=E6=9C=AA=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=88=B0=E5=BA=93=E5=AD=98=E4=BF=A1=E6=81=AF"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因分析: 1. SQL查询 getRegRequestBaseInfo 未返回 medication_id/adviceDefinitionId 字段, 退回医嘱的 adviceDefinitionId 为 null,导致库存校验查询无法匹配到库存记录 2. 退回医嘱可能缺少 locationId,严格的 locationId 匹配导致校验失败 修复方案: 1. AdviceManageAppMapper.xml:在三个UNION查询中分别添加 medication_id/device_def_id/activity_id AS advice_definition_id 2. AdviceUtils.checkInventory(): - 过滤 null adviceDefinitionId,避免SQL查询异常 - 所有adviceDefinitionId为null时跳过库存校验 - 退回医嘱单个adviceDefinitionId为null时跳过该校验项 - 添加 locationId 容错匹配(为null时跳过location匹配) Co-Authored-By: Claude Opus 4.7 --- .../web/doctorstation/utils/AdviceUtils.java | 19 +++++++++++++++---- .../AdviceManageAppMapper.xml | 9 ++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java index 5e4e9c28..6dccd820 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java @@ -83,9 +83,14 @@ public class AdviceUtils { * @return 提示信息 */ public String checkInventory(List adviceSaveList) { - // 医嘱定义ID集合 + // 医嘱定义ID集合(过滤null值,避免SQL查询异常) List adviceDefinitionIdList - = adviceSaveList.stream().map(AdviceSaveDto::getAdviceDefinitionId).collect(Collectors.toList()); + = adviceSaveList.stream().map(AdviceSaveDto::getAdviceDefinitionId) + .filter(id -> id != null).collect(Collectors.toList()); + // 🔧 Bug #504 修复:如果所有adviceDefinitionId都为null,跳过库存校验 + if (adviceDefinitionIdList.isEmpty()) { + return null; + } // 医嘱库存集合 List adviceInventoryList = doctorStationAdviceAppMapper.getAdviceInventory(null, adviceDefinitionIdList, @@ -99,6 +104,10 @@ public class AdviceUtils { = this.subtractInventory(adviceInventoryList, adviceDraftInventoryList); // 检查库存 for (AdviceSaveDto saveDto : adviceSaveList) { + // 🔧 Bug #504 修复:退回医嘱可能adviceDefinitionId为空,跳过校验 + if (saveDto.getAdviceDefinitionId() == null) { + continue; + } boolean matched = false; for (AdviceInventoryDto inventoryDto : adviceInventory) { // 匹配条件:adviceDefinitionId, adviceTableName, locationId, lotNumber 同时相等 @@ -108,10 +117,12 @@ public class AdviceUtils { || saveDto.getLotNumber().equals(inventoryDto.getLotNumber()); boolean tableNameMatch = StringUtils.isEmpty(saveDto.getAdviceTableName()) || inventoryDto.getItemTable().equals(saveDto.getAdviceTableName()); -// if (saveDto.) + // 🔧 Bug #504 修复:退回医嘱可能locationId为空,跳过location匹配 + boolean locationMatch = saveDto.getLocationId() == null + || inventoryDto.getLocationId().equals(saveDto.getLocationId()); if (inventoryDto.getItemId().equals(saveDto.getAdviceDefinitionId()) && tableNameMatch - && inventoryDto.getLocationId().equals(saveDto.getLocationId()) && lotNumberMatch) { + && locationMatch && lotNumberMatch) { matched = true; // 检查库存是否充足 BigDecimal minUnitQuantity = saveDto.getMinUnitQuantity(); diff --git a/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml b/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml index c5d06303..4be9c705 100755 --- a/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml +++ b/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml @@ -216,7 +216,8 @@ ccd.name AS condition_definition_name, T1.therapy_enum AS therapyEnum, T1.sort_number AS sort_number, - T1.based_on_id AS based_on_id + T1.based_on_id AS based_on_id, + T1.medication_id AS advice_definition_id FROM med_medication_request AS T1 LEFT JOIN med_medication_definition AS T2 ON T2.ID = T1.medication_id AND T2.delete_flag = '0' @@ -268,7 +269,8 @@ '' AS condition_definition_name, 2 AS therapyEnum, 99 AS sort_number, - T1.based_on_id AS based_on_id + T1.based_on_id AS based_on_id, + T1.device_def_id AS advice_definition_id FROM wor_device_request AS T1 LEFT JOIN adm_device_definition AS T2 ON T2.ID = T1.device_def_id AND T2.delete_flag = '0' @@ -317,7 +319,8 @@ '' AS condition_definition_name, COALESCE(T1.therapy_enum, 2) AS therapyEnum, 99 AS sort_number, - T1.based_on_id AS based_on_id + T1.based_on_id AS based_on_id, + T1.activity_id AS advice_definition_id FROM wor_service_request AS T1 LEFT JOIN wor_activity_definition AS T2 ON T2.ID = T1.activity_id