浏览代码

组织机构树相关功能修改

songxinlu 3 年之前
父节点
当前提交
d31ed87bc7

+ 29 - 0
common/src/main/java/com/lantone/common/dto/GetDeptInfoDTO.java

@@ -0,0 +1,29 @@
+package com.lantone.common.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 科室返回对象
+ */
+@Data
+public class GetDeptInfoDTO implements Serializable {
+    private static final long serialVersionUID = 1L;
+    @ApiModelProperty(value = "科室编号")
+    private Long deptId;
+    @ApiModelProperty(value = "科室名称")
+    private String deptName;
+    @ApiModelProperty(value = "组织类型(0:AI病案质控平台 1:集团医院 2:医共 3:医联 4:医院 5:科室)")
+    private String type = "5";
+    @ApiModelProperty(value = "状态")
+    private String status;
+    @ApiModelProperty(value = "病区id")
+    private String regionId;
+    @ApiModelProperty(value = "病区名称")
+    private String regionName;
+    @ApiModelProperty(value = "记录创建时间")
+    private Date gmtCreate;
+}

+ 1 - 1
common/src/main/java/com/lantone/common/dto/GetDeptTreeDTO.java

@@ -16,5 +16,5 @@ public class GetDeptTreeDTO implements Serializable {
     @ApiModelProperty(value = "科室名称")
     private String deptName;
     @ApiModelProperty(value = "是否关联")
-    private String relation;
+    private String relation = "未关联";
 }

+ 39 - 0
common/src/main/java/com/lantone/common/dto/GetHospitalListInfoDTO.java

@@ -0,0 +1,39 @@
+package com.lantone.common.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * <p>
+ * 用户组织机构树对象
+ * </p>
+ */
+@Data
+public class GetHospitalListInfoDTO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "编号")
+    private Long hospitalId;
+
+    private Long parentId;
+
+    @ApiModelProperty(value = "名称")
+    private String hospitalName;
+    @ApiModelProperty(value = "状态")
+    private String status;
+
+    @ApiModelProperty(value = "组织类型(0:AI病案质控平台 1:集团医院 2:医共 3:医联 4:医院 5:科室)")
+    private String type;
+
+    @ApiModelProperty(value = "该医院的科室列表")
+    private List<GetDeptInfoDTO> depts;
+
+    @ApiModelProperty(value = "该虚拟医院的医院列表")
+    private List<GetHospitalListInfoDTO> hospitalDTOS;
+    @ApiModelProperty(value = "记录创建时间")
+    private Date gmtCreate;
+}

+ 1 - 1
common/src/main/java/com/lantone/common/dto/GetHospitalTreeDTO.java

@@ -36,5 +36,5 @@ public class GetHospitalTreeDTO implements Serializable {
     private List<GetHospitalTreeDTO> hospitalDTOS;
 
     @ApiModelProperty(value = "是否关联")
-    private String relation;
+    private String relation = "未关联";
 }

+ 25 - 0
common/src/main/java/com/lantone/common/vo/GetHospitalListInfoVO.java

@@ -0,0 +1,25 @@
+package com.lantone.common.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @Description:组织管理列表页查询对象
+ * @Author songxl
+ * @Date 2021/8/9
+ */
+@Data
+public class GetHospitalListInfoVO {
+
+    @ApiModelProperty(value = "登录用户医院id" ,hidden = true)
+    private Long hospitalId;
+
+    @ApiModelProperty(value = "医院名称")
+    private String hospitalName;
+    @ApiModelProperty(value = "类型")
+    private String type;
+    @ApiModelProperty(value = "当前状态")
+    private String status;
+    @ApiModelProperty(value = "所属病区id")
+    private String regionId;
+}

+ 4 - 0
dblayer-mbg/src/main/java/com/lantone/dblayermbg/mapper/DeptMapper.java

@@ -1,7 +1,9 @@
 package com.lantone.dblayermbg.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.lantone.common.dto.GetDeptInfoDTO;
 import com.lantone.common.dto.GetDeptTreeDTO;
+import com.lantone.common.vo.GetHospitalListInfoVO;
 import com.lantone.dblayermbg.entity.Dept;
 import org.apache.ibatis.annotations.Param;
 
@@ -15,4 +17,6 @@ import java.util.List;
 public interface DeptMapper extends BaseMapper<Dept> {
 
     List<GetDeptTreeDTO> getDeptInfo(@Param("hospitalId") long hospitalId);
+
+    List<GetDeptInfoDTO> getDeptRegion(@Param("getHospitalListInfoVO") GetHospitalListInfoVO getHospitalListInfoVO);
 }

+ 4 - 5
dblayer-mbg/src/main/java/com/lantone/dblayermbg/mapper/HospitalMapper.java

@@ -1,8 +1,9 @@
 package com.lantone.dblayermbg.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.lantone.common.dto.GetHospitalDeptDTO;
+import com.lantone.common.dto.GetHospitalListInfoDTO;
 import com.lantone.common.dto.GetHospitalTreeDTO;
+import com.lantone.common.vo.GetHospitalListInfoVO;
 import com.lantone.dblayermbg.entity.Hospital;
 import org.apache.ibatis.annotations.Param;
 
@@ -15,9 +16,7 @@ import java.util.List;
  */
 public interface HospitalMapper extends BaseMapper<Hospital> {
 
-    List<GetHospitalTreeDTO> getHospitalTreeInfo(@Param("hospitalId") long hospitalId,@Param("userId") Long userId);
+    List<GetHospitalTreeDTO> getHospitalTreeInfo(@Param("hospitalId") long hospitalId);
 
-    List<GetHospitalDeptDTO> getUserHospitalDept(@Param("hospitalId")Long hospitalId,@Param("userId") Long userId);
-
-    List<GetHospitalDeptDTO> getUserHospital(@Param("hospitalId")Long hospitalId,@Param("userId") Long userId);
+    List<GetHospitalListInfoDTO> getHospitalById(@Param("getHospitalListInfoVO") GetHospitalListInfoVO getHospitalListInfoVO);
 }

+ 29 - 0
dblayer-mbg/src/main/resources/mapper/DeptMapper.xml

@@ -13,4 +13,33 @@
             AND d.`hospital_id` = #{hospitalId}
         </if>
     </select>
+    <select id="getDeptRegion" resultType="com.lantone.common.dto.GetDeptInfoDTO">
+        SELECT
+            d.id deptId,
+            d.`name` deptName,
+            d.`status`,
+            r.id regionId,
+            r.`name` regionName,
+            d.gmt_create gmtCreate
+        FROM
+            sys_dept d,
+            sys_region_dept rd,
+            sys_region r
+        WHERE
+            d.is_deleted = 'N'
+        AND rd.is_deleted = 'N'
+        AND r.is_deleted = 'N'
+        AND d.id = rd.dept_id
+        AND rd.region_id = r.id
+        AND d.hospital_id = #{getHospitalListInfoVO.hospitalId}
+        <if test="getHospitalListInfoVO.hospitalName !=null and getHospitalListInfoVO.hospitalName!=''">
+            AND d.`name` LIKE concat('%',#{getHospitalListInfoVO.hospitalName},'%')
+        </if>
+        <if test="getHospitalListInfoVO.status !=null and getHospitalListInfoVO.status!=''">
+            AND d.`status` = #{getHospitalListInfoVO.status}
+        </if>
+        <if test="getHospitalListInfoVO.status !=null and getHospitalListInfoVO.status!=''">
+            AND r.id = #{getHospitalListInfoVO.regionId}
+        </if>
+    </select>
 </mapper>

+ 30 - 97
dblayer-mbg/src/main/resources/mapper/HospitalMapper.xml

@@ -3,108 +3,41 @@
 <mapper namespace="com.lantone.dblayermbg.mapper.HospitalMapper">
     <select id="getHospitalTreeInfo" resultType="com.lantone.common.dto.GetHospitalTreeDTO">
         SELECT
-        h.id hospitalId,
-        h.`name` hospitalName,
-        h.type,
-        h.parent_id parentId
+            h.id hospitalId,
+            h.parent_id parentId,
+            h.`name` hospitalName,
+            h.type
         FROM
-        sys_hospital h
+            sys_hospital h
         WHERE
-        h.is_deleted = 'N'
-        AND h.status  = '1'
-        <if test="hospitalId!=null">
-            AND h.parent_id = #{hospitalId}
-        </if>
-        <if test="userId!=null">
-            AND h.creator = #{userId}
-        </if>
-    </select>
-    <select id="getUserHospitalDept" resultType="com.lantone.common.dto.GetHospitalDeptDTO">
-        SELECT
-            t1.*,
-        IF (
-            ISNULL(t2.hospitalId),
-            '未关联',
-            '已关联'
-        ) relation
-        FROM
-            (
-                SELECT
-                    h.id hospitalId,
-                    h.`name` hospitalName,
-                    d.id deptId,
-                    d.`name` deptName,
-                    h.parent_id parentId,
-			        h.type
-                FROM
-                    sys_hospital h,
-                    sys_dept d
-                WHERE
-                    h.id = d.hospital_id
-                AND h.`status` = '1'
-                AND h.is_deleted = 'N'
-                AND d.is_deleted = 'N'
-                AND h.id = #{hospitalId}
-            ) t1
-        LEFT JOIN (
-            SELECT
-                h.id hospitalId,
-                h.`name` hospitalName,
-                d.id deptId,
-                d.`name` deptName
-            FROM
-                sys_hospital h,
-                sys_hospital_user hu,
-                sys_dept_user ud,
-                sys_dept d,
-                sys_user u
-            WHERE
-                h.id = hu.hospital_id
-            AND h.`status` = '1'
-            AND u.`status` = '1'
-            AND u.id = hu.user_id
-            AND hu.user_id = ud.user_id
-            AND ud.dept_id = d.id
-            AND hu.hospital_id = d.hospital_id
-            AND ud.user_id = #{userId}
-        ) t2 ON t1.hospitalId = t2.hospitalId
-        AND t1.deptId = t2.deptId
+            h.is_deleted = 'N'
+        AND h.`status` = '1'
+        AND FIND_IN_SET(h.id, getChildList(#{hospitalId}))
     </select>
-    <select id="getUserHospital" resultType="com.lantone.common.dto.GetHospitalDeptDTO">
+    <select id="getHospitalById" resultType="com.lantone.common.dto.GetHospitalListInfoDTO">
         SELECT
-            t1.*,
-        IF (
-            ISNULL(t2.hospitalId),
-            '未关联',
-            '已关联'
-        ) relation
+            h.id hospitalId,
+            h.`name` hospitalName,
+            h.parent_id parentId,
+            h.`status`,
+            h.type,
+            h.gmt_create gmtCreate
         FROM
-            (
-                SELECT
-                    h.id hospitalId,
-                    h.`name` hospitalName,
-                    h.parent_id parentId,
-                    h.type
-                FROM
-                    sys_hospital h
-                WHERE
-                    h.`status` = 1
-                AND h.is_deleted = 'N'
-                AND h.id = #{hospitalId}
-                OR h.parent_id = #{hospitalId}
-            ) t1
-        LEFT JOIN (
-            SELECT
-                h.id hospitalId,
-                h.`name` hospitalName,
-                h.type
-            FROM
-                sys_hospital h,
-                sys_hospital_user hu
-            WHERE
-                h.id = hu.hospital_id
-            AND hu.user_id = #{userId}
-        ) t2 ON t1.hospitalId = t2.hospitalId
+            sys_hospital h
+        WHERE
+            h.is_deleted = 'N'
+        AND h.id = #{getHospitalListInfoVO.hospitalId}
+        OR h.parent_id = #{getHospitalListInfoVO.hospitalId}
+        <if test="getHospitalListInfoVO.hospitalName !=null and getHospitalListInfoVO.hospitalName!=''">
+            AND h.`name` LIKE concat ('%',#{getHospitalListInfoVO.hospitalName},'%')
+        </if>
+        <if test="getHospitalListInfoVO.type !=null and getHospitalListInfoVO.type!=''">
+            AND h.type = #{getHospitalListInfoVO.type}
+        </if>
+        <if test="getHospitalListInfoVO.status !=null and getHospitalListInfoVO.status!=''">
+            AND h.`status` = #{getHospitalListInfoVO.status}
+        </if>
+
 
     </select>
 </mapper>

+ 103 - 50
security-center/src/main/java/com/lantone/security/facade/HospitalManagementFacade.java

@@ -2,26 +2,27 @@ package com.lantone.security.facade;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.graphbuilder.math.func.FactFunction;
 import com.lantone.common.dto.DownBoxRegionDTO;
-import com.lantone.common.dto.GetDeptTreeDTO;
 import com.lantone.common.dto.GetHospitalByIdDTO;
-import com.lantone.common.dto.GetHospitalTreeDTO;
+import com.lantone.common.dto.GetHospitalListInfoDTO;
 import com.lantone.common.dto.GetHospitalUserDTO;
 import com.lantone.common.enums.IsDeleteEnum;
 import com.lantone.common.exception.Asserts;
 import com.lantone.common.util.DateUtil;
+import com.lantone.common.util.EntityUtil;
+import com.lantone.common.util.ListUtil;
 import com.lantone.common.vo.AddHospitalTreeVO;
-import com.lantone.common.vo.AddHospitalUserVO;
 import com.lantone.common.vo.AddHospitalVO;
 import com.lantone.common.vo.AddRoleVO;
 import com.lantone.common.vo.AddUserVO;
+import com.lantone.common.vo.GetHospitalListInfoVO;
 import com.lantone.common.vo.UpdateHospitalVO;
 import com.lantone.dblayermbg.entity.Hospital;
 import com.lantone.dblayermbg.entity.HospitalUser;
 import com.lantone.dblayermbg.entity.Region;
 import com.lantone.dblayermbg.entity.Role;
 import com.lantone.dblayermbg.entity.User;
+import com.lantone.dblayermbg.facade.DeptFacade;
 import com.lantone.dblayermbg.facade.HospitalFacade;
 import com.lantone.dblayermbg.facade.HospitalUserFacade;
 import com.lantone.dblayermbg.facade.RegionFacade;
@@ -47,6 +48,8 @@ public class HospitalManagementFacade {
     @Autowired
     private HospitalFacade hospitalFacade;
     @Autowired
+    private DeptFacade deptFacade;
+    @Autowired
     private HospitalUserFacade hospitalUserFacade;
     @Autowired
     private UserRoleFacade userRoleFacade;
@@ -116,17 +119,18 @@ public class HospitalManagementFacade {
         }
         return false;
     }
+
     /**
-     * @Description删除组织
      * @param hospitalId
+     * @Description删除组织
      * @Return boolean
      */
     public boolean deleteHospital(Long hospitalId) {
         //1.删除组织表sys_hospital
-        if(hospitalFacade.removeById(hospitalId)){
+        if (hospitalFacade.removeById(hospitalId)) {
             //2.删除该组织的管理用户、角色
             return deleteHUserAndRole(hospitalId);
-        }else {
+        } else {
             Asserts.fail("组织表删除失败");
         }
 
@@ -134,18 +138,18 @@ public class HospitalManagementFacade {
     }
 
     /**
-     * @Description删除该组织的管理用户、角色
      * @param hospitalId
+     * @Description删除该组织的管理用户、角色
      * @Return boolean
      */
     private boolean deleteHUserAndRole(Long hospitalId) {
         //1.获取用户id
         Long userId = hospitalUserFacade.getBaseMapper().getHospitalUserById(hospitalId);
-        if(userManagementFacade.deleteUser(userId)){
+        if (userManagementFacade.deleteUser(userId)) {
             //2.获取角色id
             Long roleId = userRoleFacade.getBaseMapper().getUserRoleById(userId);
             return roleManagementFacade.deleteRole(roleId);
-        }else {
+        } else {
             Asserts.fail("管理用户删除失败");
         }
 
@@ -153,69 +157,69 @@ public class HospitalManagementFacade {
     }
 
     /**
-     * @Description修改组织信息
      * @param updateHospitalVO
+     * @Description修改组织信息
      * @Return boolean
      */
     public boolean updateHospital(UpdateHospitalVO updateHospitalVO) {
         //1.删除该组织关联的管理用户以及角色
-        if(deleteHUserAndRole(updateHospitalVO.getId())){
+        if (deleteHUserAndRole(updateHospitalVO.getId())) {
             Hospital hospital = new Hospital();
-            BeanUtils.copyProperties(updateHospitalVO,hospital);
+            BeanUtils.copyProperties(updateHospitalVO, hospital);
             //2.修改组织信息
-            if(hospitalFacade.updateById(hospital)){
+            if (hospitalFacade.updateById(hospital)) {
                 //3.创建组织与管理用户、角色
                 AddHospitalVO addHospitalVO = new AddHospitalVO();
-                BeanUtils.copyProperties(addHospitalVO,updateHospitalVO);
+                BeanUtils.copyProperties(addHospitalVO, updateHospitalVO);
                 addHospitalVO.setAddHospitalUserVO(updateHospitalVO.getAddHospitalUserVO());
                 addHospitalVO.setSoftwares(updateHospitalVO.getSoftwares());
-                return saveUser(updateHospitalVO.getId(),addHospitalVO);
+                return saveUser(updateHospitalVO.getId(), addHospitalVO);
             }
         }
         return false;
     }
 
     /**
-     * @Description禁用启用组织
      * @param hospitalId
      * @param status
+     * @Description禁用启用组织
      * @Return boolean
      */
     public boolean disableHospital(Long hospitalId, String status) {
-        return hospitalFacade.update(new UpdateWrapper<Hospital>().set("status",status).eq("id",hospitalId));
+        return hospitalFacade.update(new UpdateWrapper<Hospital>().set("status", status).eq("id", hospitalId));
     }
 
     /**
-     * @Description通过组织id获取该组织及用户详情
      * @param hospitalId
      * @param local
+     * @Description通过组织id获取该组织及用户详情
      * @Return com.lantone.common.dto.GetHospitalByIdDTO
      */
     public GetHospitalByIdDTO getHospitalById(Long hospitalId, Long local) {
         GetHospitalByIdDTO getHospitalByIdDTO = new GetHospitalByIdDTO();
         //1.获取医院详情
         Hospital hospital = hospitalFacade.getById(hospitalId);
-        BeanUtils.copyProperties(hospital,getHospitalByIdDTO);
+        BeanUtils.copyProperties(hospital, getHospitalByIdDTO);
         getHospitalByIdDTO.setParentName(hospitalFacade.getById(hospital.getParentId()).getName());
         //2.获取该医院的管理用户详情
         User user = userFacade.getById(hospitalUserFacade.getBaseMapper().getHospitalUserById(hospitalId));
         GetHospitalUserDTO getHospitalUserDTO = new GetHospitalUserDTO();
-        BeanUtils.copyProperties(user,getHospitalUserDTO);
+        BeanUtils.copyProperties(user, getHospitalUserDTO);
         getHospitalByIdDTO.setGetHospitalUserDTO(getHospitalUserDTO);
         //3.获取管理角色相关信息
         getHospitalByIdDTO.setGetRoleDTO(roleManagementFacade.getRoleById(userRoleFacade.getBaseMapper()
-                    .getUserRoleById(user.getId())));
+                .getUserRoleById(user.getId())));
         return getHospitalByIdDTO;
     }
 
     /**
-     * @Description组织管理列表页管理员下拉框筛选类型、病区查询
      * @param
-     * @Return java.util.Map<java.lang.String,java.lang.Object>
+     * @Description组织管理列表页管理员下拉框筛选类型、病区查询
+     * @Return java.util.Map<java.lang.String, java.lang.Object>
      */
-    public Map<String,Object> getManagerBoxInfo(Long local) {
-        Map<String,Object> outMap = new HashMap<>();
-        Map<Integer,String> hospitalTypeMap = new HashMap<>();
+    public Map<String, Object> getManagerBoxInfo(Long local) {
+        Map<String, Object> outMap = new HashMap<>();
+        Map<Integer, String> hospitalTypeMap = new HashMap<>();
         //1.获取当前用户的组织类型
         int hospitalType = -1;
         Hospital hospital = hospitalFacade.getById(local);//###当前登录用户的医院id
@@ -227,36 +231,85 @@ public class HospitalManagementFacade {
             //获取病区信息
             List<DownBoxRegionDTO> downBoxRegions = new ArrayList<>();
             regionFacade.list(new QueryWrapper<Region>()
-                    .eq("hospital_id",hospital.getId())
+                    .eq("hospital_id", hospital.getId())
                     .eq("is_deleted", IsDeleteEnum.N.getKey())).stream().forEach(region -> {
                 DownBoxRegionDTO downBoxRegionDTO = new DownBoxRegionDTO();
-                BeanUtils.copyProperties(region,downBoxRegionDTO);
+                BeanUtils.copyProperties(region, downBoxRegionDTO);
                 downBoxRegions.add(downBoxRegionDTO);
             });
-            outMap.put("所属病区",downBoxRegions);
-        }else if (HospitalTypeEnum.AI_PLATFORM.getKey()== hospitalType) {
-            hospitalTypeMap.put(HospitalTypeEnum.GROUP_HOSPITAL.getKey(),HospitalTypeEnum.GROUP_HOSPITAL.getName());
-            hospitalTypeMap.put(HospitalTypeEnum.SINGLE_HOSPITAL.getKey(),HospitalTypeEnum.SINGLE_HOSPITAL.getName());
-            hospitalTypeMap.put(HospitalTypeEnum.COMMON_HOSPITAL.getKey(),HospitalTypeEnum.COMMON_HOSPITAL.getName());
-            hospitalTypeMap.put(HospitalTypeEnum.UNION_HOSPITAL.getKey(),HospitalTypeEnum.UNION_HOSPITAL.getName());
-            outMap.put("类型",hospitalTypeMap);
+            outMap.put("所属病区", downBoxRegions);
+        } else if (HospitalTypeEnum.AI_PLATFORM.getKey() == hospitalType) {
+            hospitalTypeMap.put(HospitalTypeEnum.GROUP_HOSPITAL.getKey(), HospitalTypeEnum.GROUP_HOSPITAL.getName());
+            hospitalTypeMap.put(HospitalTypeEnum.SINGLE_HOSPITAL.getKey(), HospitalTypeEnum.SINGLE_HOSPITAL.getName());
+            hospitalTypeMap.put(HospitalTypeEnum.COMMON_HOSPITAL.getKey(), HospitalTypeEnum.COMMON_HOSPITAL.getName());
+            hospitalTypeMap.put(HospitalTypeEnum.UNION_HOSPITAL.getKey(), HospitalTypeEnum.UNION_HOSPITAL.getName());
+            outMap.put("类型", hospitalTypeMap);
+        } else if (HospitalTypeEnum.GROUP_HOSPITAL.getKey() == hospitalType) {
+            hospitalTypeMap.put(HospitalTypeEnum.GROUP_HOSPITAL.getKey(), HospitalTypeEnum.GROUP_HOSPITAL.getName());
+            hospitalTypeMap.put(HospitalTypeEnum.SINGLE_HOSPITAL.getKey(), HospitalTypeEnum.SINGLE_HOSPITAL.getName());
+            outMap.put("类型", hospitalTypeMap);
+        } else if (HospitalTypeEnum.COMMON_HOSPITAL.getKey() == hospitalType) {
+            hospitalTypeMap.put(HospitalTypeEnum.SINGLE_HOSPITAL.getKey(), HospitalTypeEnum.SINGLE_HOSPITAL.getName());
+            hospitalTypeMap.put(HospitalTypeEnum.COMMON_HOSPITAL.getKey(), HospitalTypeEnum.COMMON_HOSPITAL.getName());
+            outMap.put("类型", hospitalTypeMap);
+        } else if (HospitalTypeEnum.UNION_HOSPITAL.getKey() == hospitalType) {
+            hospitalTypeMap.put(HospitalTypeEnum.SINGLE_HOSPITAL.getKey(), HospitalTypeEnum.SINGLE_HOSPITAL.getName());
+            hospitalTypeMap.put(HospitalTypeEnum.UNION_HOSPITAL.getKey(), HospitalTypeEnum.UNION_HOSPITAL.getName());
+            outMap.put("类型", hospitalTypeMap);
         }
-        else if (HospitalTypeEnum.GROUP_HOSPITAL.getKey()== hospitalType) {
-            hospitalTypeMap.put(HospitalTypeEnum.GROUP_HOSPITAL.getKey(),HospitalTypeEnum.GROUP_HOSPITAL.getName());
-            hospitalTypeMap.put(HospitalTypeEnum.SINGLE_HOSPITAL.getKey(),HospitalTypeEnum.SINGLE_HOSPITAL.getName());
-            outMap.put("类型",hospitalTypeMap);
+        return outMap;
+    }
+
+    /**
+     * @param getHospitalListInfoVO
+     * @Description获取当前登录用户的组织结构树
+     * @Return java.util.List<com.lantone.common.dto.GetHospitalListInfoDTO>
+     */
+    public List<GetHospitalListInfoDTO> getHospitalListInfo(GetHospitalListInfoVO getHospitalListInfoVO) {
+        //1.获取当前用户的组织类型
+        int hospitalType = -1;
+        Hospital hospital = hospitalFacade.getById(getHospitalListInfoVO.getHospitalId());//###当前登录用户的医院id
+        if (hospital != null) {
+            hospitalType = Integer.parseInt(hospital.getType());
         }
-        else if (HospitalTypeEnum.COMMON_HOSPITAL.getKey()== hospitalType) {
-            hospitalTypeMap.put(HospitalTypeEnum.SINGLE_HOSPITAL.getKey(),HospitalTypeEnum.SINGLE_HOSPITAL.getName());
-            hospitalTypeMap.put(HospitalTypeEnum.COMMON_HOSPITAL.getKey(),HospitalTypeEnum.COMMON_HOSPITAL.getName());
-            outMap.put("类型",hospitalTypeMap);
+        //单家医院
+        if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == hospitalType) {
+            //1.获取当前登陆用户所在医院的科室信息
+        GetHospitalListInfoDTO getHospitalListInfoDTO = new GetHospitalListInfoDTO();
+        getHospitalListInfoDTO.setHospitalId(hospital.getId());
+        getHospitalListInfoDTO.setHospitalName(hospital.getName());
+        BeanUtils.copyProperties(hospital,getHospitalListInfoDTO);
+        getHospitalListInfoDTO.setDepts(deptFacade.getBaseMapper().getDeptRegion(getHospitalListInfoVO));
+        List<GetHospitalListInfoDTO> hospitalListInfos = new ArrayList<>();
+        hospitalListInfos.add(getHospitalListInfoDTO);
+        return hospitalListInfos;
+            //虚拟医院
+        } else if (hospitalType >= 0) {
+            List<GetHospitalListInfoDTO> hospitalListInfoDTOS = hospitalFacade.getBaseMapper().getHospitalById(getHospitalListInfoVO);//###当前登录用户的医院id
+            Map<Long, List<GetHospitalListInfoDTO>> hospitalMaps = EntityUtil.makeEntityListMap(hospitalListInfoDTOS, "parentId");
+            List<GetHospitalListInfoDTO> hospitalListInfos = hospitalMaps.get(hospital.getParentId());
+            for(GetHospitalListInfoDTO bean:hospitalListInfos){
+                getSonHospital(bean,hospitalMaps);
+            }
+            return hospitalListInfos;
         }
-        else if (HospitalTypeEnum.UNION_HOSPITAL.getKey()== hospitalType) {
-            hospitalTypeMap.put(HospitalTypeEnum.SINGLE_HOSPITAL.getKey(),HospitalTypeEnum.SINGLE_HOSPITAL.getName());
-            hospitalTypeMap.put(HospitalTypeEnum.UNION_HOSPITAL.getKey(),HospitalTypeEnum.UNION_HOSPITAL.getName());
-            outMap.put("类型",hospitalTypeMap);
+
+        return null;
+    }
+    /**
+     * 递归获取医院结构
+     *
+     * @param hospital    当前医院
+     * @param hospitalMap 医院集
+     * @return 空
+     */
+    public void getSonHospital(GetHospitalListInfoDTO hospital, Map<Long, List<GetHospitalListInfoDTO>> hospitalMap) {
+        List<GetHospitalListInfoDTO> hospitals = hospitalMap.get(hospital.getHospitalId());
+        if (ListUtil.isNotEmpty(hospitals)) {
+            hospital.setHospitalDTOS(hospitals);
+            for (GetHospitalListInfoDTO bean : hospitals) {
+                getSonHospital(bean, hospitalMap);
+            }
         }
-        return outMap;
     }
-
 }

+ 82 - 130
security-center/src/main/java/com/lantone/security/facade/UserManagementFacade.java

@@ -37,6 +37,7 @@ import com.lantone.dblayermbg.facade.RoleFacade;
 import com.lantone.dblayermbg.facade.UserFacade;
 import com.lantone.dblayermbg.facade.UserRoleFacade;
 import com.lantone.security.enums.HospitalTypeEnum;
+import com.lantone.security.enums.RelationEnum;
 import com.lantone.security.service.AuthService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -63,6 +64,8 @@ public class UserManagementFacade {
     @Autowired
     private HospitalUserFacade hospitalUserFacade;
     @Autowired
+    private DeptUserFacade deptUserFacade;
+    @Autowired
     private DeptFacade deptFacade;
     @Autowired
     private UserFacade userFacade;
@@ -217,68 +220,25 @@ public class UserManagementFacade {
      * @Description获取当前用户的组织机构树
      * @Return java.util.List<com.lantone.common.dto.GetHospitalTreeDTO>
      */
-    public List<GetHospitalTreeDTO> getLoginUserHospitalTree() {
-        List<GetHospitalTreeDTO> outTree = new ArrayList<>();
-        //1.获取当前用户的组织类型
-        int hospitalType = -1;
-        Hospital hospital = hospitalFacade.getById(1l);//###当前登录用户的医院id
-        if (hospital != null) {
-            hospitalType = Integer.parseInt(hospital.getType());
-        }
-        //单家医院
-        if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == hospitalType) {
-            //获取医院的科室信息
-            List<GetDeptTreeDTO> deptTreeDTOS = deptFacade.getBaseMapper().getDeptInfo(1l);//###当前登录用户的医院id
-            GetHospitalTreeDTO getHospitalTreeDTO = new GetHospitalTreeDTO();
-            getHospitalTreeDTO.setDepts(deptTreeDTOS);
-            BeanUtils.copyProperties(hospital, getHospitalTreeDTO);
-            outTree.add(getHospitalTreeDTO);
-            return outTree;
-
-            //虚拟医院
-        } else if (hospitalType >= 0) {
-            //获取医院信息
-            GetHospitalTreeDTO getHospitalTreeDTO = new GetHospitalTreeDTO();
-            getHospitalTreeDTO.setHospitalId(hospital.getId());
-            getHospitalTreeDTO.setHospitalName(hospital.getName());
-            BeanUtils.copyProperties(hospital, getHospitalTreeDTO);
-            List<GetHospitalTreeDTO> hospitalTrees = getSonHospital(getHospitalTreeDTO);
-            getAllHospitalDTO(hospitalTrees);
-            getHospitalTreeDTO.setHospitalDTOS(hospitalTrees);
-            outTree.add(getHospitalTreeDTO);
-            return outTree;
-        }
-        return null;
-    }
-
-
-    /**
-     * @param hospitalTrees
-     * @Description 获取医院对应的子医院信息
-     * @Return void
-     */
-    private void getAllHospitalDTO(List<GetHospitalTreeDTO> hospitalTrees) {
-        if (ListUtil.isNotEmpty(hospitalTrees)) {
-            for (GetHospitalTreeDTO tempHospitalDTO : hospitalTrees) {
-                getAllHospitalDTO(getSonHospital(tempHospitalDTO));
+    public List<GetHospitalTreeDTO> getLoginUserHospitalTree(Long h) {
+        Hospital hospital = hospitalFacade.getById(h);//###当前登录用户的医院id
+        //获取当前医院的树状结构
+        List<GetHospitalTreeDTO> hospitalTrees = hospitalFacade.getBaseMapper()
+                .getHospitalTreeInfo(h);//###当前登录用户id
+        //根据parentid分组
+        Map<Long, List<GetHospitalTreeDTO>> hospitalMap = EntityUtil.makeEntityListMap(hospitalTrees, "parentId");
+        //深度遍历拼装结果
+        List<GetHospitalTreeDTO> hospitalTree = hospitalMap.get(hospital.getParentId());
+        for (GetHospitalTreeDTO getHospitalTreeDTO : hospitalTree) {
+            //真实医院添加科室信息
+            if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == Integer.parseInt(getHospitalTreeDTO.getType())) {
+                getHospitalTreeDTO.setDepts(deptFacade.getBaseMapper().getDeptInfo(getHospitalTreeDTO.getHospitalId()));
             }
+            getSonHospital(getHospitalTreeDTO, hospitalMap);
         }
+        return hospitalTree;
     }
 
-    /**
-     * @param getHospitalTreeDTO
-     * @Description获取医院信息
-     * @Return java.util.List<com.lantone.common.dto.HospitalDTO>
-     */
-    private List<GetHospitalTreeDTO> getSonHospital(GetHospitalTreeDTO getHospitalTreeDTO) {
-        if (getHospitalTreeDTO.getHospitalId() != null) {
-            List<GetHospitalTreeDTO> sonHospitals = hospitalFacade.getBaseMapper()
-                    .getHospitalTreeInfo(getHospitalTreeDTO.getHospitalId(), getHospitalTreeDTO.getCreator());
-            getHospitalTreeDTO.setHospitalDTOS(sonHospitals);
-            return sonHospitals;
-        }
-        return null;
-    }
 
     /**
      * @param updateUserVO
@@ -375,86 +335,76 @@ public class UserManagementFacade {
         //1.获取用户的基本信息
         BeanUtils.copyProperties(userFacade.getById(userId), getUserDTO);
         //2.获取当前用户的组织类型
-        int hospitalType = -1;
         Hospital hospital = hospitalFacade.getById(local);//###当前登录用户的医院id
-        if (hospital != null) {
-            hospitalType = Integer.parseInt(hospital.getType());
-        }
 
         //###通过职称id获取用户的职称
 
-        //3.1如果是单家医院
-        if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == hospitalType) {
-            List<GetHospitalDeptDTO> hospitalDepts = hospitalFacade.getBaseMapper().getUserHospitalDept(hospital.getId(), userId);
-            getUserRelation(getUserDTO, hospitalDepts, hospitalType);
-            //3.2虚拟医院
-        } else if (hospitalType >= 0) {
-            List<GetHospitalDeptDTO> hospitals = hospitalFacade.getBaseMapper().getUserHospital(hospital.getId(), userId);
-            getUserRelation(getUserDTO, hospitals, hospitalType);
-        }
+        //3.获取查询用户的科室id列表、医院id列表
+        List<Long> hospitals = hospitalUserFacade.list(new QueryWrapper<HospitalUser>()
+                .eq("user_id", userId)
+                .eq("is_deleted", IsDeleteEnum.N.getKey())).stream().map(HospitalUser::getHospitalId).collect(Collectors.toList());
+        List<Long> depts = deptUserFacade.list(new QueryWrapper<DeptUser>()
+                .eq("user_id", userId)
+                .eq("is_deleted", IsDeleteEnum.N.getKey())).stream().map(DeptUser::getDeptId).collect(Collectors.toList());
+        //3.2获取当前登录用户的组织机构树
+        //获取当前医院的树状结构
+        List<GetHospitalTreeDTO> hospitalTrees = hospitalFacade.getBaseMapper()
+                .getHospitalTreeInfo(local);//###当前登录用户的医院id
+        //根据parentid分组
+        Map<Long, List<GetHospitalTreeDTO>> hospitalMap = EntityUtil.makeEntityListMap(hospitalTrees, "parentId");
+        //深度遍历拼装结果
+        List<GetHospitalTreeDTO> hospitalTree = hospitalMap.get(hospital.getParentId());
+        getHospitalDeptInfo(hospitalMap, hospitals, depts, hospitalTree);
+        getUserDTO.setHospitalDTOS(hospitalTree);
+
         //4.获取用户的角色
         getUserDTO.setRoles(userRoleFacade.getBaseMapper().getUserRoles(userId));
         return getUserDTO;
     }
 
+
     /**
-     * @param getUserDTO
-     * @param hospitalDepts
-     * @param hospitalType
-     * @Description 获取当前用户组织机构树以及查询用户对应组织关联关系
+     * 递归获取医院结构
+     *
+     * @param hospital    当前医院
+     * @param hospitalMap 医院集
+     */
+    public void getSonHospital(GetHospitalTreeDTO hospital, Map<Long, List<GetHospitalTreeDTO>> hospitalMap, List<Long> hospitals, List<Long> depts) {
+        //通过查询用户所在的医院集添加关联关系
+        if (hospitals.contains(hospital.getHospitalId())) {
+            hospital.setRelation(RelationEnum.Y.getName());
+        }
+        List<GetHospitalTreeDTO> hospitalTreeDTOS = hospitalMap.get(hospital.getHospitalId());
+        if (ListUtil.isNotEmpty(hospitalTreeDTOS)) {
+            hospital.setHospitalDTOS(hospitalTreeDTOS);
+            getHospitalDeptInfo(hospitalMap, hospitals, depts, hospitalTreeDTOS);
+        }
+    }
+
+    /**
+     * @param hospitalMap 医院结果级
+     * @param hospitals 查询用户所在医院集
+     * @param depts 查询用户所在科室集
+     * @param hospitalTreeDTOS  当前遍历医院集
+     * @Description
      * @Return void
      */
-    private void getUserRelation(GetUserDTO getUserDTO, List<GetHospitalDeptDTO> hospitalDepts, int hospitalType) {
-
-        //单家医院
-        if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == hospitalType) {
-            if (ListUtil.isNotEmpty(hospitalDepts)) {
-                Map<Long, List<GetHospitalDeptDTO>> hospitalDeptMap = EntityUtil.makeEntityListMap(hospitalDepts, "hospitalId");
-                hospitalDeptMap.keySet().stream().forEach(hospitalId -> {
-                    if (ListUtil.isEmpty(getUserDTO.getHospitalDTOS())) {
-                        getUserDTO.setHospitalDTOS(new ArrayList<>());
-                    }
-                    if (ListUtil.isNotEmpty(hospitalDeptMap.get(hospitalId))) {
-                        GetHospitalTreeDTO oneGetHospitalTreeDTO = new GetHospitalTreeDTO();
-                        BeanUtils.copyProperties(hospitalDeptMap.get(hospitalId).get(0), oneGetHospitalTreeDTO);
-                        hospitalDeptMap.get(hospitalId).stream().forEach(getHospitalDeptDTO -> {
-                            if (ListUtil.isEmpty(oneGetHospitalTreeDTO.getDepts())) {
-                                oneGetHospitalTreeDTO.setDepts(new ArrayList<>());
-                            }
-                            GetDeptTreeDTO oneGetDeptTreeDTO = new GetDeptTreeDTO();
-                            BeanUtils.copyProperties(getHospitalDeptDTO, oneGetDeptTreeDTO);
-                            oneGetHospitalTreeDTO.getDepts().add(oneGetDeptTreeDTO);
-                        });
-                        getUserDTO.getHospitalDTOS().add(oneGetHospitalTreeDTO);
-                    }
-                });
-            }
-            //虚拟医院
-        } else if (hospitalType >= 0) {
-            if (ListUtil.isNotEmpty(hospitalDepts)) {
-                Map<Long, List<GetHospitalDeptDTO>> hospitalDeptMap = EntityUtil.makeEntityListMap(hospitalDepts, "parentId");
-                hospitalDeptMap.keySet().stream().forEach(hospitalId -> {
-                    if (ListUtil.isEmpty(getUserDTO.getHospitalDTOS())) {
-                        getUserDTO.setHospitalDTOS(new ArrayList<>());
-                    }
-                    if (ListUtil.isNotEmpty(hospitalDeptMap.get(hospitalId))) {
-                        hospitalDeptMap.get(hospitalId).stream().forEach(getHospitalDeptDTO -> {
-                            GetHospitalTreeDTO oneGetHospitalTreeDTO = new GetHospitalTreeDTO();
-                            BeanUtils.copyProperties(getHospitalDeptDTO, oneGetHospitalTreeDTO);
-                            getUserDTO.getHospitalDTOS().add(oneGetHospitalTreeDTO);
-                        });
+    private void getHospitalDeptInfo(Map<Long, List<GetHospitalTreeDTO>> hospitalMap, List<Long> hospitals, List<Long> depts, List<GetHospitalTreeDTO> hospitalTreeDTOS) {
+
+        for (GetHospitalTreeDTO bean : hospitalTreeDTOS) {
+            //真实医院添加科室信息
+            if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == Integer.parseInt(bean.getType())) {
+                List<GetDeptTreeDTO> getDeptTreeDTOList = deptFacade.getBaseMapper().getDeptInfo(bean.getHospitalId());
+                //通过查询用户所在的科室集添加关联关系
+                getDeptTreeDTOList.stream().forEach(getDeptTreeDTO -> {
+                    if (depts.contains(getDeptTreeDTO.getDeptId())) {
+                        getDeptTreeDTO.setRelation(RelationEnum.Y.getName());
                     }
                 });
-                //转成树装结构
-                Map<Long, List<GetHospitalTreeDTO>> tempHospitalDeptMap = EntityUtil.makeEntityListMap(getUserDTO.getHospitalDTOS(), "parentId");
-                List<GetHospitalTreeDTO> HospitalTreeRes = tempHospitalDeptMap.get(1L);
-                for (GetHospitalTreeDTO bean : HospitalTreeRes) {
-                    getSonHospital(bean, tempHospitalDeptMap);
-                }
-                getUserDTO.setHospitalDTOS(HospitalTreeRes);
+                bean.setDepts(getDeptTreeDTOList);
             }
+            getSonHospital(bean, hospitalMap, hospitals, depts);
         }
-
     }
 
     /**
@@ -462,18 +412,20 @@ public class UserManagementFacade {
      *
      * @param hospital    当前医院
      * @param hospitalMap 医院集
-     * @return 菜单结构
+     * @return 
      */
-    public List<GetHospitalTreeDTO> getSonHospital(GetHospitalTreeDTO hospital, Map<Long, List<GetHospitalTreeDTO>> hospitalMap) {
-        List<GetHospitalTreeDTO> sonMenu = new ArrayList<>();
-        List<GetHospitalTreeDTO> menuList = hospitalMap.get(hospital.getHospitalId());
-        if (ListUtil.isNotEmpty(menuList)) {
-            hospital.setHospitalDTOS(menuList);
-            for (GetHospitalTreeDTO bean : menuList) {
+    public void getSonHospital(GetHospitalTreeDTO hospital, Map<Long, List<GetHospitalTreeDTO>> hospitalMap) {
+        List<GetHospitalTreeDTO> hospitals = hospitalMap.get(hospital.getHospitalId());
+        if (ListUtil.isNotEmpty(hospitals)) {
+            hospital.setHospitalDTOS(hospitals);
+            for (GetHospitalTreeDTO bean : hospitals) {
+                //真实医院添加科室信息
+                if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == Integer.parseInt(bean.getType())) {
+                    bean.setDepts(deptFacade.getBaseMapper().getDeptInfo(bean.getHospitalId()));
+                }
                 getSonHospital(bean, hospitalMap);
             }
         }
-        return sonMenu;
     }
 
     /**

+ 8 - 1
security-center/src/main/java/com/lantone/security/web/HospitalManagementController.java

@@ -3,8 +3,10 @@ package com.lantone.security.web;
 
 import com.lantone.common.api.CommonResult;
 import com.lantone.common.dto.GetHospitalByIdDTO;
+import com.lantone.common.dto.GetHospitalListInfoDTO;
 import com.lantone.common.dto.GetHospitalTreeDTO;
 import com.lantone.common.vo.AddHospitalVO;
+import com.lantone.common.vo.GetHospitalListInfoVO;
 import com.lantone.common.vo.UpdateHospitalVO;
 import com.lantone.security.facade.HospitalManagementFacade;
 import io.swagger.annotations.Api;
@@ -27,7 +29,7 @@ import java.util.Map;
  * 组织管理API
  */
 @RestController
-@Api(value = "组织管理API", tags = "HospitalManagementController")
+@Api(value = "组织管理API", tags = "组织管理API")
 @RequestMapping("/hospitalManage")
 public class HospitalManagementController {
     @Autowired
@@ -71,4 +73,9 @@ public class HospitalManagementController {
     public CommonResult<Map<String,Object>> getManagerBoxInfo(Long local) {
         return CommonResult.success(hospitalManagementFacade.getManagerBoxInfo(local));
     }
+    @ApiOperation(value = "组织管理列表页查询 [by:songxl]")
+    @PostMapping("/getHospitalListInfo")
+    public CommonResult<List<GetHospitalListInfoDTO>> getHospitalListInfo(@RequestBody GetHospitalListInfoVO getHospitalListInfoVO) {
+        return CommonResult.success(hospitalManagementFacade.getHospitalListInfo(getHospitalListInfoVO));
+    }
 }

+ 2 - 2
security-center/src/main/java/com/lantone/security/web/UserManagementController.java

@@ -95,8 +95,8 @@ public class UserManagementController {
 
     @ApiOperation(value = "获取登录用户的组织机构树 [by:songxl]")
     @PostMapping("/getHospitalTree")
-    public CommonResult<List<GetHospitalTreeDTO>> getLoginUserHospitalTree() {
-        return CommonResult.success(userManagementFacade.getLoginUserHospitalTree());
+    public CommonResult<List<GetHospitalTreeDTO>> getLoginUserHospitalTree(@RequestParam Long h) {
+        return CommonResult.success(userManagementFacade.getLoginUserHospitalTree(h));
     }
 
     @ApiOperation(value = "获取当前用户所在组织的用户列表 [by:songxl]")