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<>();