Fix Bug #470: 住院医生工作站-手术申请单加载手术项目耗时过长,影响医生开单效率
根因: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 <noreply@anthropic.com>
This commit is contained in:
@@ -231,29 +231,49 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
// 费用定价主表ID集合
|
||||
List<Long> chargeItemDefinitionIdList = adviceBaseDtoList.stream().map(AdviceBaseDto::getChargeItemDefinitionId)
|
||||
.collect(Collectors.toList());
|
||||
// 医嘱库存集合
|
||||
List<AdviceInventoryDto> adviceInventoryList = doctorStationAdviceAppMapper.getAdviceInventory(locationId,
|
||||
adviceDefinitionIdList,
|
||||
CommonConstants.SqlCondition.ABOUT_INVENTORY_TABLE_STR, PublicationStatus.ACTIVE.getValue());
|
||||
// 待发放个数信息
|
||||
List<AdviceInventoryDto> adviceDraftInventoryList = doctorStationAdviceAppMapper.getAdviceDraftInventory(
|
||||
CommonConstants.TableName.MED_MEDICATION_DEFINITION, CommonConstants.TableName.ADM_DEVICE_DEFINITION,
|
||||
DispenseStatus.DRAFT.getValue(), DispenseStatus.PREPARATION.getValue());
|
||||
// 预减库存
|
||||
List<AdviceInventoryDto> adviceInventory = adviceUtils.subtractInventory(adviceInventoryList,
|
||||
adviceDraftInventoryList);
|
||||
// 查询取药科室配置
|
||||
List<AdviceInventoryDto> medLocationConfig = doctorStationAdviceAppMapper.getMedLocationConfig(organizationId);
|
||||
// 将配置转为 {categoryCode -> 允许的locationId集合}
|
||||
Map<String, Set<Long>> 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<AdviceInventoryDto> adviceInventoryList;
|
||||
List<AdviceInventoryDto> adviceDraftInventoryList;
|
||||
List<AdviceInventoryDto> 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<AdviceInventoryDto> medLocationConfig;
|
||||
Map<String, Set<Long>> 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<AdvicePriceDto> childCharge = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user