|
@@ -107,11 +107,19 @@ public class RoleManagementFacade {
|
|
|
* @Return java.lang.Boolean
|
|
|
*/
|
|
|
public Boolean deleteRole(Long roleId) {
|
|
|
- if (roleFacade.remove(new UpdateWrapper<Role>()
|
|
|
+ if (roleFacade.update(new UpdateWrapper<Role>()
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
.eq("id", roleId)
|
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey()))) {
|
|
|
- boolean flag = deleteRoleSoftwareMenu(roleId);
|
|
|
- return flag;
|
|
|
+ if (roleSoftwareMenuFacade.update(new UpdateWrapper<RoleSoftwareMenu>()
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
+ .eq("role_id", roleId)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
|
|
|
+ return roleSoftwareResourceFacade.update(new UpdateWrapper<RoleSoftwareResource>()
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
+ .eq("role_id", roleId)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
+ }
|
|
|
} else {
|
|
|
Asserts.fail("角色删除失败");
|
|
|
}
|
|
@@ -138,16 +146,16 @@ public class RoleManagementFacade {
|
|
|
*/
|
|
|
public Boolean addRole(AddRoleVO addRoleVO) {
|
|
|
//校验
|
|
|
- checkRole(addRoleVO.getName(),addRoleVO.getSoftwares());
|
|
|
+ checkRole(null,addRoleVO.getName(), addRoleVO.getSoftwares());
|
|
|
|
|
|
//1.角色表插入角色信息
|
|
|
addRoleVO.setCreator(SysUserUtils.getCurrentPrincipleId());
|
|
|
- if(addRoleVO.getHospitalId()==null){
|
|
|
+ if (addRoleVO.getHospitalId() == null) {
|
|
|
addRoleVO.setHospitalId(SysUserUtils.getCurrentHospitalId());
|
|
|
}
|
|
|
Role role = new Role();
|
|
|
BeanUtils.copyProperties(addRoleVO, role);
|
|
|
- role.setCreator(SysUserUtils.getCurrentPrincipleId()+"");
|
|
|
+ role.setCreator(SysUserUtils.getCurrentPrincipleId() + "");
|
|
|
role.setGmtCreate(DateUtil.now());
|
|
|
if (roleFacade.save(role)) {
|
|
|
//2.插入角色与系统菜单的对应关系以及角色与功能权限的对应关系sys_role_software_menu,sys_role_software_resource
|
|
@@ -159,54 +167,66 @@ public class RoleManagementFacade {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Description角色新增修改校验
|
|
|
* @param name
|
|
|
* @param softwares
|
|
|
+ * @Description角色新增修改校验
|
|
|
* @Return void
|
|
|
*/
|
|
|
- private void checkRole(String name, List<AddRoleSoftwareVO> softwares) {
|
|
|
- if(roleFacade.list(new QueryWrapper<Role>()
|
|
|
- .eq("hospital_id",SysUserUtils.getCurrentHospitalId())
|
|
|
- .eq("name",name)
|
|
|
- .eq("is_deleted",IsDeleteEnum.N.getKey())).size()>0){
|
|
|
- Asserts.fail("该角色已存在请重新输入");
|
|
|
+ private void checkRole(Long id, String name, List<AddRoleSoftwareVO> softwares) {
|
|
|
+ List<Role> roles = roleFacade.list(new QueryWrapper<Role>()
|
|
|
+ .eq("hospital_id", SysUserUtils.getCurrentHospitalId())
|
|
|
+ .eq("name", name)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
+ if (id == null) {
|
|
|
+ if (roles.size() > 0) {
|
|
|
+ Asserts.fail("该角色已存在请重新输入");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (ListUtil.isNotEmpty(roles)) {
|
|
|
+ roles.stream().forEach(role -> {
|
|
|
+ if (id != role.getId()) {
|
|
|
+ Asserts.fail("该角色已存在请重新输入");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
- if(ListUtil.isNotEmpty(softwares)){
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(softwares)) {
|
|
|
softwares.stream().forEach(addRoleSoftwareVO -> {
|
|
|
//移除菜单中的系统信息
|
|
|
addRoleSoftwareVO.getSoftwareMenuIds().remove(addRoleSoftwareVO.getId());
|
|
|
//获取菜单比对插入的功能菜单都能正常使用
|
|
|
List<SoftwareMenu> softwareMenus = softwareMenuFacade.list(new QueryWrapper<SoftwareMenu>()
|
|
|
.select("menu_id")
|
|
|
- .eq("is_deleted",IsDeleteEnum.N.getKey())
|
|
|
- .in("id",addRoleSoftwareVO.getSoftwareMenuIds()));
|
|
|
- if(ListUtil.isEmpty(softwareMenus)){
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("id", addRoleSoftwareVO.getSoftwareMenuIds()));
|
|
|
+ if (ListUtil.isEmpty(softwareMenus)) {
|
|
|
Asserts.fail("该功能菜单不存在,刷新后重新添加~");
|
|
|
}
|
|
|
- if(ListUtil.isNotEmpty(addRoleSoftwareVO.getSoftwareMenuIds())){
|
|
|
- if(addRoleSoftwareVO.getSoftwareMenuIds().size()!= menuFacade.count(new QueryWrapper<Menu>()
|
|
|
- .eq("status", StatusEnum.Enable.getKey())
|
|
|
- .eq("is_deleted",IsDeleteEnum.N.getKey())
|
|
|
- .in("id",softwareMenus.stream().map(SoftwareMenu::getMenuId).collect(Collectors.toList())))){
|
|
|
- Asserts.fail("该角色要绑定的功能菜单已更新请刷新重试~");
|
|
|
- }
|
|
|
- }
|
|
|
+ if (ListUtil.isNotEmpty(addRoleSoftwareVO.getSoftwareMenuIds())) {
|
|
|
+ if (addRoleSoftwareVO.getSoftwareMenuIds().size() != menuFacade.count(new QueryWrapper<Menu>()
|
|
|
+ .eq("status", StatusEnum.Enable.getKey())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("id", softwareMenus.stream().map(SoftwareMenu::getMenuId).collect(Collectors.toList())))) {
|
|
|
+ Asserts.fail("该角色要绑定的功能菜单已更新请刷新重试~");
|
|
|
+ }
|
|
|
+ }
|
|
|
//功能权限校验
|
|
|
//获取菜单比对插入的功能菜单都能正常使用
|
|
|
- if(ListUtil.isNotEmpty(addRoleSoftwareVO.getSoftwareResourceIds())){
|
|
|
+ if (ListUtil.isNotEmpty(addRoleSoftwareVO.getSoftwareResourceIds())) {
|
|
|
//去重 菜单对应的功能权限可能是一个
|
|
|
List<SoftwareResource> softwareResources = softwareResourceFacade.list(new QueryWrapper<SoftwareResource>()
|
|
|
.select("resource_id")
|
|
|
- .eq("is_deleted",IsDeleteEnum.N.getKey())
|
|
|
- .in("id",addRoleSoftwareVO.getSoftwareResourceIds()));
|
|
|
- if(ListUtil.isEmpty(softwareResources)){
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("id", addRoleSoftwareVO.getSoftwareResourceIds()));
|
|
|
+ if (ListUtil.isEmpty(softwareResources)) {
|
|
|
Asserts.fail("该功能菜单不存在,刷新后重新添加~");
|
|
|
}
|
|
|
Set resourceSet = new HashSet(addRoleSoftwareVO.getSoftwareResourceIds());
|
|
|
- if(resourceSet.size()!= resourceFacade.count(new QueryWrapper<Resource>()
|
|
|
+ if (resourceSet.size() != resourceFacade.count(new QueryWrapper<Resource>()
|
|
|
.eq("status", StatusEnum.Enable.getKey())
|
|
|
- .eq("is_deleted",IsDeleteEnum.N.getKey())
|
|
|
- .in("id",softwareResources.stream().map(SoftwareResource::getResourceId).collect(Collectors.toList())))){
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("id", softwareResources.stream().map(SoftwareResource::getResourceId).collect(Collectors.toList())))) {
|
|
|
Asserts.fail("该角色要绑定的功能菜单已更新请刷新重试~");
|
|
|
}
|
|
|
}
|
|
@@ -258,6 +278,8 @@ public class RoleManagementFacade {
|
|
|
* @Return java.lang.Boolean
|
|
|
*/
|
|
|
public Boolean updateRole(UpdateRoleVO updateRoleVO) {
|
|
|
+ //校验
|
|
|
+ checkRole(updateRoleVO.getId(), updateRoleVO.getName(), updateRoleVO.getSoftwares());
|
|
|
//1.删除原来角色系统菜单关联关系、角色系统功能权限关联关系
|
|
|
if (deleteRoleSoftwareMenu(updateRoleVO.getId())) {
|
|
|
//2.修改角色基本信息
|
|
@@ -309,10 +331,11 @@ public class RoleManagementFacade {
|
|
|
|
|
|
/**
|
|
|
* @param roleId
|
|
|
+ * @param type 区分组织管理添加角色、普通添加角色的功能菜单不同
|
|
|
* @Description通过角色id获取角色详情
|
|
|
* @Return com.lantone.common.dto.GetRoleDTO
|
|
|
*/
|
|
|
- public GetRoleDTO getRoleById(Long roleId,String type) {
|
|
|
+ public GetRoleDTO getRoleById(Long roleId, String type) {
|
|
|
GetRoleDTO getRoleDTO = new GetRoleDTO();
|
|
|
//1.获取角色基本信息
|
|
|
List<Role> roles = roleFacade.list(new QueryWrapper<Role>()
|
|
@@ -324,12 +347,12 @@ public class RoleManagementFacade {
|
|
|
//获取管理员的角色列表
|
|
|
List<Long> loginRoles = userRoleFacade.getBaseMapper().getUserRoles(SysUserUtils.getCurrentPrincipleId())
|
|
|
.stream().map(UserRoleDTO::getRoleId).collect(Collectors.toList());
|
|
|
- if(ListUtil.isNotEmpty(loginRoles)){
|
|
|
- List<UserMenuResourceTreeDTO> userMenuResourceTreeDTOS = getUserMenuResourceTreeByRoles(loginRoles, roles.stream().map(Role::getId).collect(Collectors.toList()),type);
|
|
|
+ if (ListUtil.isNotEmpty(loginRoles)) {
|
|
|
+ List<UserMenuResourceTreeDTO> userMenuResourceTreeDTOS = getUserMenuResourceTreeByRoles(loginRoles, roles.stream().map(Role::getId).collect(Collectors.toList()), type);
|
|
|
//获取用户服务
|
|
|
List<SoftwareDTO> loginSoftwares = softwareFacade.getBaseMapper().getUserSoftware(loginRoles);
|
|
|
List<Long> hasSoftwareIds = softwareFacade.getBaseMapper().getUserSoftware(roles.stream().map(Role::getId).collect(Collectors.toList()))
|
|
|
- .stream().map(SoftwareDTO::getId).collect(Collectors.toList());;
|
|
|
+ .stream().map(SoftwareDTO::getId).collect(Collectors.toList());
|
|
|
loginSoftwares.stream().forEach(softwareDTO -> {
|
|
|
if (hasSoftwareIds.contains(softwareDTO.getId())) {
|
|
|
softwareDTO.setRelation(RelationEnum.Y.getName());
|
|
@@ -348,7 +371,7 @@ public class RoleManagementFacade {
|
|
|
getRoleDTO.setLoginSoftwares(loginSoftwares);
|
|
|
getRoleDTO.setLoginUserMenuResourceTree(userMenuResourceTreeDTOS);
|
|
|
return getRoleDTO;
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
Asserts.fail("该登录用户无角色信息");
|
|
|
}
|
|
|
|
|
@@ -405,9 +428,9 @@ public class RoleManagementFacade {
|
|
|
//1.获取当前用户的角色列表
|
|
|
List<Long> roles = userRoleFacade.getBaseMapper().getUserRoles(SysUserUtils.getCurrentPrincipleId())
|
|
|
.stream().map(UserRoleDTO::getRoleId).collect(Collectors.toList());
|
|
|
- if(ListUtil.isNotEmpty(roles)){
|
|
|
- return getUserMenuResourceTreeByRoles(roles,type);
|
|
|
- }else {
|
|
|
+ if (ListUtil.isNotEmpty(roles)) {
|
|
|
+ return getUserMenuResourceTreeByRoles(roles, type);
|
|
|
+ } else {
|
|
|
Asserts.fail("当前登录用户无角色信息");
|
|
|
}
|
|
|
return null;
|
|
@@ -418,15 +441,15 @@ public class RoleManagementFacade {
|
|
|
* @Description通过角色列表获取用户功能菜单树
|
|
|
* @Return java.util.Map<java.lang.Long, java.util.List < com.lantone.common.dto.UserMenuResourceTreeDTO>>
|
|
|
*/
|
|
|
- private List<UserMenuResourceTreeDTO> getUserMenuResourceTreeByRoles(List<Long> roles,String type) {
|
|
|
+ private List<UserMenuResourceTreeDTO> getUserMenuResourceTreeByRoles(List<Long> roles, String type) {
|
|
|
List hideMenus = null;
|
|
|
//获取type下要隐藏的菜单
|
|
|
List<GetDictionaryInfoByTypeDTO> configHideMenus = dictionaryInfoFacade.getBaseMapper()
|
|
|
.getDictionaryInfoByType(DictionaryEnum.MANAGE_HIDE_MENU.getKey());
|
|
|
- if(ListUtil.isNotEmpty(configHideMenus)){
|
|
|
+ if (ListUtil.isNotEmpty(configHideMenus)) {
|
|
|
hideMenus = JSONArray.parseArray(JSONObject.parseObject(configHideMenus.get(0).getVal()).getString(type));
|
|
|
}
|
|
|
- List<UserMenuResourceTreeDTO> userMenuResourceTree = roleSoftwareMenuFacade.getBaseMapper().getUserMenuResourceTree(roles,hideMenus);
|
|
|
+ List<UserMenuResourceTreeDTO> userMenuResourceTree = roleSoftwareMenuFacade.getBaseMapper().getUserMenuResourceTree(roles, hideMenus);
|
|
|
return getTree(userMenuResourceTree);
|
|
|
}
|
|
|
|
|
@@ -436,15 +459,15 @@ public class RoleManagementFacade {
|
|
|
* @Description通过角色列表获取用户功能菜单树
|
|
|
* @Return java.util.Map<java.lang.Long, java.util.List < com.lantone.common.dto.UserMenuResourceTreeDTO>>
|
|
|
*/
|
|
|
- private List<UserMenuResourceTreeDTO> getUserMenuResourceTreeByRoles(List<Long> loginRoles, List<Long> selectRoles,String type) {
|
|
|
+ private List<UserMenuResourceTreeDTO> getUserMenuResourceTreeByRoles(List<Long> loginRoles, List<Long> selectRoles, String type) {
|
|
|
List hideMenus = null;
|
|
|
//获取type下要隐藏的菜单
|
|
|
List<GetDictionaryInfoByTypeDTO> configHideMenus = dictionaryInfoFacade.getBaseMapper()
|
|
|
.getDictionaryInfoByType(DictionaryEnum.MANAGE_HIDE_MENU.getKey());
|
|
|
- if(ListUtil.isNotEmpty(configHideMenus)){
|
|
|
+ if (ListUtil.isNotEmpty(configHideMenus)) {
|
|
|
hideMenus = JSONArray.parseArray(JSONObject.parseObject(configHideMenus.get(0).getVal()).getString(type));
|
|
|
}
|
|
|
- List<UserMenuResourceTreeDTO> userMenuResourceTree = roleSoftwareMenuFacade.getBaseMapper().getMenuResourceRelation(loginRoles, selectRoles,hideMenus);
|
|
|
+ List<UserMenuResourceTreeDTO> userMenuResourceTree = roleSoftwareMenuFacade.getBaseMapper().getMenuResourceRelation(loginRoles, selectRoles, hideMenus);
|
|
|
return getTree(userMenuResourceTree);
|
|
|
}
|
|
|
|
|
@@ -478,7 +501,7 @@ public class RoleManagementFacade {
|
|
|
* @Return java.util.List<com.lantone.common.dto.GetCreateRoleDTO>
|
|
|
*/
|
|
|
public List<GetCreateRoleDTO> getCreateRoles(Long softwareId) {
|
|
|
- return roleFacade.getBaseMapper().getCreateRoles(SysUserUtils.getCurrentPrincipleId(),softwareId);
|
|
|
+ return roleFacade.getBaseMapper().getCreateRoles(SysUserUtils.getCurrentPrincipleId(), softwareId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -487,36 +510,36 @@ public class RoleManagementFacade {
|
|
|
* @Return java.util.Map<java.lang.Long, java.util.List < com.lantone.common.dto.GetUserShowTreeDTO>>
|
|
|
*/
|
|
|
public Map<String, Object> getUserShowMemuTree() {
|
|
|
- if(StringUtil.isEmpty(SysUserUtils.getCurrentSoftwareId())){
|
|
|
+ if (StringUtil.isEmpty(SysUserUtils.getCurrentSoftwareId())) {
|
|
|
Asserts.fail("请求头服务id为空");
|
|
|
}
|
|
|
Long softwareId = Long.parseLong(SysUserUtils.getCurrentSoftwareId());
|
|
|
Map<String, Object> out = new HashMap<>();
|
|
|
- dataAuthManagementFacade.initUserDataAuth(SysUserUtils.getCurrentPrincipleId(),SysUserUtils.getCurrentHospitalId(),SysUserUtils.getCurrentSoftwareId());
|
|
|
+ dataAuthManagementFacade.initUserDataAuth(SysUserUtils.getCurrentPrincipleId(), SysUserUtils.getCurrentHospitalId(), SysUserUtils.getCurrentSoftwareId());
|
|
|
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()))){
|
|
|
+ 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())){
|
|
|
+ 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(),softwareId);
|
|
|
+ .getUserShowMemuTree(roles.stream().map(Role::getId).collect(Collectors.toList()), notShowSoftwareMenuIds.get(), softwareId);
|
|
|
//菜单转成树状结构
|
|
|
- if(ListUtil.isNotEmpty(getUserShowTreeDTOS)){
|
|
|
- out.put("showMenuInfo",getShowTree(getUserShowTreeDTOS).get(softwareId));
|
|
|
+ if (ListUtil.isNotEmpty(getUserShowTreeDTOS)) {
|
|
|
+ out.put("showMenuInfo", getShowTree(getUserShowTreeDTOS).get(softwareId));
|
|
|
}
|
|
|
return out;
|
|
|
}
|
|
@@ -533,7 +556,7 @@ public class RoleManagementFacade {
|
|
|
Map<Long, List<GetUserShowTreeDTO>> menuResourceMap = EntityUtil
|
|
|
.makeEntityListMap(userMenuResourceMap.get(softwareId), "parentId");
|
|
|
List<GetUserShowTreeDTO> menuRes = menuResourceMap.get(0L);
|
|
|
- if(ListUtil.isEmpty(menuRes)){
|
|
|
+ if (ListUtil.isEmpty(menuRes)) {
|
|
|
Asserts.fail("菜单目录为空");
|
|
|
}
|
|
|
for (GetUserShowTreeDTO bean : menuRes) {
|