|
@@ -10,7 +10,10 @@ import com.lantone.common.domain.UserDto;
|
|
import com.lantone.common.dto.GetDeptTreeDTO;
|
|
import com.lantone.common.dto.GetDeptTreeDTO;
|
|
import com.lantone.common.dto.GetHospitalTreeDTO;
|
|
import com.lantone.common.dto.GetHospitalTreeDTO;
|
|
import com.lantone.common.dto.GetUserDTO;
|
|
import com.lantone.common.dto.GetUserDTO;
|
|
|
|
+import com.lantone.common.dto.GetUserHospitalsDTO;
|
|
import com.lantone.common.dto.GetUserPageDTO;
|
|
import com.lantone.common.dto.GetUserPageDTO;
|
|
|
|
+import com.lantone.common.dto.SoftwareDTO;
|
|
|
|
+import com.lantone.common.dto.UserSoftwareHospitalDTO;
|
|
import com.lantone.common.enums.IsDeleteEnum;
|
|
import com.lantone.common.enums.IsDeleteEnum;
|
|
import com.lantone.common.enums.StatusEnum;
|
|
import com.lantone.common.enums.StatusEnum;
|
|
import com.lantone.common.exception.Asserts;
|
|
import com.lantone.common.exception.Asserts;
|
|
@@ -43,9 +46,13 @@ import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -152,48 +159,29 @@ public class UserManagementFacade {
|
|
*/
|
|
*/
|
|
private boolean saveUserHospital(AddHospitalTreeVO addHospitalTreeVO, Long userId, List<Long> roles) {
|
|
private boolean saveUserHospital(AddHospitalTreeVO addHospitalTreeVO, Long userId, List<Long> roles) {
|
|
|
|
|
|
- //1.获取组织类型
|
|
|
|
- //1.1单家医院
|
|
|
|
- if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == Integer.parseInt(addHospitalTreeVO.getType())) {
|
|
|
|
- //插入用户和医院的关系
|
|
|
|
- if (ListUtil.isNotEmpty(addHospitalTreeVO.getHospitals())) {
|
|
|
|
- addHospitalTreeVO.getHospitals().stream().forEach(hospitalId -> {
|
|
|
|
- HospitalUser hospitalUser = new HospitalUser();
|
|
|
|
- hospitalUser.setUserId(userId);
|
|
|
|
- hospitalUser.setHospitalId(hospitalId);
|
|
|
|
- hospitalUserFacade.save(hospitalUser);
|
|
|
|
- });
|
|
|
|
- //插入用户和科室的关系(没有科室信息默认为全院)
|
|
|
|
- if (ListUtil.isNotEmpty(addHospitalTreeVO.getDepts())) {
|
|
|
|
- addHospitalTreeVO.getDepts().stream().forEach(deptID -> {
|
|
|
|
- DeptUser userDept = new DeptUser();
|
|
|
|
- userDept.setDeptId(deptID);
|
|
|
|
- userDept.setUserId(userId);
|
|
|
|
- userDeptFacade.save(userDept);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- //插入用户和角色的关系
|
|
|
|
- return saveUserRole(userId, roles);
|
|
|
|
- } else {
|
|
|
|
- Asserts.fail("用户所属组织为空");
|
|
|
|
- }
|
|
|
|
- //非单家医院用户
|
|
|
|
- } else {
|
|
|
|
- //插入用户和医院的关系
|
|
|
|
- if (ListUtil.isNotEmpty(addHospitalTreeVO.getHospitals())) {
|
|
|
|
- addHospitalTreeVO.getHospitals().stream().forEach(hospitalId -> {
|
|
|
|
- HospitalUser hospitalUser = new HospitalUser();
|
|
|
|
- hospitalUser.setUserId(userId);
|
|
|
|
- hospitalUser.setHospitalId(hospitalId);
|
|
|
|
- hospitalUserFacade.save(hospitalUser);
|
|
|
|
- });
|
|
|
|
- //插入用户和角色的关系
|
|
|
|
- return saveUserRole(userId, roles);
|
|
|
|
- } else {
|
|
|
|
- Asserts.fail("用户所属组织为空");
|
|
|
|
- }
|
|
|
|
|
|
+ if(ListUtil.isEmpty(addHospitalTreeVO.getDepts())&&ListUtil.isEmpty(addHospitalTreeVO.getHospitals())){
|
|
|
|
+ Asserts.fail("用户关联的医院或科室都为空");
|
|
}
|
|
}
|
|
- return false;
|
|
|
|
|
|
+ //插入用户和科室的关系(没有科室信息默认为全院)
|
|
|
|
+ if (ListUtil.isNotEmpty(addHospitalTreeVO.getDepts())) {
|
|
|
|
+ addHospitalTreeVO.getDepts().stream().forEach(deptID -> {
|
|
|
|
+ DeptUser userDept = new DeptUser();
|
|
|
|
+ userDept.setDeptId(deptID);
|
|
|
|
+ userDept.setUserId(userId);
|
|
|
|
+ userDeptFacade.save(userDept);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ //插入用户和医院的关系
|
|
|
|
+ if (ListUtil.isNotEmpty(addHospitalTreeVO.getHospitals())) {
|
|
|
|
+ addHospitalTreeVO.getHospitals().stream().forEach(hospitalId -> {
|
|
|
|
+ HospitalUser hospitalUser = new HospitalUser();
|
|
|
|
+ hospitalUser.setUserId(userId);
|
|
|
|
+ hospitalUser.setHospitalId(hospitalId);
|
|
|
|
+ hospitalUserFacade.save(hospitalUser);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ //插入用户和角色的关系
|
|
|
|
+ return saveUserRole(userId, roles);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -344,7 +332,7 @@ public class UserManagementFacade {
|
|
//深度遍历拼装结果
|
|
//深度遍历拼装结果
|
|
List<GetHospitalTreeDTO> hospitalTree = hospitalMap.get(hospital.getParentId());
|
|
List<GetHospitalTreeDTO> hospitalTree = hospitalMap.get(hospital.getParentId());
|
|
getHospitalDeptInfo(hospitalMap, hospitals, depts, hospitalTree);
|
|
getHospitalDeptInfo(hospitalMap, hospitals, depts, hospitalTree);
|
|
- getUserDTO.setHospitalDTOS(hospitalTree);
|
|
|
|
|
|
+ getUserDTO.setHospitals(hospitalTree);
|
|
|
|
|
|
//4.获取用户的角色
|
|
//4.获取用户的角色
|
|
getUserDTO.setRoles(userRoleFacade.getBaseMapper().getUserRoles(userId));
|
|
getUserDTO.setRoles(userRoleFacade.getBaseMapper().getUserRoles(userId));
|
|
@@ -365,7 +353,7 @@ public class UserManagementFacade {
|
|
}
|
|
}
|
|
List<GetHospitalTreeDTO> hospitalTreeDTOS = hospitalMap.get(hospital.getHospitalId());
|
|
List<GetHospitalTreeDTO> hospitalTreeDTOS = hospitalMap.get(hospital.getHospitalId());
|
|
if (ListUtil.isNotEmpty(hospitalTreeDTOS)) {
|
|
if (ListUtil.isNotEmpty(hospitalTreeDTOS)) {
|
|
- hospital.setHospitalDTOS(hospitalTreeDTOS);
|
|
|
|
|
|
+ hospital.setChildren(hospitalTreeDTOS);
|
|
getHospitalDeptInfo(hospitalMap, hospitals, depts, hospitalTreeDTOS);
|
|
getHospitalDeptInfo(hospitalMap, hospitals, depts, hospitalTreeDTOS);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -395,7 +383,22 @@ public class UserManagementFacade {
|
|
getSonHospital(bean, hospitalMap, hospitals, depts);
|
|
getSonHospital(bean, hospitalMap, hospitals, depts);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 递归获取医院结构
|
|
|
|
+ *
|
|
|
|
+ * @param hospital 当前医院
|
|
|
|
+ * @param hospitalMap 医院集
|
|
|
|
+ * @return 空
|
|
|
|
+ */
|
|
|
|
+ public void getSonHospital(GetUserHospitalsDTO hospital, Map<Long, List<GetUserHospitalsDTO>> hospitalMap) {
|
|
|
|
+ List<GetUserHospitalsDTO> hospitals = hospitalMap.get(hospital.getHospitalId());
|
|
|
|
+ if (ListUtil.isNotEmpty(hospitals)) {
|
|
|
|
+ hospital.setChildren(hospitals);
|
|
|
|
+ for (GetUserHospitalsDTO bean : hospitals) {
|
|
|
|
+ getSonHospital(bean, hospitalMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 递归获取医院结构
|
|
* 递归获取医院结构
|
|
*
|
|
*
|
|
@@ -406,7 +409,7 @@ public class UserManagementFacade {
|
|
public void getSonHospital(GetHospitalTreeDTO hospital, Map<Long, List<GetHospitalTreeDTO>> hospitalMap) {
|
|
public void getSonHospital(GetHospitalTreeDTO hospital, Map<Long, List<GetHospitalTreeDTO>> hospitalMap) {
|
|
List<GetHospitalTreeDTO> hospitals = hospitalMap.get(hospital.getHospitalId());
|
|
List<GetHospitalTreeDTO> hospitals = hospitalMap.get(hospital.getHospitalId());
|
|
if (ListUtil.isNotEmpty(hospitals)) {
|
|
if (ListUtil.isNotEmpty(hospitals)) {
|
|
- hospital.setHospitalDTOS(hospitals);
|
|
|
|
|
|
+ hospital.setChildren(hospitals);
|
|
for (GetHospitalTreeDTO bean : hospitals) {
|
|
for (GetHospitalTreeDTO bean : hospitals) {
|
|
//真实医院添加科室信息
|
|
//真实医院添加科室信息
|
|
if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == Integer.parseInt(bean.getType())) {
|
|
if (HospitalTypeEnum.SINGLE_HOSPITAL.getKey() == Integer.parseInt(bean.getType())) {
|
|
@@ -429,4 +432,70 @@ public class UserManagementFacade {
|
|
getUserPageVO.setLocalUserID(SysUserUtils.getCurrentPrincipleId());
|
|
getUserPageVO.setLocalUserID(SysUserUtils.getCurrentPrincipleId());
|
|
return hospitalUserFacade.getBaseMapper().getUserPage(getUserPageVO);
|
|
return hospitalUserFacade.getBaseMapper().getUserPage(getUserPageVO);
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * @Description获取用户所属组织
|
|
|
|
+ * @param
|
|
|
|
+ * @Return java.util.List<com.lantone.common.dto.GetHospitalTreeDTO>
|
|
|
|
+ */
|
|
|
|
+ public Map<String,Object> getUserHospitals() {
|
|
|
|
+ Map<String,Object> out = new HashMap<>();
|
|
|
|
+ //但系统单家医院直接跳转
|
|
|
|
+ boolean jumpFlag = true;
|
|
|
|
+ //1.获取用户系统信息
|
|
|
|
+ List<SoftwareDTO> softwares = userFacade.getBaseMapper().getUserSoftwareByUId(SysUserUtils.getCurrentPrincipleId());
|
|
|
|
+ if(softwares.size()>1){
|
|
|
|
+ jumpFlag = false;
|
|
|
|
+ }
|
|
|
|
+ AtomicInteger count = new AtomicInteger();
|
|
|
|
+ List<UserSoftwareHospitalDTO> userSoftwareHospitals = new ArrayList<>();
|
|
|
|
+ if(ListUtil.isNotEmpty(softwares)){
|
|
|
|
+ softwares.stream().forEach(softwareDTO -> {
|
|
|
|
+ UserSoftwareHospitalDTO tempU = new UserSoftwareHospitalDTO();
|
|
|
|
+ BeanUtils.copyProperties(softwareDTO,tempU);
|
|
|
|
+ //获取该系统下的医院
|
|
|
|
+ List<GetUserHospitalsDTO> softwareHospitals = userFacade.getBaseMapper()
|
|
|
|
+ .getUserSoftwareHospitals(SysUserUtils.getCurrentPrincipleId(),softwareDTO.getId());
|
|
|
|
+ count.set(count.get() + softwareHospitals.size());
|
|
|
|
+ //转换成树状结构
|
|
|
|
+ Map<Long,List<GetUserHospitalsDTO>> softwareHospitalMap = EntityUtil.makeEntityListMap(softwareHospitals,"parentId");
|
|
|
|
+ tempU.setHospitals(transTreeData(softwareHospitalMap,softwareHospitals));
|
|
|
|
+ userSoftwareHospitals.add(tempU);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if(count.get()>1){
|
|
|
|
+ jumpFlag = false;
|
|
|
|
+ }
|
|
|
|
+ out.put("jump",jumpFlag);
|
|
|
|
+ out.put("software",userSoftwareHospitals);
|
|
|
|
+ return out;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * @Description将医院信息转换成树状结构
|
|
|
|
+ * @param softwareHospitalMap
|
|
|
|
+ * @param softwareHospitals
|
|
|
|
+ * @Return java.util.List<com.lantone.common.dto.GetUserHospitalsDTO>
|
|
|
|
+ */
|
|
|
|
+ private List<GetUserHospitalsDTO> transTreeData(Map<Long, List<GetUserHospitalsDTO>> softwareHospitalMap,List<GetUserHospitalsDTO> softwareHospitals) {
|
|
|
|
+ if(softwareHospitalMap==null)return null;
|
|
|
|
+ List<GetUserHospitalsDTO> out = new ArrayList<>();
|
|
|
|
+ Set<Long> tempParents = new HashSet<>();
|
|
|
|
+ Set<Long> parents = softwareHospitalMap.keySet();
|
|
|
|
+ parents.stream().forEach(id->{
|
|
|
|
+ softwareHospitals.stream().forEach(getUserHospitalsDTO -> {
|
|
|
|
+ if(getUserHospitalsDTO.getHospitalId().equals(id)){
|
|
|
|
+ tempParents.add(id);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ parents.stream().forEach(parentId->{
|
|
|
|
+ if(!tempParents.contains(parentId)){
|
|
|
|
+ List<GetUserHospitalsDTO> hospitalListInfos = softwareHospitalMap.get(parentId);
|
|
|
|
+ for(GetUserHospitalsDTO bean:hospitalListInfos){
|
|
|
|
+ getSonHospital(bean,softwareHospitalMap);
|
|
|
|
+ }
|
|
|
|
+ out.addAll(hospitalListInfos);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return out;
|
|
|
|
+ }
|
|
}
|
|
}
|