Explorar o código

修改数据权限新增、修改接口,修改当前管理用户管理角色列表接口

songxinlu %!s(int64=3) %!d(string=hai) anos
pai
achega
62d4b94764

+ 0 - 19
common/src/main/java/com/lantone/common/vo/AddAuthRoleVO.java

@@ -1,19 +0,0 @@
-package com.lantone.common.vo;
-
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-
-import javax.validation.constraints.NotNull;
-import java.io.Serializable;
-
-@Data
-public class AddAuthRoleVO implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    @ApiModelProperty(value = "角色名称" ,required = true)
-    @NotNull(message = "角色名称不能为空")
-    private Long id;
-
-    @ApiModelProperty(value = "角色名称" ,required = true)
-    private String name;
-}

+ 5 - 6
common/src/main/java/com/lantone/common/vo/AddAuthSoftwareVO.java

@@ -3,6 +3,7 @@ package com.lantone.common.vo;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import javax.validation.Valid;
 import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
@@ -15,14 +16,12 @@ import java.util.List;
 public class AddAuthSoftwareVO implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    @ApiModelProperty(value = "编号",required = true)
+    @ApiModelProperty(value = "系统服务编号",required = true)
     @NotNull(message = "系统服务编号为空")
     private Long id;
 
-    @ApiModelProperty(value = "服务名称")
-    private String name;
-
     @ApiModelProperty(value = "数据权限详情列表",required = true)
-    @NotEmpty(message = "数据权限详情列表为空")
-    private List<DataAuthDetailVO> dataAuthDetailVOS;
+    @Valid
+    @NotNull(message = "数据权限详情列表为空")
+    private DataAuthDetailVO dataAuthDetail;
 }

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

@@ -23,7 +23,6 @@ public class AddAuthVO {
     private AddDataAuthVO addDataAuthVO;
 
     @ApiModelProperty(value = "角色列表", required = true)
-    @Valid
     @NotEmpty(message = "角色列表为空")
-    private List<AddAuthRoleVO> roles;
+    private List<Long> roles;
 }

+ 1 - 7
common/src/main/java/com/lantone/common/vo/AddDataAuthVO.java

@@ -20,10 +20,7 @@ import java.util.List;
 @Data
 public class AddDataAuthVO implements Serializable {
     private static final long serialVersionUID = 1L;
-
-
     @ApiModelProperty(value = "数据权限名称", required = true)
-    @Valid
     @NotBlank(message = ("数据权限名称为空"))
     private String name;
 
@@ -31,11 +28,8 @@ public class AddDataAuthVO implements Serializable {
     @NotBlank(message = ("数据权限状态为空"))
     private String status;
 
-
-    @ApiModelProperty(value = "创建时间",hidden = true)
-    private Date createTime;
-
     @ApiModelProperty(value = "系统列表", required = true)
+    @Valid
     @NotEmpty(message = "系统列表为空")
     private List<AddAuthSoftwareVO> softwareVOS;
 

+ 4 - 10
common/src/main/java/com/lantone/common/vo/DataAuthDetailVO.java

@@ -6,19 +6,18 @@ import lombok.Data;
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
- * @ClassName: DataAuthDetailVO
  * @Description: 数据权限详情
  * @Author songxl
  * @Date 2021/7/22
- * @Version 1.0
  */
 @Data
 public class DataAuthDetailVO implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    @ApiModelProperty(value = "数据权限编号")
+    @ApiModelProperty(value = "数据权限编号",hidden = true)
     private Long serviceDataAuthId;
 
     @ApiModelProperty(value = "数据范围类型::1:全部组织,2:全部科室,3:全部科室除本科室外,4:本科室,5:本医疗组,6:本人,7:自定义" ,required = true)
@@ -28,12 +27,7 @@ public class DataAuthDetailVO implements Serializable {
     @ApiModelProperty(value = "detail_id的类型 1:detail_id为医院id 2:为科室id3:为医生id")
     private Integer detailType;
 
-    @ApiModelProperty(value = "医院、科室、医生id")
-    private Long detailId;
+    @ApiModelProperty(value = "医院、科室、医生id 列表")
+    private List<Long> detailIds;
 
-    @ApiModelProperty(value = "创建用户编号")
-    private Long creator;
-
-    @ApiModelProperty(value = "创建时间")
-    private Date createTime;
 }

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

@@ -23,7 +23,6 @@ public class UpdateAuthVO {
     private UpdateDataAuthVO updateDataAuthVO;
 
     @ApiModelProperty(value = "角色列表", required = true)
-    @Valid
     @NotEmpty(message = "角色列表为空")
-    private List<AddAuthRoleVO> roles;
+    private List<Long> roles;
 }

+ 1 - 1
dblayer-mbg/src/main/java/com/lantone/dblayermbg/entity/RoleSoftwareDataAuth.java

@@ -62,7 +62,7 @@ public class RoleSoftwareDataAuth implements Serializable {
      * 创建人,0表示无创建人值
      */
     @TableField("creator")
-    private String creator;
+    private Long creator;
 
     /**
      * 修改人,如果为0则表示纪录未修改

+ 21 - 13
dblayer-mbg/src/main/resources/mapper/DoctorMapper.xml

@@ -30,33 +30,41 @@
         AND detail.is_deleted = 'N'
         WHERE
             dept.id = dd.dept_id
+        AND h.id = dept.hospital_id
         AND doc.id = dd.doctor_id
         AND h.is_deleted = 'N'
         AND dept.is_deleted = 'N'
         AND doc.is_deleted = 'N'
         AND dd.is_deleted = 'N'
+        <if test="doctorVO.name!=null and doctorVO.name!=''">
+            AND doc.`name` LIKE concat('%',#{doctorVO.name},'%')
+        </if>
+        <if test="doctorVO.mobilePhone!=null and doctorVO.mobilePhone!=''">
+            AND doc.mobilePhone LIKE concat('%',#{doctorVO.mobilePhone},'%')
+        </if>
+        ) t
+        WHERE 1=1
+        <if test="doctorVO.relation != null ">
+            AND t.relation = #{doctorVO.relation}
+        </if>
         <if test="doctorVO.hospitals !=null and doctorVO.hospitals.size!=0">
-            AND h.id IN
+            AND t.hospitalId IN
             <foreach collection="doctorVO.hospitals" item="id" open="(" close=")" separator=",">
                 #{id}
             </foreach>
         </if>
-        <if test="doctorVO.depts !=null and doctorVO.depts.size!=0">
-            AND dept.id IN
+        <if test="doctorVO.hospitals !=null and doctorVO.hospitals.size!=0 and doctorVO.depts !=null and doctorVO.depts.size!=0">
+            OR t.deptId IN
             <foreach collection="doctorVO.depts" item="id" open="(" close=")" separator=",">
                 #{id}
             </foreach>
         </if>
-        <if test="doctorVO.name!=null and doctorVO.name!=''">
-            AND doc.`name` LIKE concat('%',#{doctorVO.name},'%')
-        </if>
-        <if test="doctorVO.mobilePhone!=null and doctorVO.mobilePhone!=''">
-            AND doc.mobilePhone LIKE concat('%',#{doctorVO.mobilePhone},'%')
-        </if>
-        ) t
-        WHERE
-        <if test="doctorVO.relation != null ">
-            t.relation = #{doctorVO.relation}
+        <if test="(doctorVO.hospitals ==null or doctorVO.hospitals.size==0) and doctorVO.depts !=null and doctorVO.depts.size!=0">
+            AND t.deptId IN
+            <foreach collection="doctorVO.depts" item="id" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
         </if>
+
     </select>
 </mapper>

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

@@ -28,6 +28,6 @@
             r.is_deleted = 'N'
         AND r.`status` = '1'
         AND r.hospital_id = #{hospitalId}
-        AND r.`remark` != 'ManagementRole'
+--         AND r.`remark` != 'ManagementRole'
     </select>
 </mapper>

+ 76 - 65
security-center/src/main/java/com/lantone/security/facade/DataAuthManagementFacade.java

@@ -16,10 +16,8 @@ import com.lantone.common.exception.Asserts;
 import com.lantone.common.util.DateUtil;
 import com.lantone.common.util.ListUtil;
 import com.lantone.common.util.SysUserUtils;
-import com.lantone.common.vo.AddAuthRoleVO;
 import com.lantone.common.vo.AddAuthSoftwareVO;
 import com.lantone.common.vo.AddAuthVO;
-import com.lantone.common.vo.DataAuthDetailVO;
 import com.lantone.common.vo.GetDataAuthPageVO;
 import com.lantone.common.vo.GetDoctorPageVO;
 import com.lantone.common.vo.UpdateAuthVO;
@@ -27,6 +25,7 @@ import com.lantone.dblayermbg.entity.DataAuth;
 import com.lantone.dblayermbg.entity.DataAuthDetail;
 import com.lantone.dblayermbg.entity.Dept;
 import com.lantone.dblayermbg.entity.Hospital;
+import com.lantone.dblayermbg.entity.Menu;
 import com.lantone.dblayermbg.entity.RoleSoftwareDataAuth;
 import com.lantone.dblayermbg.entity.SoftwareDataAuth;
 import com.lantone.dblayermbg.facade.DataAuthDetailFacade;
@@ -36,6 +35,8 @@ import com.lantone.dblayermbg.facade.DoctorFacade;
 import com.lantone.dblayermbg.facade.HospitalFacade;
 import com.lantone.dblayermbg.facade.RoleSoftwareDataAuthFacade;
 import com.lantone.dblayermbg.facade.SoftwareDataAuthFacade;
+import com.lantone.dblayermbg.service.impl.DataAuthDetailServiceImpl;
+import com.lantone.dblayermbg.service.impl.RoleSoftwareDataAuthServiceImpl;
 import com.lantone.security.enums.DataAuthDataTypeEnum;
 import com.lantone.security.enums.DataAuthDetailTypeEnum;
 import com.lantone.security.enums.HospitalTypeEnum;
@@ -50,15 +51,14 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 
 /**
- * @ClassName: DataAuthHandleFacade
  * @Description:数据权限操作facade
  * @Author songxl
  * @Date 2021/7/21
- * @Version 1.0
  */
 @Component
 public class DataAuthManagementFacade {
@@ -115,11 +115,11 @@ public class DataAuthManagementFacade {
                 }
             }
             //4.插入新建数据权限与系统的关系
-            saveServiceDataAuth(updateAuthVO.getUpdateDataAuthVO().getSoftwareVOS(), updateAuthVO.getRoles(), updateAuthVO.getUpdateDataAuthVO().getId());
+            return saveServiceDataAuth(updateAuthVO.getUpdateDataAuthVO().getSoftwareVOS(), updateAuthVO.getRoles(), updateAuthVO.getUpdateDataAuthVO().getId());
         } else {
             Asserts.fail("数据权限修改失败");
         }
-        return true;
+        return false;
     }
 
     /**
@@ -153,26 +153,27 @@ public class DataAuthManagementFacade {
      */
     public boolean deleteDataAuth(Long Id) {
         //1.删除数据权限
-        boolean dataAuthdelete = dataAuthFacade.remove(new UpdateWrapper<DataAuth>()
-                .eq("id", Id)
-                .eq("is_deleted", IsDeleteEnum.N.getKey()));
+        boolean dataAuthdelete = dataAuthFacade.update(new UpdateWrapper<DataAuth>()
+                .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 (deleteServiceDataAuth(serviceDataAuthIDS)) {
+//                    return true;
+//                } else {
+//                    Asserts.fail("数据权限与系统关系删除失败");
+//                }
+//            }
+            return true;
         } else {
             Asserts.fail("数据权限删除失败");
         }
-        return true;
+        return false;
     }
 
     /**
@@ -187,68 +188,78 @@ public class DataAuthManagementFacade {
         dataAuth.setGmtCreate(DateUtil.now());
         dataAuth.setCreator(SysUserUtils.getCurrentPrincipleId());
         if (dataAuthFacade.save(dataAuth)) {
-            //2.插入新建数据权限与系统的关系
-            saveServiceDataAuth(addAuthVO.getAddDataAuthVO().getSoftwareVOS(), addAuthVO.getRoles(), dataAuth.getId());
+            //2.插入新建数据权限与系统的关系 sys_software_data_auth
+            return saveServiceDataAuth(addAuthVO.getAddDataAuthVO().getSoftwareVOS(), addAuthVO.getRoles(), dataAuth.getId());
         } else {
             Asserts.fail("数据权限插入失败");
         }
-        return true;
+        return false;
 
     }
 
     /**
-     * @Description插入新建数据权限与系统的关系
      * @param softwareVOS
      * @param roles
      * @param dataAuthId
+     * @Description插入新建数据权限与系统的关系
      * @Return void
      */
-    private void saveServiceDataAuth(List<AddAuthSoftwareVO> softwareVOS, List<AddAuthRoleVO> roles, Long dataAuthId) {
-
-        for (AddAuthSoftwareVO sysServiceVO : softwareVOS) {
-            SoftwareDataAuth serviceDataAuth = new SoftwareDataAuth();
-            serviceDataAuth.setSoftwareId(sysServiceVO.getId());
-            serviceDataAuth.setDataAuthId(dataAuthId);
-            serviceDataAuth.setGmtCreate(DateUtil.now());
-            serviceDataAuth.setCreator("1");
-            //                serviceDataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
-            boolean serviceDataAuthInsert = softwareDataAuthFacade.save(serviceDataAuth);
-            if (serviceDataAuthInsert) {
-                //1.获取上一步插入时新生成的数据权限名称与系统关联编号service_data_auth _id
-                Long serviceDataAuthId = softwareDataAuthFacade.list(new QueryWrapper<SoftwareDataAuth>()
-                        .eq("software_id", sysServiceVO.getId())
-                        .eq("data_auth_id", dataAuthId)
-                        .eq("is_deleted", IsDeleteEnum.N.getKey())).get(0).getId();
-
+    private boolean saveServiceDataAuth(List<AddAuthSoftwareVO> softwareVOS, List<Long> roles, Long dataAuthId) {
+        AtomicBoolean out = new AtomicBoolean(false);
+        softwareVOS.stream().forEach(softwareVO->{
+            SoftwareDataAuth softwareDataAuth = new SoftwareDataAuth();
+            softwareDataAuth.setSoftwareId(softwareVO.getId());
+            softwareDataAuth.setDataAuthId(dataAuthId);
+            softwareDataAuth.setGmtCreate(DateUtil.now());
+            softwareDataAuth.setCreator(SysUserUtils.getCurrentPrincipleId()+"");
+            if (softwareDataAuthFacade.save(softwareDataAuth)) {
                 //2.插入数据权限系统关联表与角色管理sys_role_service_data_auth
-                for (AddAuthRoleVO role : roles) {
+                List<RoleSoftwareDataAuth> roleSoftwareDataAuths = new ArrayList<>();
+                for (Long roleId : roles) {
                     RoleSoftwareDataAuth roleServiceDataAuth = new RoleSoftwareDataAuth();
-                    roleServiceDataAuth.setRoleId(role.getId());
-                    roleServiceDataAuth.setSoftwareDataAuthId(serviceDataAuthId);
+                    roleServiceDataAuth.setRoleId(roleId);
+                    roleServiceDataAuth.setSoftwareDataAuthId(softwareDataAuth.getId());
                     roleServiceDataAuth.setGmtCreate(DateUtil.now());
-                    roleServiceDataAuth.setCreator("1");
-                    //                        roleServiceDataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
-                    if (!roleSoftwareDataAuthFacade.save(roleServiceDataAuth)) {
-                        Asserts.fail("角色对应服务数据权限关系插入失败");
-                    }
+                    roleServiceDataAuth.setCreator(SysUserUtils.getCurrentPrincipleId());
+                    roleSoftwareDataAuths.add(roleServiceDataAuth);
                 }
-                //3.插入数据权限详细信息。sys_data_auth_detail
-                for (DataAuthDetailVO dataAuthDetailVO : sysServiceVO.getDataAuthDetailVOS()) {
-                    DataAuthDetail dataAuthDetail = new DataAuthDetail();
-                    BeanUtils.copyProperties(dataAuthDetailVO, dataAuthDetail);
-                    //                        dataAuthDetail.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
-                    dataAuthDetail.setGmtCreate(DateUtil.now());
-                    dataAuthDetail.setCreator("1");
-                    dataAuthDetail.setSoftwareDataAuthId(serviceDataAuthId);
-                    if (!dataAuthDetailFacade.save(dataAuthDetail)) {
-                        Asserts.fail("数据权限明细插入失败");
+                if (new RoleSoftwareDataAuthServiceImpl().saveBatch(roleSoftwareDataAuths)) {
+                    //3.插入数据权限详细信息。sys_data_auth_detail
+                    //自定义时
+                    List<DataAuthDetail> dataAuthDetails = new ArrayList<>();
+                    if (ListUtil.isNotEmpty(softwareVO.getDataAuthDetail().getDetailIds())
+                            && softwareVO.getDataAuthDetail().getDetailType() != null) {
+                        softwareVO.getDataAuthDetail().getDetailIds().stream().forEach(id -> {
+                            DataAuthDetail dataAuthDetail = new DataAuthDetail();
+                            BeanUtils.copyProperties(softwareVO.getDataAuthDetail(), dataAuthDetail);
+                            dataAuthDetail.setGmtCreate(DateUtil.now());
+                            dataAuthDetail.setCreator(SysUserUtils.getCurrentPrincipleId() + "");
+                            dataAuthDetail.setSoftwareDataAuthId(softwareDataAuth.getId());
+                            dataAuthDetail.setDetailId(id);
+                            dataAuthDetails.add(dataAuthDetail);
+                        });
+                    } else {
+                        DataAuthDetail dataAuthDetail = new DataAuthDetail();
+                        BeanUtils.copyProperties(softwareVO.getDataAuthDetail(), dataAuthDetail);
+                        dataAuthDetail.setGmtCreate(DateUtil.now());
+                        dataAuthDetail.setCreator(SysUserUtils.getCurrentPrincipleId() + "");
+                        dataAuthDetail.setSoftwareDataAuthId(softwareDataAuth.getId());
+                        dataAuthDetails.add(dataAuthDetail);
+                    }
+                    if(new DataAuthDetailServiceImpl().saveBatch(dataAuthDetails)){
+                        out.set(true);
+                    }else {
+                        Asserts.fail("数据权限详情插入失败");
                     }
+                } else {
+                    Asserts.fail("角色对应服务数据权限关系插入失败");
                 }
 
             } else {
                 Asserts.fail("服务对应数据权限关系插入失败");
             }
-        }
+        });
+        return out.get();
     }
 
     /**
@@ -318,8 +329,8 @@ public class DataAuthManagementFacade {
     }
 
     /**
-     * @Description 获取组织-科室信息以及自定义科室
      * @param dataAuthDetailDTO
+     * @Description 获取组织-科室信息以及自定义科室
      * @Return void
      */
     public void getDeptDetial(DataAuthDetailDTO dataAuthDetailDTO) {
@@ -340,9 +351,9 @@ public class DataAuthManagementFacade {
     }
 
     /**
-     * @Description取对应医院的科室信息
      * @param hospitalDTO
      * @param dataAuthDetailDTO
+     * @Description取对应医院的科室信息
      * @Return void
      */
     private void getDeptInfo(HospitalDTO hospitalDTO, DataAuthDetailDTO dataAuthDetailDTO) {
@@ -377,8 +388,8 @@ public class DataAuthManagementFacade {
     }
 
     /**
-     * @Description 获取医院对应的子医院信息
      * @param hospitalDTOS
+     * @Description 获取医院对应的子医院信息
      * @Return void
      */
     private void getAllHospitalDTO(List<HospitalDTO> hospitalDTOS) {

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

@@ -16,6 +16,7 @@ import com.lantone.dblayermbg.entity.MenuResource;
 import com.lantone.dblayermbg.entity.Resource;
 import com.lantone.dblayermbg.entity.SoftwareMenu;
 import com.lantone.dblayermbg.entity.SoftwareResource;
+import com.lantone.dblayermbg.entity.User;
 import com.lantone.dblayermbg.facade.MenuFacade;
 import com.lantone.dblayermbg.facade.MenuResourceFacade;
 import com.lantone.dblayermbg.facade.ResourceFacade;
@@ -239,15 +240,12 @@ public class FuncManagementFacade {
      */
     public Boolean deleteMenu(Long id) {
         //1.删除原来menu关联插入的数据
-        if (menuFacade.remove(new UpdateWrapper<Menu>()
-                .eq("id", id)
-                .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
-            boolean flag = deleteMenuJoinDate(id, 1l);
-            if(flag){
-                //重新加载角色权限
-                resourceFacade.initResourceRolesMap();
-            }
-            return flag;
+        if (menuFacade.update(new UpdateWrapper<Menu>()
+                .set("is_deleted", IsDeleteEnum.Y.getKey())
+                .eq("id", id))) {
+            //重新加载角色权限
+            resourceFacade.initResourceRolesMap();
+            return true;
         } else {
             Asserts.fail("菜单详情删除失败");
         }

+ 65 - 0
security-center/src/main/java/com/lantone/security/facade/RoleManagementFacade.java

@@ -13,6 +13,7 @@ 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.enums.StatusEnum;
 import com.lantone.common.exception.Asserts;
 import com.lantone.common.util.DateUtil;
 import com.lantone.common.util.EntityUtil;
@@ -24,17 +25,24 @@ 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.Menu;
+import com.lantone.dblayermbg.entity.Resource;
 import com.lantone.dblayermbg.entity.Role;
 import com.lantone.dblayermbg.entity.RoleSoftwareMenu;
 import com.lantone.dblayermbg.entity.RoleSoftwareResource;
+import com.lantone.dblayermbg.entity.SoftwareMenu;
+import com.lantone.dblayermbg.entity.SoftwareResource;
 import com.lantone.dblayermbg.entity.UserRole;
 import com.lantone.dblayermbg.facade.DictionaryInfoFacade;
 import com.lantone.dblayermbg.facade.HospitalFacade;
+import com.lantone.dblayermbg.facade.MenuFacade;
 import com.lantone.dblayermbg.facade.ResourceFacade;
 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.SoftwareResourceFacade;
 import com.lantone.dblayermbg.facade.UserRoleFacade;
 import com.lantone.dblayermbg.service.impl.RoleSoftwareMenuServiceImpl;
 import com.lantone.dblayermbg.service.impl.RoleSoftwareResourceServiceImpl;
@@ -79,6 +87,12 @@ public class RoleManagementFacade {
     private DictionaryInfoFacade dictionaryInfoFacade;
     @Autowired
     private ResourceFacade resourceFacade;
+    @Autowired
+    private MenuFacade menuFacade;
+    @Autowired
+    private SoftwareMenuFacade softwareMenuFacade;
+    @Autowired
+    private SoftwareResourceFacade softwareResourceFacade;
 
 
     /**
@@ -121,6 +135,9 @@ public class RoleManagementFacade {
      * @Return java.lang.Boolean
      */
     public Boolean addRole(AddRoleVO addRoleVO) {
+        //校验
+        checkRole(addRoleVO.getName(),addRoleVO.getSoftwares());
+
         //1.角色表插入角色信息
         addRoleVO.setCreator(SysUserUtils.getCurrentPrincipleId());
         if(addRoleVO.getHospitalId()==null){
@@ -138,6 +155,54 @@ public class RoleManagementFacade {
         return false;
     }
 
+    /**
+     * @Description角色新增修改校验
+     * @param name
+     * @param softwares
+     * @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("该角色已存在请重新输入");
+        }
+        if(ListUtil.isNotEmpty(softwares)){
+            softwares.stream().forEach(addRoleSoftwareVO -> {
+                //获取菜单比对插入的功能菜单都能正常使用
+               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",softwareMenuFacade.list(new QueryWrapper<SoftwareMenu>()
+                                   .select("menu_id")
+                                   .eq("is_deleted",IsDeleteEnum.N.getKey())
+                                   .in("id",addRoleSoftwareVO.getSoftwareMenuIds()))
+                                   .stream().map(SoftwareMenu::getMenuId).collect(Collectors.toList())))){
+                       Asserts.fail("该角色要绑定的功能菜单已更新请刷新重试~");
+                   }
+               }
+                //功能权限校验
+                //获取菜单比对插入的功能菜单都能正常使用
+                if(ListUtil.isNotEmpty(addRoleSoftwareVO.getSoftwareResourceIds())){
+                    //去重 菜单对应的功能权限可能是一个
+                    Set resourceSet = new HashSet(addRoleSoftwareVO.getSoftwareResourceIds());
+                    if(resourceSet.size()!= resourceFacade.count(new QueryWrapper<Resource>()
+                            .eq("status", StatusEnum.Enable.getKey())
+                            .eq("is_deleted",IsDeleteEnum.N.getKey())
+                            .in("id",softwareResourceFacade.list(new QueryWrapper<SoftwareResource>()
+                                    .select("resource_id")
+                                    .eq("is_deleted",IsDeleteEnum.N.getKey())
+                                    .in("id",addRoleSoftwareVO.getSoftwareResourceIds()))
+                                    .stream().map(SoftwareResource::getResourceId).collect(Collectors.toList())))){
+                        Asserts.fail("该角色要绑定的功能菜单已更新请刷新重试~");
+                    }
+                }
+            });
+        }
+    }
+
     /**
      * @param softwares
      * @param roleId