From 52951d729621ce8512f0d769142a9bf16fdcf27c Mon Sep 17 00:00:00 2001 From: Ranyunqiao <2499115710@qq.com> Date: Thu, 12 Mar 2026 14:30:19 +0800 Subject: [PATCH] =?UTF-8?q?167=20=E4=BD=8F=E9=99=A2=E7=AE=A1=E7=90=86-?= =?UTF-8?q?=E3=80=8B=E4=BD=8F=E9=99=A2=E6=8A=A4=E5=A3=AB=E7=AB=99-?= =?UTF-8?q?=E3=80=8B=E5=85=A5=E5=87=BA=E8=BD=AC=E7=AE=A1=E7=90=86=EF=BC=9A?= =?UTF-8?q?=E6=8A=A4=E5=A3=AB=E7=99=BB=E5=BD=95=E7=9A=84=E7=A7=91=E5=AE=A4?= =?UTF-8?q?=E8=83=BD=E6=8E=A5=E6=94=B6=E6=9F=A5=E7=9C=8B=E5=88=B0=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E7=A7=91=E5=AE=A4=E7=9A=84=E5=85=A5=E7=A7=91=E6=82=A3?= =?UTF-8?q?=E8=80=85=20=E5=85=A5=E9=99=A2=E7=97=85=E5=8C=BA=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=8B=E6=8B=89=E5=86=85=E5=AE=B9=E9=99=90=E5=88=B6?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E6=98=BE=E7=A4=BA=E5=BD=93=E5=89=8D=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=A7=91=E5=AE=A4=E5=AF=B9=E5=BA=94=E7=9A=84=E7=97=85?= =?UTF-8?q?=E5=8C=BA=EF=BC=8C=E5=A6=82=E8=AF=A5=E6=8A=A4=E5=A3=AB=E8=BF=98?= =?UTF-8?q?=E6=9C=89=E5=85=B6=E4=BB=96=E7=A7=91=E5=AE=A4=E7=9A=84=E6=9D=83?= =?UTF-8?q?=E9=99=90=E9=9C=80=E8=A6=81=E5=81=9A=E5=88=87=E6=8D=A2=E7=A7=91?= =?UTF-8?q?=E5=AE=A4=E6=93=8D=E4=BD=9C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appservice/impl/CommonServiceImpl.java | 106 +++++++++++++++++- .../controller/CommonAppController.java | 4 +- .../charge/register/components/api.js | 11 ++ .../register/components/registerForm.vue | 6 +- .../inOut/components/bedAllocation.vue | 6 +- 5 files changed, 119 insertions(+), 14 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/appservice/impl/CommonServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/appservice/impl/CommonServiceImpl.java index 9d1ca616..62c2bbff 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/appservice/impl/CommonServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/appservice/impl/CommonServiceImpl.java @@ -464,17 +464,86 @@ public class CommonServiceImpl implements ICommonService { */ @Override public List getPractitionerWard() { - // 查询当前登录者管理的病区 + // 获取当前登录用户信息 Long practitionerId = SecurityUtils.getLoginUser().getPractitionerId(); + Long currentOrgId = SecurityUtils.getLoginUser().getOrgId(); + + log.info("getPractitionerWard - practitionerId: {}, currentOrgId: {}", practitionerId, currentOrgId); + + // 获取用户配置的位置 ID 列表(可能包含科室、病区等) List locationIds = practitionerRoleService.getLocationIdsByPractitionerId(practitionerId); - List locationList - = locationService.getLocationList(locationIds, Collections.singletonList(LocationStatus.ACTIVE.getValue())); + // 获取用户配置的科室 ID 列表 + List orgIds = practitionerRoleService.getOrgIdsByPractitionerId(practitionerId); + + log.info("getPractitionerWard - locationIds: {}, orgIds: {}", locationIds, orgIds); + List wardList = new ArrayList<>(); - for (Location ward : locationList) { - if (LocationForm.WARD.getValue().equals(ward.getFormEnum())) { - wardList.add(ward); + + // 方式 1:从 locationIds 中过滤出病区 + if (locationIds != null && !locationIds.isEmpty()) { + // 过滤掉 null 值 + locationIds = locationIds.stream().filter(id -> id != null).collect(java.util.stream.Collectors.toList()); + if (!locationIds.isEmpty()) { + List locationList + = locationService.getLocationList(locationIds, Collections.singletonList(LocationStatus.ACTIVE.getValue())); + log.info("getPractitionerWard - 从 locationIds 查询到的位置总数:{}", locationList != null ? locationList.size() : 0); + + for (Location location : locationList) { + log.info("getPractitionerWard - 位置:id={}, name={}, formEnum={}, organizationId={}", + location.getId(), location.getName(), location.getFormEnum(), location.getOrganizationId()); + if (LocationForm.WARD.getValue().equals(location.getFormEnum())) { + // 如果当前有选择科室,只添加当前科室的病区 + if (currentOrgId == null || currentOrgId.equals(location.getOrganizationId())) { + wardList.add(location); + } + } + } } } + + // 方式 2:从 orgIds 查询病区(补充查询,确保能获取到病区) + if (orgIds != null && !orgIds.isEmpty()) { + // 过滤掉 null 值并去重 + orgIds = orgIds.stream().filter(id -> id != null).distinct().collect(java.util.stream.Collectors.toList()); + if (!orgIds.isEmpty()) { + log.info("getPractitionerWard - 从 orgIds 查询病区,orgIds: {}", orgIds); + for (Long orgId : orgIds) { + // 如果当前有选择科室,只查询当前科室的病区 + if (currentOrgId != null && !currentOrgId.equals(orgId)) { + continue; + } + List orgWards = locationService.getWardList(orgId); + log.info("getPractitionerWard - orgId: {} 查询到病区数:{}", orgId, orgWards != null ? orgWards.size() : 0); + if (orgWards != null && !orgWards.isEmpty()) { + wardList.addAll(orgWards); + } + } + } + } + + // 方式 3:如果仍然没有病区,且 currentOrgId 为空,尝试获取所有病区 + if (wardList.isEmpty() && currentOrgId == null) { + log.info("getPractitionerWard - 尝试获取所有病区"); + List allWards = locationService.getWardList(null); + log.info("getPractitionerWard - 所有病区数:{}", allWards != null ? allWards.size() : 0); + if (allWards != null && !allWards.isEmpty()) { + wardList.addAll(allWards); + } + } + + // 去重:根据病区 ID 去重(因为方式 1 和方式 2 可能会查询到相同的病区) + if (!wardList.isEmpty()) { + wardList = wardList.stream() + .collect(java.util.stream.Collectors.collectingAndThen( + java.util.stream.Collectors.toCollection(() -> + new java.util.TreeSet<>(java.util.Comparator.comparing(Location::getId))), + ArrayList::new + )); + } + + log.info("getPractitionerWard - 最终病区数:{}", wardList.size()); + + // 转换为 DTO List locationDtoList = new ArrayList<>(); LocationDto locationDto; for (Location ward : wardList) { @@ -482,6 +551,31 @@ public class CommonServiceImpl implements ICommonService { BeanUtils.copyProperties(ward, locationDto); locationDtoList.add(locationDto); } + + return locationDtoList; + } + + /** + * 将Location列表转换为LocationDto列表 + * + * @param locationList Location列表 + * @return LocationDto列表 + */ + private List convertToLocationDtoList(List locationList) { + List locationDtoList = new ArrayList<>(); + if (locationList == null || locationList.isEmpty()) { + return locationDtoList; + } + + LocationDto locationDto; + for (Location location : locationList) { + // 只返回病区类型的位置 + if (LocationForm.WARD.getValue().equals(location.getFormEnum())) { + locationDto = new LocationDto(); + BeanUtils.copyProperties(location, locationDto); + locationDtoList.add(locationDto); + } + } return locationDtoList; } diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/controller/CommonAppController.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/controller/CommonAppController.java index 1b043e1a..d3a0dfd1 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/controller/CommonAppController.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/controller/CommonAppController.java @@ -202,8 +202,8 @@ public class CommonAppController { * @return 病区列表 */ @GetMapping(value = "/practitioner-ward") - public List getPractitionerWard() { - return commonService.getPractitionerWard(); + public R getPractitionerWard() { + return R.ok(commonService.getPractitionerWard()); } /** diff --git a/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/api.js b/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/api.js index a3ea9cae..d6711d77 100644 --- a/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/api.js +++ b/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/api.js @@ -206,3 +206,14 @@ export function getAllWards(params = {}) { }, }); } + +/** + * 获取当前登录用户有权限管理的病区 + */ +export function getPractitionerWard(queryParams) { + return request({ + url: '/app-common/practitioner-ward', + method: 'get', + params: queryParams, + }); +} diff --git a/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/registerForm.vue b/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/registerForm.vue index 05f42564..425dbe82 100644 --- a/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/registerForm.vue +++ b/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/registerForm.vue @@ -202,7 +202,7 @@