ソースを参照

功能权限、数据权限禁用启用、删除方法修改,新增、修改添加校验

songxinlu 3 年 前
コミット
ba6ecf8029

+ 2 - 2
common/src/main/java/com/lantone/common/dto/GetMenuByIdDTO.java

@@ -40,8 +40,8 @@ public class GetMenuByIdDTO implements Serializable {
     @ApiModelProperty(value = "类型:0:目录,1菜单,2按钮,3:功能")
     private String type;
 
-    @ApiModelProperty(value = "页面路由")
-    private String url;
+    @ApiModelProperty(value = "权限标识")
+    private String code;
 
     @ApiModelProperty(value = "资源权限")
     private String permission;

+ 2 - 2
common/src/main/java/com/lantone/common/dto/GetMenusTreeDTO.java

@@ -31,8 +31,8 @@ public class GetMenusTreeDTO implements Serializable {
     @ApiModelProperty(value = "类型:0:目录,1菜单,2按钮,3:功能")
     private String type;
 
-    @ApiModelProperty(value = "页面路由")
-    private String url;
+    @ApiModelProperty(value = "权限标识")
+    private String code;
 
     @ApiModelProperty(value = "资源权限")
     private String permission;

+ 2 - 1
common/src/main/java/com/lantone/common/vo/AddMenuVO.java

@@ -41,7 +41,8 @@ public class AddMenuVO implements Serializable {
     @NotBlank(message = "类型为空")
     private String type;
 
-    @ApiModelProperty(value = "权限标识")
+    @ApiModelProperty(value = "权限标识",required = true)
+    @NotBlank(message = "权限标识为空")
     private String code;
 
     @ApiModelProperty(value = "图标")

+ 0 - 3
common/src/main/java/com/lantone/common/vo/UpdateAuthVO.java

@@ -22,7 +22,4 @@ public class UpdateAuthVO {
     @NotNull(message = "数据权限对象为空")
     private UpdateDataAuthVO updateDataAuthVO;
 
-    @ApiModelProperty(value = "角色列表", required = true)
-    @NotEmpty(message = "角色列表为空")
-    private List<Long> roles;
 }

+ 2 - 1
common/src/main/java/com/lantone/common/vo/UpdateMenuVO.java

@@ -44,7 +44,8 @@ public class UpdateMenuVO implements Serializable {
     @NotBlank(message = "类型为空")
     private String type;
 
-    @ApiModelProperty(value = "权限标识")
+    @ApiModelProperty(value = "权限标识",required = true)
+    @NotBlank(message = "权限标识为空")
     private String code;
 
     @ApiModelProperty(value = "图标")

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

@@ -5,6 +5,8 @@ import com.lantone.common.dto.GetMenuByIdDTO;
 import com.lantone.dblayermbg.entity.Menu;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * <p>
  * 表名:sys_menu Mapper接口
@@ -13,4 +15,6 @@ import org.apache.ibatis.annotations.Param;
 public interface MenuMapper extends BaseMapper<Menu> {
 
     GetMenuByIdDTO getMenuById(@Param("id") Long id,@Param("softwareId") Long softwareId);
+
+    List<Long> getChildMenus(@Param("id")Long id,@Param("status") String selectStatus);
 }

+ 15 - 0
dblayer-mbg/src/main/resources/mapper/MenuMapper.xml

@@ -14,6 +14,7 @@
         pm.`name` parentName,
         m.`name`,
         m.type,
+        m.`code`,
         r.url premission,
         m.order_no orderNo,
         m.menu_describe menuDescribe,
@@ -35,4 +36,18 @@
             AND m.id = #{id}
         </if>
     </select>
+    <select id="getChildMenus" resultType="java.lang.Long">
+        SELECT
+            m.id
+        FROM
+            sys_menu m
+        WHERE
+            m.is_deleted = 'N'
+        <if test="status != null and status !=''">
+            AND m.`status` = #{status}
+        </if>
+        <if test="id !=null">
+            AND FIND_IN_SET(m.id, getChildMenu(#{id}))
+        </if>
+    </select>
 </mapper>

+ 1 - 1
dblayer-mbg/src/main/resources/mapper/RoleSoftwareMenuMapper.xml

@@ -10,7 +10,7 @@
             m.order_no,
             m.remark,
             m.type,
-            m.url url,
+            m.`code`,
             IF (
             m.`status` = 1,
             "启用",

+ 67 - 16
security-center/src/main/java/com/lantone/security/facade/DataAuthManagementFacade.java

@@ -28,6 +28,7 @@ import com.lantone.common.vo.UpdateAuthVO;
 import com.lantone.dblayermbg.entity.DataAuth;
 import com.lantone.dblayermbg.entity.DataAuthDetail;
 import com.lantone.dblayermbg.entity.DeptUser;
+import com.lantone.dblayermbg.entity.Role;
 import com.lantone.dblayermbg.entity.RoleSoftwareDataAuth;
 import com.lantone.dblayermbg.entity.SoftwareDataAuth;
 import com.lantone.dblayermbg.facade.DataAuthDetailFacade;
@@ -38,6 +39,7 @@ import com.lantone.dblayermbg.facade.DoctorFacade;
 import com.lantone.dblayermbg.facade.HospitalFacade;
 import com.lantone.dblayermbg.facade.HospitalUserFacade;
 import com.lantone.dblayermbg.facade.MedoupDoctorFacade;
+import com.lantone.dblayermbg.facade.RoleFacade;
 import com.lantone.dblayermbg.facade.RoleSoftwareDataAuthFacade;
 import com.lantone.dblayermbg.facade.SoftwareDataAuthFacade;
 import com.lantone.dblayermbg.facade.UserFacade;
@@ -90,6 +92,8 @@ public class DataAuthManagementFacade {
     @Autowired
     private UserFacade userFacade;
     @Autowired
+    private RoleFacade roleFacade;
+    @Autowired
     private MedoupDoctorFacade medoupDoctorFacade;
 
 
@@ -112,7 +116,8 @@ public class DataAuthManagementFacade {
      * @Return boolean
      */
     public boolean updateDataAuth(UpdateAuthVO updateAuthVO) {
-
+        //校验
+        check(updateAuthVO.getUpdateDataAuthVO().getId(), updateAuthVO.getUpdateDataAuthVO().getName(), updateAuthVO.getUpdateDataAuthVO().getSoftwareVOS());
         //1.修改数据权限
         boolean dataAuthUpdate = dataAuthFacade.update(new UpdateWrapper<DataAuth>()
                 .set("name", updateAuthVO.getUpdateDataAuthVO().getName())
@@ -172,18 +177,31 @@ public class DataAuthManagementFacade {
                 .set("is_deleted", IsDeleteEnum.Y.getKey())
                 .eq("id", Id));
         if (dataAuthdelete) {
-//            //2.获取该权限 系统与数据权限信息关联表(sys_service_data_auth)的关联id
-//            List<Long> serviceDataAuthIDS = softwareDataAuthFacade.list(new QueryWrapper<SoftwareDataAuth>()
-//                    .eq("data_auth_id", Id)
-//                    .eq("is_deleted", IsDeleteEnum.N.getKey())).stream().map(SoftwareDataAuth::getId).collect(Collectors.toList());
-//            //3.通过serviceDataAuthIDS 删除sys_role_service_data_auth和sys_service_data_auth和sys_data_auth_detail 对应关系
-//            if (ListUtil.isNotEmpty(serviceDataAuthIDS)) {
-//                if (deleteServiceDataAuth(serviceDataAuthIDS)) {
-//                    return true;
-//                } else {
-//                    Asserts.fail("数据权限与系统关系删除失败");
-//                }
-//            }
+            //2.获取该权限 系统与数据权限信息关联表(sys_service_data_auth)的关联id
+            List<Long> serviceDataAuthIDS = softwareDataAuthFacade.list(new QueryWrapper<SoftwareDataAuth>()
+                    .eq("data_auth_id", Id)
+                    .eq("is_deleted", IsDeleteEnum.N.getKey())).stream().map(SoftwareDataAuth::getId).collect(Collectors.toList());
+            //3.通过serviceDataAuthIDS 删除sys_role_service_data_auth和sys_service_data_auth和sys_data_auth_detail 对应关系
+            if (ListUtil.isNotEmpty(serviceDataAuthIDS)) {
+                if (dataAuthDetailFacade.update(new UpdateWrapper<DataAuthDetail>()
+                        .set("is_deleted", IsDeleteEnum.Y.getKey())
+                        .in("software_data_auth_id", serviceDataAuthIDS)
+                        .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
+                    if (roleSoftwareDataAuthFacade.update(new UpdateWrapper<RoleSoftwareDataAuth>()
+                            .set("is_deleted", IsDeleteEnum.Y.getKey())
+                            .in("software_data_auth_id", serviceDataAuthIDS)
+                            .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
+                        return softwareDataAuthFacade.update(new UpdateWrapper<SoftwareDataAuth>()
+                                .set("is_deleted", IsDeleteEnum.Y.getKey())
+                                .in("id", serviceDataAuthIDS)
+                                .eq("is_deleted", IsDeleteEnum.N.getKey()));
+                    } else {
+                        Asserts.fail("数据权限与系统、角色关联关系删除失败");
+                    }
+                } else {
+                    Asserts.fail("系统数据权限与数据权限明细关联关系删除失败");
+                }
+            }
             return true;
         } else {
             Asserts.fail("数据权限删除失败");
@@ -197,6 +215,8 @@ public class DataAuthManagementFacade {
      * @Return boolean
      */
     public boolean addDataAuth(AddAuthVO addAuthVO) {
+        //校验
+        check(null, addAuthVO.getAddDataAuthVO().getName(), addAuthVO.getAddDataAuthVO().getSoftwareVOS());
         //1.插入新建数据权限
         DataAuth dataAuth = new DataAuth();
         BeanUtils.copyProperties(addAuthVO.getAddDataAuthVO(), dataAuth);
@@ -212,6 +232,38 @@ public class DataAuthManagementFacade {
 
     }
 
+    /**
+     * @param id
+     * @param name
+     * @param softwareVOS
+     * @Description数据权限添加、修改时校验
+     * @Return void
+     */
+    private void check(Long id, String name, List<AddAuthSoftwareVO> softwareVOS) {
+        List<DataAuth> dataAuths = dataAuthFacade.list(new QueryWrapper<DataAuth>()
+                .eq("name", name)
+                .eq("is_deleted", IsDeleteEnum.N.getKey()));
+        //数据权限名称校验
+        if (id == null) {
+            if (dataAuths.size() > 0) {
+                Asserts.fail("该数据权限已存在,请重新输入");
+            }
+        } else {
+            if (dataAuths.stream().map(DataAuth::getId).collect(Collectors.toList()).contains(id)) {
+                Asserts.fail("该数据权限已存在,请重新输入");
+            }
+        }
+        //绑定角色校验
+        softwareVOS.stream().forEach(addAuthSoftwareVO -> {
+            if (roleFacade.list(new QueryWrapper<Role>()
+                    .in("id", addAuthSoftwareVO.getRoles())
+                    .eq("is_deleted", IsDeleteEnum.N.getKey())).size() != addAuthSoftwareVO.getRoles().size()) {
+                Asserts.fail("绑定角色存在变更,请刷新重试~");
+            }
+        });
+
+    }
+
     /**
      * @param softwareVOS
      * @param dataAuthId
@@ -286,7 +338,6 @@ public class DataAuthManagementFacade {
         if (ListUtil.isEmpty(softwareDataAuths)) {
             Asserts.fail("该数据权限无系统信息,请联系管理员");
         }
-        List<Long> softwareDataAuthIds = softwareDataAuths.stream().map(SoftwareDataAuth::getId).collect(Collectors.toList());
         //2.系统-(角色、数据权限详情)信息组装
         List<GetDataAuthSoftwareDTO> softwares = new ArrayList<>();
         softwareDataAuths.stream().forEach(softwareDataAuth -> {
@@ -360,7 +411,7 @@ public class DataAuthManagementFacade {
      * @Return void
      */
     @Async
-    public void initUserDataAuth(Long userId, Long hospitalId,String softwareId) {
+    public void initUserDataAuth(Long userId, Long hospitalId, String softwareId) {
         //获取当前用户的数据权限
         List<GetDataAuthDetailDTO> dataAuthDetails = dataAuthFacade.getBaseMapper()
                 .getDataAuth(userId, softwareId);
@@ -399,7 +450,7 @@ public class DataAuthManagementFacade {
                     notDepts.addAll(deptUserFacade.list(new QueryWrapper<DeptUser>()
                             .eq("user_id", userId)
                             .eq("is_deleted", IsDeleteEnum.N.getKey())).stream()
-                                .map(DeptUser::getDeptId).collect(Collectors.toList()));
+                            .map(DeptUser::getDeptId).collect(Collectors.toList()));
                 }
                 //本科室
                 if (DataAuthDataTypeEnum.ALL_SELF_DEPT.getKey() == dataType) {

+ 42 - 9
security-center/src/main/java/com/lantone/security/facade/FuncManagementFacade.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.lantone.common.dto.GetMenuByIdDTO;
 import com.lantone.common.dto.GetMenusTreeDTO;
+import com.lantone.common.enums.StatusEnum;
 import com.lantone.common.exception.Asserts;
 import com.lantone.common.util.DateUtil;
 import com.lantone.common.util.EntityUtil;
@@ -35,6 +36,7 @@ import org.springframework.stereotype.Component;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 /**
@@ -71,12 +73,12 @@ public class FuncManagementFacade {
         GetMenusTreeVo getMenusTreeVo = new GetMenusTreeVo();
         getMenusTreeVo.setCreator(SysUserUtils.getCurrentPrincipleId());
         List<Long> roleIds = userRoleFacade.list(new QueryWrapper<UserRole>()
-                .eq("user_id",SysUserUtils.getCurrentPrincipleId())
-                .eq("is_deleted",IsDeleteEnum.N.getKey())).stream().map(UserRole::getRoleId).collect(Collectors.toList());
-        if(ListUtil.isEmpty(roleIds)){
+                .eq("user_id", SysUserUtils.getCurrentPrincipleId())
+                .eq("is_deleted", IsDeleteEnum.N.getKey())).stream().map(UserRole::getRoleId).collect(Collectors.toList());
+        if (ListUtil.isEmpty(roleIds)) {
             Asserts.fail("当前登录用户没有角色,请联系管理员~");
         }
-        if(StringUtil.isEmpty(SysUserUtils.getCurrentSoftwareId())){
+        if (StringUtil.isEmpty(SysUserUtils.getCurrentSoftwareId())) {
             Asserts.fail("请求头服务id为空");
         }
         getMenusTreeVo.setSoftwareId(Long.parseLong(SysUserUtils.getCurrentSoftwareId()));
@@ -122,11 +124,12 @@ public class FuncManagementFacade {
      * @Return java.lang.Boolean
      */
     public Boolean addMenu(AddMenuVO addMenuVO) {
+        check(null,addMenuVO.getCode());
         //1.插入sys_menu
         //1.1插入sys_menu
         Menu menu = new Menu();
         BeanUtils.copyProperties(addMenuVO, menu);
-        menu.setCreator(SysUserUtils.getCurrentPrincipleId()+"");
+        menu.setCreator(SysUserUtils.getCurrentPrincipleId() + "");
         menu.setGmtCreate(DateUtil.now());
         if (menuFacade.save(menu)) {
             //2.插入功能菜单对应系统对应系统 sys_software_menu和sys_role_software_menu
@@ -140,6 +143,24 @@ public class FuncManagementFacade {
         return false;
     }
 
+    private void check(Long id, String code) {
+        List<Menu> menus = menuFacade.list(new QueryWrapper<Menu>()
+                .eq("code", code)
+                .eq("", IsDeleteEnum.N.getKey()));
+        if (id == null) {
+            if (ListUtil.isNotEmpty(menus)) {
+                Asserts.fail("该权限标识已存在,请重新输入");
+            }
+        } else {
+            menus.stream().forEach(menu -> {
+                if (id != menu.getId() && code.equals(menu.getCode())) {
+                    Asserts.fail("该权限标识已存在,请重新输入");
+                }
+            });
+        }
+
+    }
+
     /**
      * @param permissions
      * @param softwares
@@ -156,14 +177,14 @@ public class FuncManagementFacade {
                         .select("id")
                         .eq("url", permission)
                         .eq("is_deleted", IsDeleteEnum.N.getKey()));
-                if(hasPermissions.size()>0){
+                if (hasPermissions.size() > 0) {
                     //2.3 获取对应的 resourceID
                     // 插入菜单和功能权限对应关系
                     MenuResource menuResource = new MenuResource();
                     menuResource.setMenuId(menuID);
                     menuResource.setResourceId(hasPermissions.get(0).getId());
                     menuResourceFacade.save(menuResource);
-                }else {
+                } else {
                     //2.4 有权限 则插入sys_resource
                     Resource resource = new Resource();
                     resource.setUrl(permission);
@@ -239,9 +260,18 @@ public class FuncManagementFacade {
      * @Return java.lang.Boolean
      */
     public Boolean disableMenu(Long id, String status) {
+        AtomicBoolean out = new AtomicBoolean(false);
+        String selectStatus = "0";
+        if (StatusEnum.Enable.getKey().equals(status)) {
+            selectStatus = StatusEnum.Disable.getKey();
+        } else {
+            selectStatus = StatusEnum.Enable.getKey();
+        }
+        //获取功能菜单及其子集
+        List<Long> ids=menuFacade.getBaseMapper().getChildMenus(id,selectStatus);
         boolean flag = menuFacade.update(new UpdateWrapper<Menu>()
                 .set("status", status)
-                .eq("id", id)
+                .in("id", ids)
                 .eq("is_deleted", IsDeleteEnum.N.getKey()));
         return flag;
     }
@@ -252,10 +282,12 @@ public class FuncManagementFacade {
      * @Return java.lang.Boolean
      */
     public Boolean deleteMenu(Long id) {
+        //获取功能菜单及其子集
+        List<Long> ids=menuFacade.getBaseMapper().getChildMenus(id,StatusEnum.Enable.getKey());
         //1.删除原来menu关联插入的数据
         if (menuFacade.update(new UpdateWrapper<Menu>()
                 .set("is_deleted", IsDeleteEnum.Y.getKey())
-                .eq("id", id))) {
+                .in("id", ids))) {
             return true;
         } else {
             Asserts.fail("菜单详情删除失败");
@@ -269,6 +301,7 @@ public class FuncManagementFacade {
      * @Return java.lang.Boolean
      */
     public Boolean updateMenu(UpdateMenuVO updateMenuVO) {
+        check(updateMenuVO.getId(),updateMenuVO.getCode());
         //1.删除原来menu关联插入的数据
         if (deleteMenuJoinDate(updateMenuVO.getId(), 1l)) {
             //2.修改sys_menu 菜单表

+ 78 - 55
security-center/src/main/java/com/lantone/security/facade/RoleManagementFacade.java

@@ -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) {

+ 23 - 21
security-center/src/main/java/com/lantone/security/facade/UserManagementFacade.java

@@ -210,16 +210,16 @@ public class UserManagementFacade {
         checkRoles(roles);
         //5.用户如果没有医疗组、科室 绑定角色不能选择本医疗组、全部科室除本科室外、本科室数据权限角色
         //科室
-        userDeptCheck(roles,deptFlag);
+        userDeptCheck(roles, deptFlag);
         //医疗组(无医生信息,就不会有医疗组;有医生信息无医疗组)
         boolean groupFlag = false;
         if (StringUtil.isEmpty(user.getJobNo())) {
             groupFlag = true;
         } else {
-            List<Doctor> doctors  = doctorfacade.list(new QueryWrapper<Doctor>()
+            List<Doctor> doctors = doctorfacade.list(new QueryWrapper<Doctor>()
                     .eq("code", user.getJobNo())
                     .eq("is_deleted", IsDeleteEnum.N.getKey()));
-            if(ListUtil.isNotEmpty(doctors)){
+            if (ListUtil.isNotEmpty(doctors)) {
                 List<MedoupDoctor> medoupDoctors = medoupDoctorFacade.list(new QueryWrapper<MedoupDoctor>()
                         .in("dcotor_id", doctors.stream().map(Doctor::getId).collect(Collectors.toList()))
                         .eq("is_deleted", IsDeleteEnum.N.getKey()));
@@ -259,7 +259,7 @@ public class UserManagementFacade {
      * @Description校验用户如果没有科室信息时,是否分配科室数据权限相关的角色
      * @Return void
      */
-    private void userDeptCheck(List<Long> roles,boolean deptFlag) {
+    private void userDeptCheck(List<Long> roles, boolean deptFlag) {
         //获取当前用户的角色
         List<Long> dataTypes = new ArrayList<>();
         dataTypes.add(DataAuthDataTypeEnum.ALL_DEPT_NOT_SELF.getKey() * 1l);
@@ -269,12 +269,12 @@ public class UserManagementFacade {
         StringBuffer errStr = new StringBuffer();
         //角色需要用户包含科室信息
         if (ListUtil.isNotEmpty(checkRoles)) {
-            if(!deptFlag){
+            if (!deptFlag) {
                 checkRoles.stream().forEach(userRoleDTO -> {
                     errStr.append(userRoleDTO.getRoleName() + ";");
                 });
             }
-            if(StringUtil.isNotEmpty(errStr.toString())){
+            if (StringUtil.isNotEmpty(errStr.toString())) {
                 Asserts.fail(errStr.toString() + "角色需要用户具备科室信息");
             }
         }
@@ -344,14 +344,16 @@ public class UserManagementFacade {
             Asserts.fail("用户关联的医院或科室都为空");
         }
         //如果选择科室没有添加科室对应的医院
-        addHospitalTreeVO.getHospitals().addAll(deptFacade.list(new QueryWrapper<Dept>()
-                .in("id",addHospitalTreeVO.getDepts())
-                .eq("is_deleted",IsDeleteEnum.N.getKey())
-                .eq("status",StatusEnum.Enable.getKey())).stream().map(Dept::getHospitalId).collect(Collectors.toList()));
-        //去重
-        Set<Long> hospitalSet = new HashSet<>(addHospitalTreeVO.getHospitals());
-        List<Long> hospitals = new ArrayList<>(hospitalSet);
-        addHospitalTreeVO.setHospitals(hospitals);
+        if (ListUtil.isNotEmpty(addHospitalTreeVO.getDepts())) {
+            addHospitalTreeVO.getHospitals().addAll(deptFacade.list(new QueryWrapper<Dept>()
+                    .in("id", addHospitalTreeVO.getDepts())
+                    .eq("is_deleted", IsDeleteEnum.N.getKey())
+                    .eq("status", StatusEnum.Enable.getKey())).stream().map(Dept::getHospitalId).collect(Collectors.toList()));
+            //去重
+            Set<Long> hospitalSet = new HashSet<>(addHospitalTreeVO.getHospitals());
+            List<Long> hospitals = new ArrayList<>(hospitalSet);
+            addHospitalTreeVO.setHospitals(hospitals);
+        }
 
         //插入用户和科室的关系(没有科室信息默认为全院)
         if (ListUtil.isNotEmpty(addHospitalTreeVO.getDepts())) {
@@ -509,7 +511,7 @@ public class UserManagementFacade {
         GetUserDTO getUserDTO = new GetUserDTO();
         //1.获取用户的基本信息
         User user = userFacade.getById(userId);
-        if(user==null){
+        if (user == null) {
             Asserts.fail("该用户不存在请刷新重试~");
         }
         BeanUtils.copyProperties(user, getUserDTO);
@@ -553,10 +555,10 @@ public class UserManagementFacade {
     }
 
     /**
-     * @param hospitalMap      医院结果级
-     * @param hospitals        查询用户所在医院集
+     * @param hospitalMap       医院结果级
+     * @param hospitals         查询用户所在医院集
      * @param userHospitalDepts 查询用户所在科室集
-     * @param hospitalTreeDTOS 当前遍历医院集
+     * @param hospitalTreeDTOS  当前遍历医院集
      * @Description
      * @Return void
      */
@@ -573,7 +575,7 @@ public class UserManagementFacade {
                     if (depts.contains(getDeptTreeDTO.getDeptId())) {
                         getDeptTreeDTO.setRelation(RelationEnum.Y.getName());
                         //如果只有医院没有科室则是医院全选
-                    }else if(hospitals.contains(bean.getHospitalId())&&!dHospitals.contains(bean.getHospitalId())){
+                    } else if (hospitals.contains(bean.getHospitalId()) && !dHospitals.contains(bean.getHospitalId())) {
                         getDeptTreeDTO.setRelation(RelationEnum.Y.getName());
                         bean.setRelation(RelationEnum.Y.getName());
                     }
@@ -671,8 +673,8 @@ public class UserManagementFacade {
         out.put("jump", jumpFlag);
         out.put("software", userSoftwareHospitals);
         UserInfoDTO userInfo = new UserInfoDTO();
-        BeanUtils.copyProperties(userFacade.getById(SysUserUtils.getCurrentPrincipleId()),userInfo);
-        out.put("userInfo",userInfo);
+        BeanUtils.copyProperties(userFacade.getById(SysUserUtils.getCurrentPrincipleId()), userInfo);
+        out.put("userInfo", userInfo);
         return out;
     }
 

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

@@ -55,7 +55,7 @@ public class FuncManagementController {
         return CommonResult.success(funcManagementFacade.updateMenu(updateMenuVO));
     }
 
-    @ApiOperation(value = "获取菜单详情 [by:songxl]")
+    @ApiOperation(value = "查看功能菜单 [by:songxl]")
     @PostMapping("/getMenuById")
     public CommonResult<GetMenuByIdDTO> getMenuById(@RequestParam @Valid @NotNull(message = "功能菜单编号为空") Long id, @RequestParam @Valid @NotNull(message = "系统编号为空") Long softwareId) {
         return CommonResult.success(funcManagementFacade.getMenuById(id, softwareId));