Переглянути джерело

超管设置新增角色配置

wangliang 2 роки тому
батько
коміт
29c846436f
17 змінених файлів з 362 додано та 74 видалено
  1. 12 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/params/SysAdminSetParam.java
  2. 12 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/CustomPrivilegeResult.java
  3. 11 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/SysAdminSetResult.java
  4. 92 11
      distributed-print/src/main/java/com/qmth/distributed/print/api/SysAdminSetController.java
  5. 73 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/entity/TSchoolRole.java
  6. 3 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/mapper/SysUserRoleMapper.java
  7. 16 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/mapper/TSchoolRoleMapper.java
  8. 10 1
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/SysUserRoleService.java
  9. 25 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/TSchoolRoleService.java
  10. 11 15
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysOrgServiceImpl.java
  11. 6 19
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysRoleServiceImpl.java
  12. 13 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysUserRoleServiceImpl.java
  13. 5 15
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysUserServiceImpl.java
  14. 35 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TSchoolRoleServiceImpl.java
  15. 13 13
      teachcloud-common/src/main/resources/mapper/SysRoleMapper.xml
  16. 20 0
      teachcloud-common/src/main/resources/mapper/SysUserRoleMapper.xml
  17. 5 0
      teachcloud-common/src/main/resources/mapper/TSchoolRoleMapper.xml

+ 12 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/params/SysAdminSetParam.java

@@ -32,6 +32,10 @@ public class SysAdminSetParam extends TSchoolPrivilege {
     @ApiModelProperty(value = "同步配置地址")
     String syncServicePath;
 
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "角色id数组")
+    private Long[] roleIds;
+
     public SysAdminSetParam() {
 
     }
@@ -49,6 +53,14 @@ public class SysAdminSetParam extends TSchoolPrivilege {
         this.teachcloudExchangeSerivePath = teachcloudExchangeSerivePath;
     }
 
+    public Long[] getRoleIds() {
+        return roleIds;
+    }
+
+    public void setRoleIds(Long[] roleIds) {
+        this.roleIds = roleIds;
+    }
+
     public String getSyncServicePath() {
         return syncServicePath;
     }

+ 12 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/CustomPrivilegeResult.java

@@ -2,6 +2,7 @@ package com.qmth.distributed.print.business.bean.result;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.qmth.teachcloud.common.bean.dto.PrivilegeDto;
+import com.qmth.teachcloud.common.entity.SysRole;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
@@ -23,6 +24,9 @@ public class CustomPrivilegeResult implements Serializable {
     @ApiModelProperty(value = "全局pdf格式")
     List<String> sysPdfSize;
 
+    @ApiModelProperty(value = "自定义角色")
+    List<SysRole> customRoleList;
+
     public CustomPrivilegeResult() {
 
     }
@@ -39,6 +43,14 @@ public class CustomPrivilegeResult implements Serializable {
         this.customPrivilegeList = customPrivilegeList;
     }
 
+    public List<SysRole> getCustomRoleList() {
+        return customRoleList;
+    }
+
+    public void setCustomRoleList(List<SysRole> customRoleList) {
+        this.customRoleList = customRoleList;
+    }
+
     public List<String> getSysPdfSize() {
         return sysPdfSize;
     }

+ 11 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/SysAdminSetResult.java

@@ -37,6 +37,9 @@ public class SysAdminSetResult implements Serializable {
     @ApiModelProperty(value = "同步配置地址")
     String syncServicePath;
 
+    @ApiModelProperty(value = "自定义角色id")
+    List<String> roleIdList;
+
     public SysAdminSetResult() {
 
     }
@@ -61,6 +64,14 @@ public class SysAdminSetResult implements Serializable {
         this.teachcloudExchangeSerivePath = teachcloudExchangeSerivePath;
     }
 
+    public List<String> getRoleIdList() {
+        return roleIdList;
+    }
+
+    public void setRoleIdList(List<String> roleIdList) {
+        this.roleIdList = roleIdList;
+    }
+
     public String getSyncServicePath() {
         return syncServicePath;
     }

+ 92 - 11
distributed-print/src/main/java/com/qmth/distributed/print/api/SysAdminSetController.java

@@ -67,6 +67,9 @@ public class SysAdminSetController {
     @Resource
     MySQLDatabaseBackup mySQLDatabaseBackup;
 
+    @Resource
+    TSchoolRoleService tSchoolRoleService;
+
     @ApiOperation(value = "数据还原")
     @ApiResponses({@ApiResponse(code = 200, message = "数据还原信息", response = ResultUtil.class)})
     @RequestMapping(value = "/backup", method = RequestMethod.POST)
@@ -117,7 +120,7 @@ public class SysAdminSetController {
     }
 
     @ApiOperation(value = "系统试卷规格配置查询")
-    @ApiResponses({@ApiResponse(code = 200, message = "系统试卷规格配置信息", response = SysPrivilege.class)})
+    @ApiResponses({@ApiResponse(code = 200, message = "系统试卷规格配置信息", response = CustomPrivilegeResult.class)})
     @RequestMapping(value = "/paper/sys/select", method = RequestMethod.POST)
     public Result sysadminPaperSysSelect() {
         SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.SYS_PDF_SIZE_LIST);
@@ -212,9 +215,9 @@ public class SysAdminSetController {
     }
 
     @ApiOperation(value = "查询自定义菜单权限")
-    @ApiResponses({@ApiResponse(code = 200, message = "菜单权限信息", response = SysPrivilege.class)})
+    @ApiResponses({@ApiResponse(code = 200, message = "菜单权限信息", response = CustomPrivilegeResult.class)})
     @RequestMapping(value = "/menu/custom/list", method = RequestMethod.POST)
-    public Result customList() {
+    public Result customMenuList() {
         List<PrivilegeDto> customPrivilegeList = sysPrivilegeService.addCustomList();
         return ResultUtil.ok(new CustomPrivilegeResult(customPrivilegeList));
     }
@@ -223,7 +226,7 @@ public class SysAdminSetController {
     @ApiResponses({@ApiResponse(code = 200, message = "菜单权限信息", response = ResultUtil.class)})
     @RequestMapping(value = "/menu/custom/save", method = RequestMethod.POST)
     @Transactional
-    public Result getRolePrivileges(@Valid @RequestBody SysAdminSetParam tSchoolPrivilegeParam, BindingResult bindingResult) throws NoSuchAlgorithmException {
+    public Result schoolPrivilegeSave(@Valid @RequestBody SysAdminSetParam tSchoolPrivilegeParam, BindingResult bindingResult) throws NoSuchAlgorithmException {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
@@ -268,12 +271,8 @@ public class SysAdminSetController {
         //清缓存
         if (!CollectionUtils.isEmpty(roleSetIds)) {
             for (Long l : roleSetIds) {
-                if (Objects.isNull(commonCacheService.updateRoleCache(l))) {
-                    commonCacheService.removeRoleCache(l);
-                }
-                if (CollectionUtils.isEmpty(commonCacheService.updateRolePrivilegeCache(l))) {
-                    commonCacheService.removeRolePrivilegeCache(l);
-                }
+                commonCacheService.removeRoleCache(l);
+                commonCacheService.removeRolePrivilegeCache(l);
                 //绑定该角色的用户都需要清除鉴权缓存
                 List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(l);
                 for (SysUserRole s : sysUserRoleList) {
@@ -292,9 +291,91 @@ public class SysAdminSetController {
     @ApiOperation(value = "学校已绑定自定义菜单权限列表")
     @ApiResponses({@ApiResponse(code = 200, message = "菜单权限信息", response = SysAdminSetResult.class)})
     @RequestMapping(value = "/menu/custom/get_school_custom_privileges", method = RequestMethod.POST)
-    public Result getRolePrivileges(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) {
+    public Result getSchoolPrivileges(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) {
         List<TSchoolPrivilege> tSchoolPrivilegeList = tSchoolPrivilegeService.findBySchoolId(schoolId);
         List<String> privilegeIdList = tSchoolPrivilegeList.stream().map(s -> String.valueOf(s.getPrivilegeId())).collect(Collectors.toList());
         return ResultUtil.ok(new SysAdminSetResult(schoolId, CollectionUtils.isEmpty(privilegeIdList) ? new ArrayList<>() : privilegeIdList));
     }
+
+    @ApiOperation(value = "查询自定义角色权限")
+    @ApiResponses({@ApiResponse(code = 200, message = "角色权限信息", response = CustomPrivilegeResult.class)})
+    @RequestMapping(value = "/role/custom/list", method = RequestMethod.POST)
+    public Result customRoleList() {
+        QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
+        sysRoleQueryWrapper.lambda().eq(SysRole::getDefaultRole, true)
+                .eq(SysRole::getEnable, true)
+                .isNull(SysRole::getSchoolId)
+                .ne(SysRole::getType, SystemConstant.ADMIN_CODE.toUpperCase())
+                .orderByAsc(SysRole::getId);
+        List<SysRole> sysRoleList = sysRoleService.list(sysRoleQueryWrapper);
+        CustomPrivilegeResult customPrivilegeResult = new CustomPrivilegeResult();
+        customPrivilegeResult.setCustomRoleList(sysRoleList);
+        return ResultUtil.ok(sysRoleList);
+    }
+
+    @ApiOperation(value = "学校新增/修改自定义角色权限")
+    @ApiResponses({@ApiResponse(code = 200, message = "角色权限信息", response = ResultUtil.class)})
+    @RequestMapping(value = "/role/custom/save", method = RequestMethod.POST)
+    @Transactional
+    public Result schoolRoleSave(@Valid @RequestBody SysAdminSetParam tSchoolPrivilegeParam, BindingResult bindingResult) throws NoSuchAlgorithmException {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        Set<Long> userSetIds = null;
+        QueryWrapper<TSchoolRole> tSchoolRoleQueryWrapper = new QueryWrapper<>();
+        tSchoolRoleQueryWrapper.lambda().eq(TSchoolRole::getSchoolId, tSchoolPrivilegeParam.getSchoolId());
+        List<TSchoolRole> tSchoolRoles = tSchoolRoleService.list(tSchoolRoleQueryWrapper);
+        if (!CollectionUtils.isEmpty(tSchoolRoles)) {//编辑
+            Set<Long> changeRoleSetIds = tSchoolRoles.stream().filter(s -> !Arrays.asList(tSchoolPrivilegeParam.getRoleIds()).contains(s.getRoleId()))
+                    .collect(Collectors.toList())
+                    .stream().map(s -> s.getRoleId())
+                    .collect(Collectors.toSet());
+            //数据发生改变
+            if (!CollectionUtils.isEmpty(changeRoleSetIds)) {
+                //查询该角色下所有用户,删除该角色所发生改变的用户数据
+                List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleIdsAndSchoolId(changeRoleSetIds, tSchoolPrivilegeParam.getSchoolId());
+
+                if (!CollectionUtils.isEmpty(sysUserRoleList)) {
+                    List<Long> ids = new ArrayList<>(sysUserRoleList.size());
+                    for (SysUserRole s : sysUserRoleList) {
+                        userSetIds.add(s.getUserId());
+                        ids.add(s.getId());
+                    }
+                    sysUserRoleService.removeByIds(ids);
+                }
+            }
+            tSchoolRoleService.remove(tSchoolRoleQueryWrapper);
+        }
+        Long[] roleIds = tSchoolPrivilegeParam.getRoleIds();
+        if (Objects.nonNull(roleIds) && roleIds.length > 0) {
+            List<TSchoolRole> tSchoolRoleList = new ArrayList<>();
+            for (int i = 0; i < roleIds.length; i++) {
+                tSchoolRoleList.add(new TSchoolRole(tSchoolPrivilegeParam.getSchoolId(), roleIds[i]));
+            }
+            tSchoolRoleService.saveBatch(tSchoolRoleList);
+        }
+
+        //清缓存
+        if (!CollectionUtils.isEmpty(userSetIds)) {
+            for (Long l : userSetIds) {
+                commonCacheService.removeUserCache(l);
+                commonCacheService.removeUserAuthCache(l);
+                commonCacheService.removeUserMenuCache(l);
+                commonCacheService.removeUserRolePrivilegeCache(l);
+            }
+        }
+        return ResultUtil.ok(true);
+    }
+
+    @ApiOperation(value = "学校已绑定自定义角色权限列表")
+    @ApiResponses({@ApiResponse(code = 200, message = "角色权限信息", response = SysAdminSetResult.class)})
+    @RequestMapping(value = "/role/custom/get_school_custom_roles", method = RequestMethod.POST)
+    public Result getSchoolRoles(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) {
+        List<TSchoolRole> tSchoolRoleList = tSchoolRoleService.findBySchoolId(schoolId);
+        List<String> roleIdList = tSchoolRoleList.stream().map(s -> String.valueOf(s.getRoleId())).collect(Collectors.toList());
+        SysAdminSetResult sysAdminSetResult = new SysAdminSetResult();
+        sysAdminSetResult.setSchoolId(schoolId);
+        sysAdminSetResult.setRoleIdList(CollectionUtils.isEmpty(roleIdList) ? new ArrayList<>() : roleIdList);
+        return ResultUtil.ok(sysAdminSetResult);
+    }
 }

+ 73 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/entity/TSchoolRole.java

@@ -0,0 +1,73 @@
+package com.qmth.teachcloud.common.entity;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 学校角色权限表
+ * </p>
+ *
+ * @author wangliang
+ * @since 2021-10-28
+ */
+@ApiModel(value = "TSchoolRole对象", description = "学校角色权限表")
+public class TSchoolRole implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "主键")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long id;
+
+    @ApiModelProperty(value = "学校id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    @NotNull(message = "学校id不能为空")
+    private Long schoolId;
+
+    @ApiModelProperty(value = "角色id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long roleId;
+
+    public TSchoolRole() {
+
+    }
+
+    public TSchoolRole(Long schoolId, Long roleId) {
+        this.schoolId = schoolId;
+        this.roleId = roleId;
+    }
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getSchoolId() {
+        return schoolId;
+    }
+
+    public void setSchoolId(Long schoolId) {
+        this.schoolId = schoolId;
+    }
+
+    public Long getRoleId() {
+        return roleId;
+    }
+
+    public void setRoleId(Long roleId) {
+        this.roleId = roleId;
+    }
+}

+ 3 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/mapper/SysUserRoleMapper.java

@@ -7,6 +7,7 @@ import com.qmth.teachcloud.common.entity.SysUserRole;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * <p>
@@ -20,6 +21,8 @@ public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
 
     List<SysRole> listRoleByUserId(@Param("userId") Long userId);
 
+    List<SysUserRole> listByRoleIdsAndSchoolId(@Param("ids") Set<Long> ids, @Param("schoolId") Long schoolId);
+
     List<MenuDto> listByUserId(@Param("userId") Long userId, @Param("schoolId") Long schoolId);
 
     List<MenuDto> listAll(@Param("schoolId") Long schoolId);

+ 16 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/mapper/TSchoolRoleMapper.java

@@ -0,0 +1,16 @@
+package com.qmth.teachcloud.common.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.teachcloud.common.entity.TSchoolRole;
+
+/**
+ * <p>
+ * 学校角色权限表 Mapper 接口
+ * </p>
+ *
+ * @author wangliang
+ * @since 2021-10-28
+ */
+public interface TSchoolRoleMapper extends BaseMapper<TSchoolRole> {
+
+}

+ 10 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/SysUserRoleService.java

@@ -1,12 +1,12 @@
 package com.qmth.teachcloud.common.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
-import com.qmth.teachcloud.common.bean.dto.MenuDto;
 import com.qmth.teachcloud.common.bean.result.MenuResult;
 import com.qmth.teachcloud.common.entity.SysRole;
 import com.qmth.teachcloud.common.entity.SysUserRole;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * <p>
@@ -20,6 +20,15 @@ public interface SysUserRoleService extends IService<SysUserRole> {
 
     List<SysUserRole> listByRoleId(Long id);
 
+    /**
+     * 根据角色ids和学校id查找
+     *
+     * @param ids
+     * @param schoolId
+     * @return
+     */
+    List<SysUserRole> listByRoleIdsAndSchoolId(Set<Long> ids, Long schoolId);
+
     List<SysRole> listRoleByUserId(Long id);
 
     void removeByUserId(Long id);

+ 25 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/TSchoolRoleService.java

@@ -0,0 +1,25 @@
+package com.qmth.teachcloud.common.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.teachcloud.common.entity.TSchoolRole;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 学校角色权限表 服务类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2021-10-28
+ */
+public interface TSchoolRoleService extends IService<TSchoolRole> {
+
+    /**
+     * 根据学校id查找自定义角色
+     *
+     * @param schoolId
+     * @return
+     */
+    List<TSchoolRole> findBySchoolId(Long schoolId);
+}

+ 11 - 15
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysOrgServiceImpl.java

@@ -53,7 +53,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
     private CommonCacheService commonCacheService;
 
     @Override
-    public List<OrgDto> listOrgTree(SpecialPrivilegeEnum specialPrivilegeEnum,boolean withoutPrintingRoom) {
+    public List<OrgDto> listOrgTree(SpecialPrivilegeEnum specialPrivilegeEnum, boolean withoutPrintingRoom) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         List<SysUserResult> sysUserResultList = sysUserService.findSysUserResultList();
         List<SysUserResult> finalSysUserResultList = sysUserResultList.stream()
@@ -74,7 +74,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
                 }).collect(Collectors.toList());
 
         List<OrgDto> orgList = this.listOrgAll(schoolId);
-        if (withoutPrintingRoom){
+        if (withoutPrintingRoom) {
             orgList = orgList.stream().filter(e -> !OrgTypeEnum.PRINTING_HOUSE.name().equals(e.getType())).collect(Collectors.toList());
         }
         Map<Long, OrgDto> map = orgList.stream()
@@ -127,9 +127,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
                 org.updateInfo(sysUser.getId());
                 success = this.updateById(org);
             }
-            if(Objects.isNull(commonCacheService.updateOrgCollegeLevelCache(schoolId))){
-                commonCacheService.removeOrgCollegeLevelCache(schoolId);
-            }
+            commonCacheService.removeOrgCollegeLevelCache(schoolId);
         } catch (Exception e) {
             if (e instanceof DuplicateKeyException) {
                 String errorColumn = e.getCause().toString();
@@ -399,9 +397,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
                 }
             }
         }
-        if(Objects.isNull(commonCacheService.updateOrgCollegeLevelCache(requestUser.getSchoolId()))){
-            commonCacheService.removeOrgCollegeLevelCache(requestUser.getSchoolId());
-        }
+        commonCacheService.removeOrgCollegeLevelCache(requestUser.getSchoolId());
         return map;
     }
 
@@ -414,13 +410,13 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
 
         List<SysOrg> orgList = this.findParentsByOrgId(orgId).stream().distinct().collect(Collectors.toList());
         List<SysOrg> schoolOrgList = orgList.stream().filter(e -> OrgTypeEnum.SCHOOL.equals(e.getType())).collect(Collectors.toList());
-        if (schoolOrgList.size() != 1){
+        if (schoolOrgList.size() != 1) {
             throw ExceptionResultEnum.ERROR.exception("学校信息异常");
         }
         SysOrg schoolOrg = schoolOrgList.get(0);
         Long schoolOrgId = schoolOrg.getId();
         List<SysOrg> collegeOrgList = orgList.stream().filter(e -> schoolOrgId.equals(e.getParentId())).collect(Collectors.toList());
-        if (collegeOrgList.size() != 1){
+        if (collegeOrgList.size() != 1) {
             throw ExceptionResultEnum.ERROR.exception("开课学院异常");
         }
         return collegeOrgList.get(0);
@@ -430,15 +426,15 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
     public List<SysOrg> findCollegeLevelOrgList(Long schoolId) {
         SysOrg schoolOrg = this.getOne(new QueryWrapper<SysOrg>()
                 .lambda()
-                .eq(SysOrg::getSchoolId,schoolId)
-                .eq(SysOrg::getType,OrgTypeEnum.SCHOOL));
+                .eq(SysOrg::getSchoolId, schoolId)
+                .eq(SysOrg::getType, OrgTypeEnum.SCHOOL));
 
         Long schoolOrgId = schoolOrg.getId();
 
         return this.list(new QueryWrapper<SysOrg>()
-                .lambda()
-                .eq(SysOrg::getSchoolId,schoolId)
-                .eq(SysOrg::getParentId,schoolOrgId))
+                        .lambda()
+                        .eq(SysOrg::getSchoolId, schoolId)
+                        .eq(SysOrg::getParentId, schoolOrgId))
                 .stream()
                 .filter(e -> !OrgTypeEnum.PRINTING_HOUSE.equals(e.getType()))
                 .collect(Collectors.toList());

+ 6 - 19
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysRoleServiceImpl.java

@@ -19,7 +19,6 @@ import org.slf4j.LoggerFactory;
 import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.security.NoSuchAlgorithmException;
@@ -115,15 +114,11 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
                 int count = (int) sysRolePrivilegeList.stream().filter(s -> relatedList.contains(s.getPrivilegeId())).count();
                 role.updateInfo(sysUser.getId());
                 sysRoleService.updateById(role);
-                if (Objects.isNull(commonCacheService.updateRoleCache(role.getId()))) {
-                    commonCacheService.removeRoleCache(role.getId());
-                }
+                commonCacheService.removeRoleCache(role.getId());
                 if (count != sysRolePrivilegeList.size() || count != finalRelatedSet.size()) {
                     sysRolePrivilegeService.removeByRoleId(role.getId());
                     sysRolePrivilegeService.saveBatch(role);//角色权限
-                    if (CollectionUtils.isEmpty(commonCacheService.updateRolePrivilegeCache(role.getId()))) {
-                        commonCacheService.removeRolePrivilegeCache(role.getId());
-                    }
+                    commonCacheService.removeRolePrivilegeCache(role.getId());
                     //绑定该角色的用户都需要清除鉴权缓存
                     List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(role.getId());
                     commonService.removeUserInfoBatch(sysUserRoleList.stream().map(SysUserRole::getUserId).collect(Collectors.toList()), true);
@@ -191,16 +186,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
                 int count = (int) sysRolePrivilegeList.stream().filter(s -> relatedList.contains(s.getPrivilegeId())).count();
                 role.updateInfo(sysUser.getId());
                 sysRoleService.updateById(role);
-                if (Objects.isNull(commonCacheService.updateRoleCache(role.getId()))) {
-                    commonCacheService.removeRoleCache(role.getId());
-                }
+                commonCacheService.removeRoleCache(role.getId());
                 if (count != sysRolePrivilegeList.size() || count != finalRelatedSet.size()) {
                     // 删除权限前先更新涉及特殊权限用户 -> 需要重新同步
                     sysRolePrivilegeService.removeByRoleId(role.getId());
                     sysRolePrivilegeService.saveBatch(role);//角色权限
-                    if (CollectionUtils.isEmpty(commonCacheService.updateRolePrivilegeCache(role.getId()))) {
-                        commonCacheService.removeRolePrivilegeCache(role.getId());
-                    }
+                    commonCacheService.removeRolePrivilegeCache(role.getId());
                     //绑定该角色的用户都需要清除鉴权缓存
                     List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(role.getId());
                     commonService.removeUserInfoBatch(sysUserRoleList.stream().map(s -> s.getUserId()).collect(Collectors.toList()), true);
@@ -235,9 +226,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
                 .set(SysRoleGroupMember::getEnable, role.getEnable());
         sysRoleGroupMemberService.update(sysRoleGroupMemberUpdateWrapper);
 
-        if (Objects.isNull(commonCacheService.updateRoleCache(role.getId()))) {
-            commonCacheService.removeRoleCache(role.getId());
-        }
+        commonCacheService.removeRoleCache(role.getId());
         //如果状态为禁用,需要踢下线重新登录
         if (!role.getEnable()) {
             List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(role.getId());
@@ -254,9 +243,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
         updateWrapper.lambda().set(SysRole::getEnable, role.getEnable()).eq(SysRole::getId, role.getId());
         this.update(updateWrapper);
 
-        if (Objects.isNull(commonCacheService.updateRoleCache(role.getId()))) {
-            commonCacheService.removeRoleCache(role.getId());
-        }
+        commonCacheService.removeRoleCache(role.getId());
         //如果状态为禁用,需要踢下线重新登录
         if (!role.getEnable()) {
             List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(role.getId());

+ 13 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysUserRoleServiceImpl.java

@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.List;
+import java.util.Set;
 
 /**
  * <p>
@@ -38,6 +39,18 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
         return sysUserRoleMapper.listByRoleId(id, sysUser.getSchoolId());
     }
 
+    /**
+     * 根据角色ids和学校id查找
+     *
+     * @param ids
+     * @param schoolId
+     * @return
+     */
+    @Override
+    public List<SysUserRole> listByRoleIdsAndSchoolId(Set<Long> ids, Long schoolId) {
+        return sysUserRoleMapper.listByRoleIdsAndSchoolId(ids, schoolId);
+    }
+
     @Override
     public List<SysRole> listRoleByUserId(Long userId) {
         return this.baseMapper.listRoleByUserId(userId);

+ 5 - 15
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysUserServiceImpl.java

@@ -161,9 +161,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
     public boolean enable(SysUser user) throws NoSuchAlgorithmException, IllegalAccessException {
         UpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<>();
         updateWrapper.lambda().set(SysUser::getEnable, user.getEnable()).eq(SysUser::getId, user.getId());
-        if (Objects.isNull(commonCacheService.updateUserCache(user.getId()))) {
-            commonCacheService.removeUserCache(user.getId());
-        }
+        commonCacheService.removeUserCache(user.getId());
         boolean success = this.update(updateWrapper);
         //如果状态为禁用,需要踢下线重新登录
         if (!user.getEnable()) {
@@ -556,12 +554,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
                 if (Objects.nonNull(dbUser.getOrgId())) {
                     if (dbUser.getOrgId().longValue() != sysUser.getOrgId().longValue()
                             || !Objects.equals(dbUser.getMobileNumber(), sysUser.getMobileNumber())) {
-                        if (Objects.isNull(commonCacheService.updateUserCache(sysUser.getId()))) {
-                            commonCacheService.removeUserCache(sysUser.getId());
-                        }
-                        if (Objects.isNull(commonCacheService.updateUserAuthCache(sysUser.getId()))) {
-                            commonCacheService.removeUserAuthCache(sysUser.getId());
-                        }
+                        commonCacheService.removeUserCache(sysUser.getId());
+                        commonCacheService.removeUserAuthCache(sysUser.getId());
                     }
                 }
 
@@ -655,12 +649,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
                 if (Objects.nonNull(dbUser.getOrgId())) {
                     if (containsQuestionTeacher || dbUser.getOrgId().longValue() != sysUser.getOrgId().longValue()
                             || !Objects.equals(dbUser.getMobileNumber(), sysUser.getMobileNumber())) {
-                        if (Objects.isNull(commonCacheService.updateUserCache(sysUser.getId()))) {
-                            commonCacheService.removeUserCache(sysUser.getId());
-                        }
-                        if (Objects.isNull(commonCacheService.updateUserAuthCache(sysUser.getId()))) {
-                            commonCacheService.removeUserAuthCache(sysUser.getId());
-                        }
+                        commonCacheService.removeUserCache(sysUser.getId());
+                        commonCacheService.removeUserAuthCache(sysUser.getId());
                     }
                 }
             }

+ 35 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TSchoolRoleServiceImpl.java

@@ -0,0 +1,35 @@
+package com.qmth.teachcloud.common.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.teachcloud.common.entity.TSchoolRole;
+import com.qmth.teachcloud.common.mapper.TSchoolRoleMapper;
+import com.qmth.teachcloud.common.service.TSchoolRoleService;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 学校角色权限表 服务实现类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2021-10-28
+ */
+@Service
+public class TSchoolRoleServiceImpl extends ServiceImpl<TSchoolRoleMapper, TSchoolRole> implements TSchoolRoleService {
+
+    /**
+     * 根据学校id查找自定义角色
+     *
+     * @param schoolId
+     * @return
+     */
+    @Override
+    public List<TSchoolRole> findBySchoolId(Long schoolId) {
+        QueryWrapper<TSchoolRole> tSchoolRoleQueryWrapper = new QueryWrapper<>();
+        tSchoolRoleQueryWrapper.lambda().eq(TSchoolRole::getSchoolId, schoolId);
+        return this.list(tSchoolRoleQueryWrapper);
+    }
+}

+ 13 - 13
teachcloud-common/src/main/resources/mapper/SysRoleMapper.xml

@@ -18,7 +18,7 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        select id, school_id, name, enable, type, create_id, create_time, update_id, update_time, default_role, interpret from sys_role
+        select t.id, t.school_id, t.name, t.enable, t.type, t.create_id, t.create_time, t.update_id, t.update_time, t.default_role, t.interpret from sys_role t
     </sql>
 
     <select id="listRolesByUserId" resultMap="BaseResultMap">
@@ -36,26 +36,26 @@
     </select>
 
     <select id="listPage" resultMap="BaseResultMap">
-        select * from(<include refid="Base_Column_List"></include>
+        select * from(<include refid="Base_Column_List" />
         <where>
             <if test="schoolId != null and schoolId != ''">
-                and school_id = #{schoolId}
+                and t.school_id = #{schoolId}
             </if>
             <if test="name != null and name != ''">
-                and name like concat('%', #{name}, '%')
+                and t.name like concat('%', #{name}, '%')
             </if>
             <if test="enable != null and enable != '' or enable == 0">
-                and enable = #{enable}
+                and t.enable = #{enable}
             </if>
         </where>
         union
-        select id, school_id, name, enable, type, create_id, create_time, update_id, update_time, default_role, interpret from sys_role
-        where default_role = 1 and type <![CDATA[ <> ]]> 'ADMIN'
+        <include refid="Base_Column_List" /> join t_school_role tsr on tsr.role_id = t.id and tsr.school_id = t.school_id
+        where t.default_role = 1 and t.type <![CDATA[ <> ]]> 'ADMIN'
             <if test="name != null and name != ''">
-                and name like concat('%', #{name}, '%')
+                and t.name like concat('%', #{name}, '%')
             </if>
             <if test="enable != null and enable != '' or enable == 0">
-                and enable = #{enable}
+                and t.enable = #{enable}
             </if>
             ) t
         ORDER BY t.create_time
@@ -64,13 +64,13 @@
     <select id="listRolesBySchoolId" resultMap="BaseResultMap">
         <include refid="Base_Column_List" />
         <where>
-            enable = 1
+            t.enable = 1
             <if test="schoolId != null and schoolId != ''">
-                and school_id = #{schoolId}
+                and t.school_id = #{schoolId}
             </if>
         </where>
         union
-        select id, school_id, name, enable, type, create_id, create_time, update_id, update_time, default_role, interpret from sys_role
-        where default_role = 1 and type <![CDATA[ <> ]]> 'ADMIN'
+        <include refid="Base_Column_List" /> join t_school_role tsr on tsr.role_id = t.id and tsr.school_id = t.school_id
+        where t.default_role = 1 and t.type <![CDATA[ <> ]]> 'ADMIN'
     </select>
 </mapper>

+ 20 - 0
teachcloud-common/src/main/resources/mapper/SysUserRoleMapper.xml

@@ -69,4 +69,24 @@
         </where>
     </select>
 
+    <select id="listByRoleIdsAndSchoolId" resultType="com.qmth.teachcloud.common.entity.SysUserRole">
+        select
+        *
+        from
+        sys_user_role sur
+        join sys_user su on
+        su.id = sur.user_id
+        <where>
+            <if test="ids != null and ids != '' and ids.size > 0">
+                and sur.role_id in
+                <foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
+                    #{id}
+                </foreach>
+            </if>
+            <if test="schoolId != null and schoolId != ''">
+                and su.school_id = #{schoolId}
+            </if>
+        </where>
+    </select>
+
 </mapper>

+ 5 - 0
teachcloud-common/src/main/resources/mapper/TSchoolRoleMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.qmth.teachcloud.common.mapper.TSchoolRoleMapper">
+
+</mapper>