From 9c345ded597a1a427dabc2cede4f33a056b03cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=91?= <赵云@gentronhealth.com> Date: Tue, 12 May 2026 17:22:05 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#470:=20=E4=BD=8F=E9=99=A2=E5=8C=BB?= =?UTF-8?q?=E7=94=9F=E5=B7=A5=E4=BD=9C=E7=AB=99-=E6=89=8B=E6=9C=AF?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E5=8D=95=E5=8A=A0=E8=BD=BD=E6=89=8B=E6=9C=AF?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=80=97=E6=97=B6=E8=BF=87=E9=95=BF=EF=BC=8C?= =?UTF-8?q?=E5=BD=B1=E5=93=8D=E5=8C=BB=E7=94=9F=E5=BC=80=E5=8D=95=E6=95=88?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:getAdviceBaseInfo 后端接口在查询手术项目时,仍会执行与手术无关的库存查询 (getAdviceInventory)、全表扫描待发放记录(getAdviceDraftInventory)以及药房科室 配置查询(getMedLocationConfig),其中 getAdviceDraftInventory 对 med_medication_dispense 和 wor_device_dispense 做全表扫描,无任何过滤条件, 导致手术/诊疗场景下的额外数据库开销。 修复:在 DoctorStationAdviceAppServiceImpl.getAdviceBaseInfo() 中增加类型判断, 当 adviceTypes 不包含药品(1)或耗材(2)时跳过所有库存相关查询,因为这些查询对手术/ 诊疗(3,6)项目无意义,且下游代码仅在药品/耗材处理分支中使用这些变量。 Co-Authored-By: Claude Opus 4.7 --- .../DoctorStationAdviceAppServiceImpl.java | 62 ++++++++++++------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java index 088ded73..ab864629 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java @@ -231,29 +231,49 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp // 费用定价主表ID集合 List chargeItemDefinitionIdList = adviceBaseDtoList.stream().map(AdviceBaseDto::getChargeItemDefinitionId) .collect(Collectors.toList()); - // 医嘱库存集合 - List adviceInventoryList = doctorStationAdviceAppMapper.getAdviceInventory(locationId, - adviceDefinitionIdList, - CommonConstants.SqlCondition.ABOUT_INVENTORY_TABLE_STR, PublicationStatus.ACTIVE.getValue()); - // 待发放个数信息 - List adviceDraftInventoryList = doctorStationAdviceAppMapper.getAdviceDraftInventory( - CommonConstants.TableName.MED_MEDICATION_DEFINITION, CommonConstants.TableName.ADM_DEVICE_DEFINITION, - DispenseStatus.DRAFT.getValue(), DispenseStatus.PREPARATION.getValue()); - // 预减库存 - List adviceInventory = adviceUtils.subtractInventory(adviceInventoryList, - adviceDraftInventoryList); - // 查询取药科室配置 - List medLocationConfig = doctorStationAdviceAppMapper.getMedLocationConfig(organizationId); - // 将配置转为 {categoryCode -> 允许的locationId集合} - Map> allowedLocByCategory = new HashMap<>(); - if (medLocationConfig != null && !medLocationConfig.isEmpty()) { - for (AdviceInventoryDto cfg : medLocationConfig) { - if (cfg.getCategoryCode() == null || cfg.getLocationId() == null) { - continue; + + // 判断是否包含药品或耗材类型(只有这些类型才需要库存相关查询) + boolean hasMedOrDevice = adviceTypes != null + && (adviceTypes.contains(1) || adviceTypes.contains(2)); + + // 医嘱库存集合 — 仅药品/耗材需要库存查询,手术/诊疗(3,6)无库存概念,跳过以减少数据库开销 + List adviceInventoryList; + List adviceDraftInventoryList; + List adviceInventory; + if (hasMedOrDevice) { + adviceInventoryList = doctorStationAdviceAppMapper.getAdviceInventory(locationId, + adviceDefinitionIdList, + CommonConstants.SqlCondition.ABOUT_INVENTORY_TABLE_STR, PublicationStatus.ACTIVE.getValue()); + // 待发放个数信息 + adviceDraftInventoryList = doctorStationAdviceAppMapper.getAdviceDraftInventory( + CommonConstants.TableName.MED_MEDICATION_DEFINITION, CommonConstants.TableName.ADM_DEVICE_DEFINITION, + DispenseStatus.DRAFT.getValue(), DispenseStatus.PREPARATION.getValue()); + // 预减库存 + adviceInventory = adviceUtils.subtractInventory(adviceInventoryList, adviceDraftInventoryList); + } else { + adviceInventoryList = Collections.emptyList(); + adviceDraftInventoryList = Collections.emptyList(); + adviceInventory = Collections.emptyList(); + } + // 查询取药科室配置 — 仅药品开单场景需要 + List medLocationConfig; + Map> allowedLocByCategory; + if (hasMedOrDevice) { + medLocationConfig = doctorStationAdviceAppMapper.getMedLocationConfig(organizationId); + // 将配置转为 {categoryCode -> 允许的locationId集合} + allowedLocByCategory = new HashMap<>(); + if (medLocationConfig != null && !medLocationConfig.isEmpty()) { + for (AdviceInventoryDto cfg : medLocationConfig) { + if (cfg.getCategoryCode() == null || cfg.getLocationId() == null) { + continue; + } + allowedLocByCategory.computeIfAbsent(String.valueOf(cfg.getCategoryCode()), k -> new HashSet<>()) + .add(cfg.getLocationId()); } - allowedLocByCategory.computeIfAbsent(String.valueOf(cfg.getCategoryCode()), k -> new HashSet<>()) - .add(cfg.getLocationId()); } + } else { + medLocationConfig = Collections.emptyList(); + allowedLocByCategory = Collections.emptyMap(); } // 费用定价子表信息 - 使用分批处理避免大量参数问题 List childCharge = new ArrayList<>();