|
@@ -1,21 +1,43 @@
|
|
|
package com.lantone.security.facade;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.lantone.common.dto.RoleDTO;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.lantone.common.dto.GetRoleDTO;
|
|
|
+import com.lantone.common.dto.GetRolePageDTO;
|
|
|
+import com.lantone.common.dto.SoftwareDTO;
|
|
|
+import com.lantone.common.dto.SoftwareMenuRelationDTO;
|
|
|
+import com.lantone.common.dto.UserMenuResourceTreeDTO;
|
|
|
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.vo.RoleSoftwareMenuVo;
|
|
|
-import com.lantone.common.vo.RoleVO;
|
|
|
+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.Role;
|
|
|
+import com.lantone.dblayermbg.entity.RoleSoftwareMenu;
|
|
|
+import com.lantone.dblayermbg.entity.RoleSoftwareResource;
|
|
|
import com.lantone.dblayermbg.facade.RoleFacade;
|
|
|
-import com.lantone.security.enums.CRUDEnum;
|
|
|
+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.service.impl.RoleSoftwareMenuServiceImpl;
|
|
|
+import com.lantone.dblayermbg.service.impl.RoleSoftwareResourceServiceImpl;
|
|
|
import com.lantone.security.enums.IsDeleteEnum;
|
|
|
+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.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @ClassName: FuncManagementFacade
|
|
@@ -28,201 +50,287 @@ import java.util.List;
|
|
|
public class RoleManagementFacade {
|
|
|
@Autowired
|
|
|
private RoleFacade roleFacade;
|
|
|
+ @Autowired
|
|
|
+ private RoleSoftwareMenuFacade roleSoftwareMenuFacade;
|
|
|
+ @Autowired
|
|
|
+ private RoleSoftwareResourceFacade roleSoftwareResourceFacade;
|
|
|
+ @Autowired
|
|
|
+ private SoftwareMenuFacade softwareMenuFacade;
|
|
|
+ @Autowired
|
|
|
+ private SoftwareFacade softwareFacade;
|
|
|
|
|
|
- /**
|
|
|
- * @param roleSoftwareMenuVo
|
|
|
- * @Method inputParamCheck
|
|
|
- * @Author songxl
|
|
|
- * @Version 1.0
|
|
|
- * @Description入参校验
|
|
|
- * @Return void
|
|
|
- * @Date 2021/7/28
|
|
|
- */
|
|
|
- private void inputParamCheck(RoleSoftwareMenuVo roleSoftwareMenuVo) {
|
|
|
- if (roleSoftwareMenuVo == null) {
|
|
|
- Asserts.fail("入参为空");
|
|
|
- }
|
|
|
- if (ListUtil.isEmpty(roleSoftwareMenuVo.getRoles())) {
|
|
|
- Asserts.fail("角色列表为空");
|
|
|
- }
|
|
|
- if (roleSoftwareMenuVo.getSoftwareId() == null) {
|
|
|
- Asserts.fail("服务id为空");
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
- * @param roleVO
|
|
|
- * @Method inputParamCheck
|
|
|
- * @Author songxl
|
|
|
- * @Version 1.0
|
|
|
- * @Description入参校验
|
|
|
- * @Return void
|
|
|
- * @Date 2021/7/28
|
|
|
+ * @param roleId
|
|
|
+ * @Description删除角色
|
|
|
+ * @Return java.lang.Boolean
|
|
|
*/
|
|
|
- private void inputParamCheck(RoleVO roleVO) {
|
|
|
- if (roleVO == null) {
|
|
|
- Asserts.fail("入参为空");
|
|
|
- }
|
|
|
- if (roleVO.getOpeType() == 0) {
|
|
|
- Asserts.fail("操作码为空");
|
|
|
- }
|
|
|
- switch (roleVO.getOpeType()) {
|
|
|
- case 1:
|
|
|
- if (StringUtil.isEmpty(roleVO.getName())) {
|
|
|
- Asserts.fail("角色名称为空");
|
|
|
- }
|
|
|
- if (ListUtil.isEmpty(roleVO.getSoftwares())){
|
|
|
- Asserts.fail("角色开放系统至少要选择一个");
|
|
|
- }
|
|
|
- roleVO.getSoftwares().stream().forEach(sysSoftwareVO -> {
|
|
|
- if (ListUtil.isEmpty(sysSoftwareVO.getMenus())){
|
|
|
- Asserts.fail("角色开放系统对应的菜单列表为空");
|
|
|
- }
|
|
|
- });
|
|
|
- if(StringUtil.isEmpty(roleVO.getStatus())){
|
|
|
- Asserts.fail("角色启用禁用状态为空");
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- if (roleVO.getId() == null) {
|
|
|
- Asserts.fail("角色ID为空");
|
|
|
- }
|
|
|
- if (StringUtil.isEmpty(roleVO.getName())) {
|
|
|
- Asserts.fail("角色名称为空");
|
|
|
- }
|
|
|
- if (ListUtil.isEmpty(roleVO.getSoftwares())){
|
|
|
- Asserts.fail("角色开放系统至少要选择一个");
|
|
|
- }
|
|
|
- roleVO.getSoftwares().stream().forEach(sysSoftwareVO -> {
|
|
|
- if (ListUtil.isEmpty(sysSoftwareVO.getMenus())){
|
|
|
- Asserts.fail("角色开放系统对应的菜单列表为空");
|
|
|
- }
|
|
|
- });
|
|
|
- if(StringUtil.isEmpty(roleVO.getStatus())){
|
|
|
- Asserts.fail("角色启用禁用状态为空");
|
|
|
- }
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- if (roleVO.getId() == null) {
|
|
|
- Asserts.fail("角色ID为空");
|
|
|
- }
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- if (roleVO.getId() == null) {
|
|
|
- Asserts.fail("角色ID为空");
|
|
|
- }
|
|
|
- if (roleVO.getStatus() == null) {
|
|
|
- Asserts.fail("status为空");
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ public Boolean deleteRole(Long roleId) {
|
|
|
+ if (roleFacade.remove(new UpdateWrapper<Role>()
|
|
|
+ .eq("id", roleId)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
|
|
|
+ return deleteRoleSoftwareMenu(roleId);
|
|
|
+ } else {
|
|
|
+ Asserts.fail("角色删除失败");
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
- * @param roleVO
|
|
|
- * @Method CRUDOperation
|
|
|
- * @Author songxl
|
|
|
- * @Version 1.0
|
|
|
- * @Description角色CRUD方法
|
|
|
+ * @param roleId
|
|
|
+ * @param status
|
|
|
+ * @Description
|
|
|
* @Return java.lang.Boolean
|
|
|
- * @Date 2021/7/28
|
|
|
*/
|
|
|
- public Boolean CRUDOperation(RoleVO roleVO) {
|
|
|
-
|
|
|
- try {
|
|
|
- //1.入参校验
|
|
|
- inputParamCheck(roleVO);
|
|
|
- //2.执行操作
|
|
|
- if (CRUDEnum.ADD.getKey() == roleVO.getOpeType()) { //添加
|
|
|
- return addRole(roleVO);
|
|
|
- } else if (CRUDEnum.UPDATE.getKey() == roleVO.getOpeType()) { //修改
|
|
|
- return updateRole(roleVO);
|
|
|
- } else if (CRUDEnum.DELETE.getKey() == roleVO.getOpeType()) { //删除
|
|
|
- return deleteRole(roleVO);
|
|
|
- } else if (CRUDEnum.DISBALE.getKey() == roleVO.getOpeType()) { //启用禁用
|
|
|
- return disableRole(roleVO);
|
|
|
- } else {
|
|
|
- Asserts.fail("操作码错误");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- Asserts.fail(e.toString());
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- private Boolean deleteRole(RoleVO roleVO) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- private Boolean disableRole(RoleVO roleVO) {
|
|
|
- return false;
|
|
|
+ public Boolean disableRole(Long roleId, String status) {
|
|
|
+ return roleFacade.update(new UpdateWrapper<Role>()
|
|
|
+ .set("status", status)
|
|
|
+ .eq("id", roleId)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method addRole
|
|
|
- * @Author songxl
|
|
|
- * @Version 1.0
|
|
|
+ * @param addRoleVO
|
|
|
* @Description添加角色
|
|
|
- * @param roleVO
|
|
|
* @Return java.lang.Boolean
|
|
|
- * @Date 2021/7/30
|
|
|
*/
|
|
|
- private Boolean addRole(RoleVO roleVO) {
|
|
|
+ public Boolean addRole(AddRoleVO addRoleVO) {
|
|
|
//1.角色表插入角色信息
|
|
|
- roleVO.setCreator("0");//###当前登录人
|
|
|
- roleVO.setHospitalId(2l);//###当前登录人的组织
|
|
|
+ addRoleVO.setCreator("0");//###当前登录人
|
|
|
+ addRoleVO.setHospitalId(2l);//###当前登录人的组织
|
|
|
Role role = new Role();
|
|
|
- BeanUtils.copyProperties(roleVO,role);
|
|
|
+ BeanUtils.copyProperties(addRoleVO, role);
|
|
|
role.setGmtCreate(DateUtil.now());
|
|
|
- if(roleFacade.save(role)){
|
|
|
- Long roleId = roleFacade.list(new QueryWrapper<Role>()
|
|
|
- .eq("hospital_id",role.getHospitalId())
|
|
|
- .eq("name",role.getName())
|
|
|
+ if (roleFacade.save(role)) {
|
|
|
+ Long roleId = roleFacade.list(new QueryWrapper<Role>()
|
|
|
+ .eq("hospital_id", role.getHospitalId())
|
|
|
+ .eq("name", role.getName())
|
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey())).get(0).getId();
|
|
|
- //2.插入角色与系统、菜单的对应关系
|
|
|
- return saveRoleSoftwareMenu(roleVO,roleId);
|
|
|
- }else {
|
|
|
+ //2.插入角色与系统菜单的对应关系以及角色与功能权限的对应关系sys_role_software_menu,sys_role_software_resource
|
|
|
+ return saveRoleSoftwareMenu(addRoleVO.getSoftwares(), roleId);
|
|
|
+ } else {
|
|
|
Asserts.fail("角色插入失败");
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * @Description插入角色与系统、菜单的对应关系
|
|
|
- * @param roleVO
|
|
|
+ * @param softwares
|
|
|
* @param roleId
|
|
|
+ * @Description插入角色与系统、菜单的对应关系
|
|
|
* @Return void
|
|
|
*/
|
|
|
- private Boolean saveRoleSoftwareMenu(RoleVO roleVO, Long roleId) {
|
|
|
+ public Boolean saveRoleSoftwareMenu(List<AddRoleSoftwareVO> softwares, Long roleId) {
|
|
|
+ //插入sys_role_software_menu,sys_role_software_resource
|
|
|
+ AtomicReference<Boolean> out = new AtomicReference<>(false);
|
|
|
+ softwares.stream().forEach(addRoleSoftwareVO -> {
|
|
|
+ if (ListUtil.isNotEmpty(addRoleSoftwareVO.getSoftwareMenuIds())) {
|
|
|
+ //1.添加该角色对应的系统功能菜单关系sys_role_software_menu
|
|
|
+ List<RoleSoftwareMenu> roleSoftwareMenus = new ArrayList<>();
|
|
|
+ addRoleSoftwareVO.getSoftwareMenuIds().stream().forEach(softwareMenuId -> {
|
|
|
+ RoleSoftwareMenu roleSoftwareMenu = new RoleSoftwareMenu();
|
|
|
+ roleSoftwareMenu.setRoleId(roleId);
|
|
|
+ roleSoftwareMenu.setSoftwareMenuId(softwareMenuId);
|
|
|
+ roleSoftwareMenus.add(roleSoftwareMenu);
|
|
|
+ });
|
|
|
+ out.set(new RoleSoftwareMenuServiceImpl().saveBatch(roleSoftwareMenus));
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(addRoleSoftwareVO.getSoftwareResourceIds())) {
|
|
|
+ //2.添加该角色对应的系统功能权限关系sys_role_software_resource
|
|
|
+ List<RoleSoftwareResource> roleSoftwareResources = new ArrayList<>();
|
|
|
+ addRoleSoftwareVO.getSoftwareResourceIds().stream().forEach(softwareResourceId -> {
|
|
|
+ RoleSoftwareResource roleSoftwareResource = new RoleSoftwareResource();
|
|
|
+ roleSoftwareResource.setRoleId(roleId);
|
|
|
+ roleSoftwareResource.setSoftwareResourceId(softwareResourceId);
|
|
|
+ roleSoftwareResources.add(roleSoftwareResource);
|
|
|
+ });
|
|
|
+ out.set(new RoleSoftwareResourceServiceImpl().saveBatch(roleSoftwareResources));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return out.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param updateRoleVO
|
|
|
+ * @Description修改角色
|
|
|
+ * @Return java.lang.Boolean
|
|
|
+ */
|
|
|
+ public Boolean updateRole(UpdateRoleVO updateRoleVO) {
|
|
|
+ //1.删除原来角色系统菜单关联关系、角色系统功能权限关联关系
|
|
|
+ if (deleteRoleSoftwareMenu(updateRoleVO.getId())) {
|
|
|
+ //2.修改角色基本信息
|
|
|
+ if (roleFacade.update(new UpdateWrapper<Role>()
|
|
|
+ .set("name", updateRoleVO.getName())
|
|
|
+ .set("status", updateRoleVO.getStatus())
|
|
|
+ .set(StringUtil.isNotEmpty(updateRoleVO.getRemark()), "remark", updateRoleVO.getRemark())
|
|
|
+ .set(StringUtil.isNotEmpty(updateRoleVO.getOrderNo()), "order_no", updateRoleVO.getOrderNo())
|
|
|
+ .eq("id", updateRoleVO.getId())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
|
|
|
+
|
|
|
+ return saveRoleSoftwareMenu(updateRoleVO.getSoftwares(), updateRoleVO.getId());
|
|
|
+ } else {
|
|
|
+ Asserts.fail("角色基本信息修改失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Asserts.fail("原来角色与系统菜单关联关系删除失败");
|
|
|
+ }
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- private Boolean updateRole(RoleVO roleVO) {
|
|
|
+ /**
|
|
|
+ * @param id
|
|
|
+ * @Description删除原来角色系统菜单关联关系、角色系统功能权限关联关系
|
|
|
+ * @Return boolean
|
|
|
+ */
|
|
|
+ private boolean deleteRoleSoftwareMenu(Long id) {
|
|
|
+ if (roleSoftwareMenuFacade.remove(new UpdateWrapper<RoleSoftwareMenu>()
|
|
|
+ .eq("role_id", id)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
|
|
|
+ return roleSoftwareResourceFacade.remove(new UpdateWrapper<RoleSoftwareResource>()
|
|
|
+ .eq("role_id", id)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
+ }
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method getRolePage
|
|
|
- * @Author songxl
|
|
|
- * @Version 1.0
|
|
|
+ * @param getRolePageVO
|
|
|
* @Description获取角色列表
|
|
|
- * @param roleVO
|
|
|
* @Return java.util.List<com.lantone.common.dto.RoleDTO>
|
|
|
- * @Date 2021/7/30
|
|
|
*/
|
|
|
- public List<Role> getRolePage(RoleVO roleVO) {
|
|
|
+ public List<GetRolePageDTO> getRolePage(GetRolePageVO getRolePageVO) {
|
|
|
//1.获取当前登录人id和组织id
|
|
|
- roleVO.setCreator("0");//###当前登录人
|
|
|
- roleVO.setHospitalId(2l);//###当前登录人的组织
|
|
|
- return roleFacade.getBaseMapper().getRolePage(roleVO);
|
|
|
+ getRolePageVO.setCreator("0");//###当前登录人
|
|
|
+ getRolePageVO.setHospitalId(2l);//###当前登录人的组织
|
|
|
+ return roleFacade.getBaseMapper().getRolePage(getRolePageVO);
|
|
|
}
|
|
|
|
|
|
- public RoleDTO getRoleById(RoleVO roleVO) {
|
|
|
+ /**
|
|
|
+ * @param roleId
|
|
|
+ * @Description通过角色id获取角色详情
|
|
|
+ * @Return com.lantone.common.dto.GetRoleDTO
|
|
|
+ */
|
|
|
+ public GetRoleDTO getRoleById(Long roleId) {
|
|
|
+ GetRoleDTO getRoleDTO = new GetRoleDTO();
|
|
|
+ //1.获取角色基本信息
|
|
|
+ List<Role> roles = roleFacade.list(new QueryWrapper<Role>()
|
|
|
+ .eq("id", roleId)
|
|
|
+ .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());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ getRoleDTO.setLoginSoftwares(loginSoftwares);
|
|
|
+ getRoleDTO.setLoginUserMenuResourceTree(getUserMenuResourceTreeByRoles(loginRoles,roles.stream().map(Role::getId).collect(Collectors.toList())));
|
|
|
+ return getRoleDTO;
|
|
|
+ } else {
|
|
|
+ Asserts.fail("角色的基本信息不存在");
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归获取菜单结构
|
|
|
+ *
|
|
|
+ * @param menu 当前菜单
|
|
|
+ * @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());
|
|
|
+ if (ListUtil.isNotEmpty(menuList)) {
|
|
|
+ menu.setSonMenu(menuList);
|
|
|
+ for (SoftwareMenuRelationDTO bean : menuList) {
|
|
|
+ getSonMenu(bean, menuMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sonMenu;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归获取菜单结构
|
|
|
+ *
|
|
|
+ * @param menu 当前菜单
|
|
|
+ * @param menuMap 菜单集
|
|
|
+ * @return 菜单结构
|
|
|
+ */
|
|
|
+ public List<UserMenuResourceTreeDTO> getSonMenu(UserMenuResourceTreeDTO menu, Map<Long, List<UserMenuResourceTreeDTO>> menuMap) {
|
|
|
+ List<UserMenuResourceTreeDTO> sonMenu = new ArrayList<>();
|
|
|
+ List<UserMenuResourceTreeDTO> menuList = menuMap.get(menu.getMenuId());
|
|
|
+ if (ListUtil.isNotEmpty(menuList)) {
|
|
|
+ menu.setSonMenuResource(menuList);
|
|
|
+ for (UserMenuResourceTreeDTO bean : menuList) {
|
|
|
+ getSonMenu(bean, menuMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sonMenu;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description
|
|
|
+ * @param获取用户功能菜单树
|
|
|
+ * @Return java.util.Map<java.lang.Long, java.util.List < com.lantone.common.dto.UserMenuResourceTreeDTO>>
|
|
|
+ */
|
|
|
+ public Map<Long, List<UserMenuResourceTreeDTO>> getUserMenuResourceTree() {
|
|
|
+ //1.获取当前用户的角色列表
|
|
|
+ List<Long> roles = new ArrayList<>();//###获取当前用户id再获取该用户的角色
|
|
|
+ roles.add(1l);
|
|
|
+ return getUserMenuResourceTreeByRoles(roles);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param roles
|
|
|
+ * @Description通过角色列表获取用户功能菜单树
|
|
|
+ * @Return java.util.Map<java.lang.Long, java.util.List < com.lantone.common.dto.UserMenuResourceTreeDTO>>
|
|
|
+ */
|
|
|
+ private Map<Long, List<UserMenuResourceTreeDTO>> getUserMenuResourceTreeByRoles(List<Long> roles) {
|
|
|
+ List<UserMenuResourceTreeDTO> userMenuResourceTree = roleSoftwareMenuFacade.getBaseMapper().getUserMenuResourceTree(roles);
|
|
|
+ return getTree(userMenuResourceTree);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @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);
|
|
|
+ return getTree(userMenuResourceTree);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Long, List<UserMenuResourceTreeDTO>> getTree(List<UserMenuResourceTreeDTO> userMenuResourceTree) {
|
|
|
+ Map<Long, List<UserMenuResourceTreeDTO>> resUserMenuResourceTree = new HashMap<>();
|
|
|
+ //2.获取每个系统下的菜单、功能权限
|
|
|
+ Map<Long, List<UserMenuResourceTreeDTO>> userMenuResourceMap = EntityUtil
|
|
|
+ .makeEntityListMap(userMenuResourceTree, "softwareId");
|
|
|
+ //3.获取每个系统下的功能菜单树
|
|
|
+ if (!userMenuResourceMap.keySet().isEmpty()) {
|
|
|
+ userMenuResourceMap.keySet().stream().forEach(softwareId -> {
|
|
|
+ Map<Long, List<UserMenuResourceTreeDTO>> menuResourceMap = EntityUtil
|
|
|
+ .makeEntityListMap(userMenuResourceMap.get(softwareId), "parentId");
|
|
|
+ List<UserMenuResourceTreeDTO> menuRes = menuResourceMap.get(0L);
|
|
|
+ for (UserMenuResourceTreeDTO bean : menuRes) {
|
|
|
+ getSonMenu(bean, menuResourceMap);
|
|
|
+ }
|
|
|
+ resUserMenuResourceTree.put(softwareId, menuRes);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return resUserMenuResourceTree;
|
|
|
+ }
|
|
|
}
|