|
@@ -1,43 +1,56 @@
|
|
|
package com.lantone.security.facade;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.lantone.common.dto.GetCreateRoleDTO;
|
|
|
+import com.lantone.common.dto.GetDictionaryInfoByTypeDTO;
|
|
|
import com.lantone.common.dto.GetRoleDTO;
|
|
|
import com.lantone.common.dto.GetRolePageDTO;
|
|
|
+import com.lantone.common.dto.GetUserShowTreeDTO;
|
|
|
import com.lantone.common.dto.SoftwareDTO;
|
|
|
import com.lantone.common.dto.SoftwareMenuRelationDTO;
|
|
|
import com.lantone.common.dto.UserMenuResourceTreeDTO;
|
|
|
+import com.lantone.common.dto.UserRoleDTO;
|
|
|
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.util.StringUtil;
|
|
|
+import com.lantone.common.util.SysUserUtils;
|
|
|
import com.lantone.common.vo.AddRoleSoftwareVO;
|
|
|
import com.lantone.common.vo.AddRoleVO;
|
|
|
import com.lantone.common.vo.GetRolePageVO;
|
|
|
import com.lantone.common.vo.UpdateRoleVO;
|
|
|
+import com.lantone.dblayermbg.entity.Hospital;
|
|
|
import com.lantone.dblayermbg.entity.Role;
|
|
|
import com.lantone.dblayermbg.entity.RoleSoftwareMenu;
|
|
|
import com.lantone.dblayermbg.entity.RoleSoftwareResource;
|
|
|
+import com.lantone.dblayermbg.entity.UserRole;
|
|
|
+import com.lantone.dblayermbg.facade.DictionaryInfoFacade;
|
|
|
+import com.lantone.dblayermbg.facade.HospitalFacade;
|
|
|
import com.lantone.dblayermbg.facade.RoleFacade;
|
|
|
import com.lantone.dblayermbg.facade.RoleSoftwareMenuFacade;
|
|
|
import com.lantone.dblayermbg.facade.RoleSoftwareResourceFacade;
|
|
|
import com.lantone.dblayermbg.facade.SoftwareFacade;
|
|
|
-import com.lantone.dblayermbg.facade.SoftwareMenuFacade;
|
|
|
+import com.lantone.dblayermbg.facade.UserRoleFacade;
|
|
|
import com.lantone.dblayermbg.service.impl.RoleSoftwareMenuServiceImpl;
|
|
|
import com.lantone.dblayermbg.service.impl.RoleSoftwareResourceServiceImpl;
|
|
|
import com.lantone.common.enums.IsDeleteEnum;
|
|
|
+import com.lantone.security.enums.DictionaryEnum;
|
|
|
import com.lantone.security.enums.RelationEnum;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -45,21 +58,24 @@ import java.util.stream.Collectors;
|
|
|
* @ClassName: FuncManagementFacade
|
|
|
* @Description: 功能管理API
|
|
|
* @Author songxl
|
|
|
- * @Date 2021/7/28
|
|
|
- * @Version 1.0
|
|
|
*/
|
|
|
@Component
|
|
|
public class RoleManagementFacade {
|
|
|
@Autowired
|
|
|
private RoleFacade roleFacade;
|
|
|
@Autowired
|
|
|
+ private UserRoleFacade userRoleFacade;
|
|
|
+ @Autowired
|
|
|
private RoleSoftwareMenuFacade roleSoftwareMenuFacade;
|
|
|
@Autowired
|
|
|
private RoleSoftwareResourceFacade roleSoftwareResourceFacade;
|
|
|
@Autowired
|
|
|
- private SoftwareMenuFacade softwareMenuFacade;
|
|
|
- @Autowired
|
|
|
private SoftwareFacade softwareFacade;
|
|
|
+ @Autowired
|
|
|
+ private HospitalFacade hospitalFacade;
|
|
|
+ @Autowired
|
|
|
+ private DictionaryInfoFacade dictionaryInfoFacade;
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -98,8 +114,10 @@ public class RoleManagementFacade {
|
|
|
*/
|
|
|
public Boolean addRole(AddRoleVO addRoleVO) {
|
|
|
//1.角色表插入角色信息
|
|
|
- addRoleVO.setCreator("0");//###当前登录人
|
|
|
- addRoleVO.setHospitalId(2l);//###当前登录人的组织
|
|
|
+ addRoleVO.setCreator(SysUserUtils.getCurrentPrincipleId());
|
|
|
+ if(addRoleVO.getHospitalId()==null){
|
|
|
+ addRoleVO.setHospitalId(SysUserUtils.getCurrentHospitalId());
|
|
|
+ }
|
|
|
Role role = new Role();
|
|
|
BeanUtils.copyProperties(addRoleVO, role);
|
|
|
role.setGmtCreate(DateUtil.now());
|
|
@@ -136,7 +154,9 @@ public class RoleManagementFacade {
|
|
|
if (ListUtil.isNotEmpty(addRoleSoftwareVO.getSoftwareResourceIds())) {
|
|
|
//2.添加该角色对应的系统功能权限关系sys_role_software_resource
|
|
|
List<RoleSoftwareResource> roleSoftwareResources = new ArrayList<>();
|
|
|
- addRoleSoftwareVO.getSoftwareResourceIds().stream().forEach(softwareResourceId -> {
|
|
|
+ //资源去重
|
|
|
+ Set<Long> softwareResourceIds = new HashSet(addRoleSoftwareVO.getSoftwareResourceIds());
|
|
|
+ softwareResourceIds.stream().forEach(softwareResourceId -> {
|
|
|
RoleSoftwareResource roleSoftwareResource = new RoleSoftwareResource();
|
|
|
roleSoftwareResource.setRoleId(roleId);
|
|
|
roleSoftwareResource.setSoftwareResourceId(softwareResourceId);
|
|
@@ -198,8 +218,8 @@ public class RoleManagementFacade {
|
|
|
*/
|
|
|
public IPage<GetRolePageDTO> getRolePage(GetRolePageVO getRolePageVO) {
|
|
|
//1.获取当前登录人id和组织id
|
|
|
- getRolePageVO.setCreator("0");//###当前登录人
|
|
|
- getRolePageVO.setHospitalId(2l);//###当前登录人的组织
|
|
|
+ getRolePageVO.setCreator(SysUserUtils.getCurrentPrincipleId());
|
|
|
+ getRolePageVO.setHospitalId(SysUserUtils.getCurrentHospitalId());
|
|
|
return roleFacade.getBaseMapper().getRolePage(getRolePageVO);
|
|
|
}
|
|
|
|
|
@@ -216,25 +236,30 @@ public class RoleManagementFacade {
|
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
if (ListUtil.isNotEmpty(roles)) {
|
|
|
BeanUtils.copyProperties(roles.get(0), getRoleDTO);
|
|
|
- //2.获取当前登录用户的功能菜单树
|
|
|
- //获取当前用户的角色列表
|
|
|
- List<Long> loginRoles = new ArrayList<>();//###获取当前用户id再获取该用户的角色
|
|
|
- loginRoles.add(1l);
|
|
|
- //获取用户服务
|
|
|
- List<SoftwareDTO> loginSoftwares = softwareFacade.getBaseMapper().getUserSoftware(loginRoles);
|
|
|
- List<SoftwareDTO> hasSoftwares = softwareFacade.getBaseMapper().getUserSoftware(roles.stream().map(Role::getId).collect(Collectors.toList()));
|
|
|
- loginSoftwares.stream().forEach(softwareDTO -> {
|
|
|
- hasSoftwares.stream().forEach(hasSoftwareDto->{
|
|
|
- if(softwareDTO.getId().equals(hasSoftwareDto.getId())){
|
|
|
- softwareDTO.setRelation(RelationEnum.Y.getName());
|
|
|
- }else {
|
|
|
- softwareDTO.setRelation(RelationEnum.N.getName());
|
|
|
- }
|
|
|
+ //2.获取当前登录用户(管理员)的功能菜单树
|
|
|
+ //获取管理员的角色列表
|
|
|
+ List<Long> loginRoles = userRoleFacade.getBaseMapper().getUserRoles(SysUserUtils.getCurrentPrincipleId())
|
|
|
+ .stream().map(UserRoleDTO::getRoleId).collect(Collectors.toList());
|
|
|
+ if(ListUtil.isNotEmpty(loginRoles)){
|
|
|
+ //获取用户服务
|
|
|
+ List<SoftwareDTO> loginSoftwares = softwareFacade.getBaseMapper().getUserSoftware(loginRoles);
|
|
|
+ List<SoftwareDTO> hasSoftwares = softwareFacade.getBaseMapper().getUserSoftware(roles.stream().map(Role::getId).collect(Collectors.toList()));
|
|
|
+ loginSoftwares.stream().forEach(softwareDTO -> {
|
|
|
+ hasSoftwares.stream().forEach(hasSoftwareDto -> {
|
|
|
+ if (softwareDTO.getId().equals(hasSoftwareDto.getId())) {
|
|
|
+ softwareDTO.setRelation(RelationEnum.Y.getName());
|
|
|
+ } else {
|
|
|
+ softwareDTO.setRelation(RelationEnum.N.getName());
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
- getRoleDTO.setLoginSoftwares(loginSoftwares);
|
|
|
- getRoleDTO.setLoginUserMenuResourceTree(getUserMenuResourceTreeByRoles(loginRoles,roles.stream().map(Role::getId).collect(Collectors.toList())));
|
|
|
- return getRoleDTO;
|
|
|
+ getRoleDTO.setLoginSoftwares(loginSoftwares);
|
|
|
+ getRoleDTO.setLoginUserMenuResourceTree(getUserMenuResourceTreeByRoles(loginRoles, roles.stream().map(Role::getId).collect(Collectors.toList())));
|
|
|
+ return getRoleDTO;
|
|
|
+ }else {
|
|
|
+ Asserts.fail("该登录用户无角色信息");
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
Asserts.fail("角色的基本信息不存在");
|
|
|
}
|
|
@@ -248,12 +273,12 @@ public class RoleManagementFacade {
|
|
|
* @param menuMap 菜单集
|
|
|
* @return 菜单结构
|
|
|
*/
|
|
|
- public List<SoftwareMenuRelationDTO> getSonMenu(SoftwareMenuRelationDTO menu, Map<Long, List<SoftwareMenuRelationDTO>> menuMap) {
|
|
|
- List<SoftwareMenuRelationDTO> sonMenu = new ArrayList<>();
|
|
|
- List<SoftwareMenuRelationDTO> menuList = menuMap.get(menu.getMenuId());
|
|
|
+ public List<GetUserShowTreeDTO> getSonMenu(GetUserShowTreeDTO menu, Map<Long, List<GetUserShowTreeDTO>> menuMap) {
|
|
|
+ List<GetUserShowTreeDTO> sonMenu = new ArrayList<>();
|
|
|
+ List<GetUserShowTreeDTO> menuList = menuMap.get(menu.getMenuId());
|
|
|
if (ListUtil.isNotEmpty(menuList)) {
|
|
|
menu.setSonMenu(menuList);
|
|
|
- for (SoftwareMenuRelationDTO bean : menuList) {
|
|
|
+ for (GetUserShowTreeDTO bean : menuList) {
|
|
|
getSonMenu(bean, menuMap);
|
|
|
}
|
|
|
}
|
|
@@ -286,9 +311,14 @@ public class RoleManagementFacade {
|
|
|
*/
|
|
|
public Map<Long, List<UserMenuResourceTreeDTO>> getUserMenuResourceTree() {
|
|
|
//1.获取当前用户的角色列表
|
|
|
- List<Long> roles = new ArrayList<>();//###获取当前用户id再获取该用户的角色
|
|
|
- roles.add(1l);
|
|
|
- return getUserMenuResourceTreeByRoles(roles);
|
|
|
+ List<Long> roles = userRoleFacade.getBaseMapper().getUserRoles(SysUserUtils.getCurrentPrincipleId())
|
|
|
+ .stream().map(UserRoleDTO::getRoleId).collect(Collectors.toList());
|
|
|
+ if(ListUtil.isNotEmpty(roles)){
|
|
|
+ return getUserMenuResourceTreeByRoles(roles);
|
|
|
+ }else {
|
|
|
+ Asserts.fail("当前登录用户无角色信息");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -302,13 +332,13 @@ public class RoleManagementFacade {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param loginRoles 当前登录用户的角色列表
|
|
|
+ * @param loginRoles 当前登录用户的角色列表
|
|
|
* @param selectRoles 要查询用户的角色列表
|
|
|
* @Description通过角色列表获取用户功能菜单树
|
|
|
* @Return java.util.Map<java.lang.Long, java.util.List < com.lantone.common.dto.UserMenuResourceTreeDTO>>
|
|
|
*/
|
|
|
- private Map<Long, List<UserMenuResourceTreeDTO>> getUserMenuResourceTreeByRoles(List<Long> loginRoles,List<Long> selectRoles) {
|
|
|
- List<UserMenuResourceTreeDTO> userMenuResourceTree = roleSoftwareMenuFacade.getBaseMapper().getMenuResourceRelation(loginRoles,selectRoles);
|
|
|
+ private Map<Long, List<UserMenuResourceTreeDTO>> getUserMenuResourceTreeByRoles(List<Long> loginRoles, List<Long> selectRoles) {
|
|
|
+ List<UserMenuResourceTreeDTO> userMenuResourceTree = roleSoftwareMenuFacade.getBaseMapper().getMenuResourceRelation(loginRoles, selectRoles);
|
|
|
return getTree(userMenuResourceTree);
|
|
|
}
|
|
|
|
|
@@ -332,7 +362,68 @@ public class RoleManagementFacade {
|
|
|
return resUserMenuResourceTree;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param
|
|
|
+ * @Description获取当前登录用户管理的角色列表
|
|
|
+ * @Return java.util.List<com.lantone.common.dto.GetCreateRoleDTO>
|
|
|
+ */
|
|
|
public List<GetCreateRoleDTO> getCreateRoles() {
|
|
|
- return roleFacade.getBaseMapper().getCreateRoles(1l);
|
|
|
+
|
|
|
+ return roleFacade.getBaseMapper().getCreateRoles(SysUserUtils.getCurrentHospitalId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param
|
|
|
+ * @Description获取当前登录用户的显示的菜单列表
|
|
|
+ * @Return java.util.Map<java.lang.Long, java.util.List < com.lantone.common.dto.GetUserShowTreeDTO>>
|
|
|
+ */
|
|
|
+ public Map<Long, List<GetUserShowTreeDTO>> getUserShowMemuTree() {
|
|
|
+ AtomicReference<List> notShowSoftwareMenuIds = new AtomicReference<>();
|
|
|
+ //1.1获取当前用户的角色列表
|
|
|
+ List<Role> roles = roleFacade.list(new QueryWrapper<Role>().
|
|
|
+ in("id", userRoleFacade.list(new QueryWrapper<UserRole>()
|
|
|
+ .eq("user_id", SysUserUtils.getCurrentPrincipleId())).stream().map(UserRole::getRoleId).collect(Collectors.toList())));
|
|
|
+ //1.2判断该用户是否是管理用户
|
|
|
+ if(ListUtil.isNotEmpty(roles.stream().filter(role -> "ManagementRole".equals(role.getRemark())).collect(Collectors.toList()))){
|
|
|
+ Hospital hospital = hospitalFacade.getById(SysUserUtils.getCurrentHospitalId());
|
|
|
+ if (hospital != null) {
|
|
|
+ //2.获取字典禁用菜单配置
|
|
|
+ List<GetDictionaryInfoByTypeDTO> notShowMenus = dictionaryInfoFacade.getBaseMapper()
|
|
|
+ .getDictionaryInfoByType(DictionaryEnum.NOT_SHOW_MENU.getKey());
|
|
|
+ notShowMenus.stream().forEach(getDictionaryInfoByTypeDTO -> {
|
|
|
+ if(hospital.getType().equals(getDictionaryInfoByTypeDTO.getName())){
|
|
|
+ notShowSoftwareMenuIds.set(Arrays.asList(getDictionaryInfoByTypeDTO.getVal().split(",")));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<GetUserShowTreeDTO> getUserShowTreeDTOS = roleSoftwareMenuFacade.getBaseMapper()
|
|
|
+ .getUserShowMemuTree(roles.stream().map(Role::getId).collect(Collectors.toList()),notShowSoftwareMenuIds.get());
|
|
|
+ //菜单转成树状结构
|
|
|
+ if(ListUtil.isNotEmpty(getUserShowTreeDTOS)){
|
|
|
+ return getShowTree(getUserShowTreeDTOS);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Map<Long, List<GetUserShowTreeDTO>> getShowTree(List<GetUserShowTreeDTO> userMenuResourceTree) {
|
|
|
+ Map<Long, List<GetUserShowTreeDTO>> resUserMenuResourceTree = new HashMap<>();
|
|
|
+ //2.获取每个系统下的菜单、功能权限
|
|
|
+ Map<Long, List<GetUserShowTreeDTO>> userMenuResourceMap = EntityUtil
|
|
|
+ .makeEntityListMap(userMenuResourceTree, "softwareId");
|
|
|
+ //3.获取每个系统下的功能菜单树
|
|
|
+ if (!userMenuResourceMap.keySet().isEmpty()) {
|
|
|
+ userMenuResourceMap.keySet().stream().forEach(softwareId -> {
|
|
|
+ Map<Long, List<GetUserShowTreeDTO>> menuResourceMap = EntityUtil
|
|
|
+ .makeEntityListMap(userMenuResourceMap.get(softwareId), "parentId");
|
|
|
+ List<GetUserShowTreeDTO> menuRes = menuResourceMap.get(0L);
|
|
|
+ for (GetUserShowTreeDTO bean : menuRes) {
|
|
|
+ getSonMenu(bean, menuResourceMap);
|
|
|
+ }
|
|
|
+ resUserMenuResourceTree.put(softwareId, menuRes);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return resUserMenuResourceTree;
|
|
|
}
|
|
|
}
|