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 6995a5c6..27b7d0fe 100644 --- 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 @@ -140,6 +140,17 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp 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; + } + allowedLocByCategory.computeIfAbsent(String.valueOf(cfg.getCategoryCode()), k -> new HashSet<>()) + .add(cfg.getLocationId()); + } + } // 费用定价子表信息 List childCharge = doctorStationAdviceAppMapper .getChildCharge(ConditionCode.LOT_NUMBER_COST.getCode(), chargeItemDefinitionIdList); @@ -163,6 +174,19 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp .filter(e -> baseDto.getAdviceDefinitionId().equals(e.getItemId()) && baseDto.getAdviceTableName().equals(e.getItemTable())) .collect(Collectors.toList()); + // 当存在按科室配置时:仅保留被允许的药房/药库的库存; + // 若该药品类别未在配置中出现,则视为不可开立(清空库存以便前端过滤掉) + if (!allowedLocByCategory.isEmpty()) { + Set allowedLoc = + allowedLocByCategory.get(String.valueOf(baseDto.getCategoryCode())); + if (allowedLoc == null || allowedLoc.isEmpty()) { + inventoryList = Collections.emptyList(); + } else { + inventoryList = inventoryList.stream() + .filter(inv -> allowedLoc.contains(inv.getLocationId())) + .collect(Collectors.toList()); + } + } // 库存信息 baseDto.setInventoryList(inventoryList); // 设置默认产品批号 @@ -174,18 +198,15 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp baseDto.setDefaultLotNumber(hasInventoryList.get(0).getLotNumber()); } } - if (!inventoryList.isEmpty() && !medLocationConfig.isEmpty()) { - // 第一步:在medLocationConfig中匹配categoryCode - AdviceInventoryDto result1 = medLocationConfig.stream() - .filter(dto -> baseDto.getCategoryCode().equals(dto.getCategoryCode())).findFirst() - .orElse(null); - if (result1 != null) { - // 第二步:在inventoryList中匹配locationId - AdviceInventoryDto result2 = inventoryList.stream() - .filter(dto -> result1.getLocationId().equals(dto.getLocationId())).findFirst() - .orElse(null); - if (result2 != null && result2.getLotNumber() != null) { - baseDto.setDefaultLotNumber(result2.getLotNumber()); + if (!inventoryList.isEmpty() && !allowedLocByCategory.isEmpty()) { + Set allowedLoc = + allowedLocByCategory.get(String.valueOf(baseDto.getCategoryCode())); + if (allowedLoc != null && !allowedLoc.isEmpty()) { + AdviceInventoryDto hit = inventoryList.stream() + .filter(inv -> allowedLoc.contains(inv.getLocationId())) + .findFirst().orElse(null); + if (hit != null && hit.getLotNumber() != null) { + baseDto.setDefaultLotNumber(hit.getLotNumber()); } } }