wangliang пре 1 година
родитељ
комит
6601382235
25 измењених фајлова са 830 додато и 19 уклоњено
  1. 11 0
      sop-business/src/main/java/com/qmth/sop/business/bean/dto/RoleDto.java
  2. 58 0
      sop-business/src/main/java/com/qmth/sop/business/bean/params/SysRolePrivilegeParams.java
  3. 40 0
      sop-business/src/main/java/com/qmth/sop/business/bean/result/UserRoleNameResult.java
  4. 37 1
      sop-business/src/main/java/com/qmth/sop/business/entity/SysRole.java
  5. 12 0
      sop-business/src/main/java/com/qmth/sop/business/entity/SysRolePrivilege.java
  6. 12 0
      sop-business/src/main/java/com/qmth/sop/business/mapper/SysRoleMapper.java
  7. 9 0
      sop-business/src/main/java/com/qmth/sop/business/mapper/SysUserMapper.java
  8. 8 0
      sop-business/src/main/java/com/qmth/sop/business/mapper/SysUserRoleMapper.java
  9. 8 0
      sop-business/src/main/java/com/qmth/sop/business/service/SysRolePrivilegeService.java
  10. 31 0
      sop-business/src/main/java/com/qmth/sop/business/service/SysRoleService.java
  11. 8 0
      sop-business/src/main/java/com/qmth/sop/business/service/SysUserRoleService.java
  12. 16 0
      sop-business/src/main/java/com/qmth/sop/business/service/SysUserService.java
  13. 57 0
      sop-business/src/main/java/com/qmth/sop/business/service/impl/SysRolePrivilegeServiceImpl.java
  14. 127 1
      sop-business/src/main/java/com/qmth/sop/business/service/impl/SysRoleServiceImpl.java
  15. 11 1
      sop-business/src/main/java/com/qmth/sop/business/service/impl/SysUserRoleServiceImpl.java
  16. 72 0
      sop-business/src/main/java/com/qmth/sop/business/service/impl/SysUserServiceImpl.java
  17. 214 0
      sop-business/src/main/resources/db/log/wangliang_update_log.sql
  18. 14 0
      sop-business/src/main/resources/mapper/SysRoleMapper.xml
  19. 15 0
      sop-business/src/main/resources/mapper/SysUserMapper.xml
  20. 12 11
      sop-business/src/main/resources/mapper/SysUserRoleMapper.xml
  21. 2 0
      sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java
  22. 2 0
      sop-common/src/main/java/com/qmth/sop/common/enums/ExceptionResultEnum.java
  23. 3 1
      sop-common/src/main/java/com/qmth/sop/common/enums/FieldUniqueEnum.java
  24. 3 1
      sop-common/src/main/java/com/qmth/sop/common/enums/RoleTypeEnum.java
  25. 48 3
      sop-server/src/main/java/com/qmth/sop/server/api/SysRoleController.java

+ 11 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/dto/RoleDto.java

@@ -29,6 +29,17 @@ public class RoleDto implements Serializable {
     @ApiModelProperty(value = "角色类别,ADMIN:超级管理员,PMO:总负责人,BUSSINESS:业务线负责人,REGION_MANAGER:大区经理,REGION_COORDINATOR:区域协调人,EFFECT_ENGINEER:实施工程师,ASSISTANT_ENGINEER:助理工程师,QA:QA,CUSTOM:技术客服")
     private RoleTypeEnum type;
 
+    @ApiModelProperty(value = "是否系统内置角色,1:是,0:不是")
+    private Boolean defaultRole;
+
+    public Boolean getDefaultRole() {
+        return defaultRole;
+    }
+
+    public void setDefaultRole(Boolean defaultRole) {
+        this.defaultRole = defaultRole;
+    }
+
     public Long getId() {
         return id;
     }

+ 58 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/params/SysRolePrivilegeParams.java

@@ -0,0 +1,58 @@
+package com.qmth.sop.business.bean.params;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.common.enums.RoleTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+import org.hibernate.validator.constraints.Length;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @Description: 用户角色权限编辑参数
+ * @Author: CaoZixuan
+ * @Date: 2022-12-06
+ */
+public class SysRolePrivilegeParams implements Serializable {
+
+    @ApiModelProperty("角色id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long id;
+
+    @ApiModelProperty("角色名称")
+    @NotNull(message = "请输入角色名称")
+    @Length(min = 1, message = "请输入角色名称")
+    private String name;
+
+    @ApiModelProperty("权限id数组")
+    @NotEmpty(message = "权限集合不能为空")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private List<Long> privilegeIds;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public List<Long> getPrivilegeIds() {
+        return privilegeIds;
+    }
+
+    public void setPrivilegeIds(List<Long> privilegeIds) {
+        this.privilegeIds = privilegeIds;
+    }
+}

+ 40 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/UserRoleNameResult.java

@@ -0,0 +1,40 @@
+package com.qmth.sop.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description: 批量查询用户角色
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/12/21
+ */
+public class UserRoleNameResult implements Serializable {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "用户id")
+    private Long userId;
+
+    @ApiModelProperty(value = "用户角色名")
+    private String roleNames;
+
+    public Long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+
+    public String getRoleNames() {
+        return roleNames;
+    }
+
+    public void setRoleNames(String roleNames) {
+        this.roleNames = roleNames;
+    }
+}

+ 37 - 1
sop-business/src/main/java/com/qmth/sop/business/entity/SysRole.java

@@ -1,13 +1,19 @@
 package com.qmth.sop.business.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.business.bean.params.SysRolePrivilegeParams;
 import com.qmth.sop.common.base.BaseEntity;
+import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.RoleTypeEnum;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
+import javax.validation.constraints.NotEmpty;
 import java.io.Serializable;
+import java.util.List;
+import java.util.Objects;
 
 /**
  * <p>
@@ -32,7 +38,7 @@ public class SysRole extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "是否启用,0:停用,1:启用")
     private Boolean enable;
 
-    @ApiModelProperty(value = "角色类别,ADMIN:超级管理员,PMO:总负责人,BUSSINESS:业务线负责人,REGION_MANAGER:大区经理,REGION_COORDINATOR:区域协调人,EFFECT_ENGINEER:实施工程师,ASSISTANT_ENGINEER:助理工程师,QA:QA,CUSTOM:技术客服")
+    @ApiModelProperty(value = "角色类别,ADMIN:超级管理员,PMO:总负责人,BUSSINESS:业务线负责人,REGION_MANAGER:大区经理,REGION_COORDINATOR:区域协调人,EFFECT_ENGINEER:实施工程师,ASSISTANT_ENGINEER:助理工程师,QA:QA,CUSTOM:技术客服,DEFINED:自定义")
     private RoleTypeEnum type;
 
     @ApiModelProperty(value = "是否系统内置角色,1:是,0:不是")
@@ -41,6 +47,36 @@ public class SysRole extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "角色说明")
     private String interpret;
 
+    @JsonSerialize(using = ToStringSerializer.class)
+    @TableField(exist = false)
+    @NotEmpty(message = "权限集合不能为空")
+    private List<Long> privilegeIds;
+
+    public SysRole() {
+
+    }
+
+    public SysRole(SysRolePrivilegeParams sysRolePrivilegeParams) {
+        if (Objects.nonNull(sysRolePrivilegeParams.getId())) {
+            setId(sysRolePrivilegeParams.getId());
+        } else {
+            setId(SystemConstant.getDbUuid());
+        }
+        this.name = sysRolePrivilegeParams.getName();
+        this.type = RoleTypeEnum.DEFINED;
+        this.defaultRole = false;
+        this.interpret = RoleTypeEnum.DEFINED.getTitle();
+        this.privilegeIds = sysRolePrivilegeParams.getPrivilegeIds();
+    }
+
+    public List<Long> getPrivilegeIds() {
+        return privilegeIds;
+    }
+
+    public void setPrivilegeIds(List<Long> privilegeIds) {
+        this.privilegeIds = privilegeIds;
+    }
+
     public Long getOrgId() {
         return orgId;
     }

+ 12 - 0
sop-business/src/main/java/com/qmth/sop/business/entity/SysRolePrivilege.java

@@ -2,6 +2,7 @@ package com.qmth.sop.business.entity;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.common.contant.SystemConstant;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -35,6 +36,17 @@ public class SysRolePrivilege implements Serializable {
     @ApiModelProperty(value = "是否启用,0:停用,1:启用")
     private Boolean enable;
 
+    public SysRolePrivilege() {
+
+    }
+
+    public SysRolePrivilege(Long roleId, Long privilegeId) {
+        this.id = SystemConstant.getDbUuid();
+        this.roleId = roleId;
+        this.privilegeId = privilegeId;
+        this.enable = true;
+    }
+
     public Long getId() {
         return id;
     }

+ 12 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/SysRoleMapper.java

@@ -1,11 +1,13 @@
 package com.qmth.sop.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.qmth.sop.business.bean.dto.RoleDto;
 import com.qmth.sop.business.entity.SysRole;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -24,4 +26,14 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
      * @return
      */
     List<RoleDto> listRolesByUserId(@Param("userId") Long userId);
+
+    /**
+     * 查询角色列表
+     *
+     * @param iPage
+     * @param name
+     * @param enable
+     * @return
+     */
+    IPage<RoleDto> query(IPage<Map> iPage, @Param("name") String name, @Param("enable") Boolean enable);
 }

+ 9 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/SysUserMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.qmth.sop.business.bean.dto.UserDto;
 import com.qmth.sop.business.bean.dto.VerifyCodeCheckDto;
 import com.qmth.sop.business.bean.result.SysUserResult;
+import com.qmth.sop.business.bean.result.UserRoleNameResult;
 import com.qmth.sop.business.entity.SysUser;
 import org.apache.ibatis.annotations.Param;
 
@@ -66,4 +67,12 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
      * @return
      */
     IPage<UserDto> query(IPage<Map> iPage, @Param("userInfo") String userInfo, @Param("orgId") Long orgId, @Param("roleId") Long roleId, @Param("enable") Boolean enable);
+
+    /**
+     * 查找用户角色名
+     *
+     * @param userIds
+     * @return
+     */
+    List<UserRoleNameResult> selectRoleNames(@Param("userIds") List<Long> userIds);
 }

+ 8 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/SysUserRoleMapper.java

@@ -23,4 +23,12 @@ public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
      * @return 角色集合
      */
     List<SysRole> listRoleByUserId(@Param("userId") Long userId);
+
+    /**
+     * 根据角色id查询用户信息
+     *
+     * @param roleId
+     * @return
+     */
+    List<SysUserRole> listByRoleId(@Param("roleId") Long roleId);
 }

+ 8 - 0
sop-business/src/main/java/com/qmth/sop/business/service/SysRolePrivilegeService.java

@@ -1,6 +1,7 @@
 package com.qmth.sop.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.sop.business.entity.SysRole;
 import com.qmth.sop.business.entity.SysRolePrivilege;
 
 /**
@@ -13,4 +14,11 @@ import com.qmth.sop.business.entity.SysRolePrivilege;
  */
 public interface SysRolePrivilegeService extends IService<SysRolePrivilege> {
 
+    /**
+     * 批量保存角色权限
+     *
+     * @param role
+     * @return
+     */
+    Boolean saveBatch(SysRole role);
 }

+ 31 - 0
sop-business/src/main/java/com/qmth/sop/business/service/SysRoleService.java

@@ -1,10 +1,14 @@
 package com.qmth.sop.business.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.dto.RoleDto;
+import com.qmth.sop.business.bean.params.SysRolePrivilegeParams;
 import com.qmth.sop.business.entity.SysRole;
 
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -23,4 +27,31 @@ public interface SysRoleService extends IService<SysRole> {
      * @return
      */
     List<RoleDto> listRolesByUserId(Long userId);
+
+    /**
+     * 查询角色列表
+     *
+     * @param iPage
+     * @param name
+     * @param enable
+     * @return
+     */
+    IPage<RoleDto> query(IPage<Map> iPage, String name, Boolean enable);
+
+    /**
+     * 新增/修改角色
+     *
+     * @param sysRolePrivilegeParams
+     * @return
+     */
+    Boolean saveRole(SysRolePrivilegeParams sysRolePrivilegeParams);
+
+    /**
+     * 根据id删除角色
+     *
+     * @param roleId
+     * @return
+     * @throws NoSuchAlgorithmException
+     */
+    Boolean deleteRole(Long roleId) throws NoSuchAlgorithmException;
 }

+ 8 - 0
sop-business/src/main/java/com/qmth/sop/business/service/SysUserRoleService.java

@@ -40,4 +40,12 @@ public interface SysUserRoleService extends IService<SysUserRole> {
      * @param roleIds
      */
     public void addUserRolePrivilege(SysUser sysUser, Long[] roleIds);
+
+    /**
+     * 根据角色id查询用户信息
+     *
+     * @param roleId
+     * @return
+     */
+    List<SysUserRole> listByRoleId(Long roleId);
 }

+ 16 - 0
sop-business/src/main/java/com/qmth/sop/business/service/SysUserService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.dto.UserDto;
 import com.qmth.sop.business.bean.result.LoginResult;
 import com.qmth.sop.business.bean.result.SysUserResult;
+import com.qmth.sop.business.bean.result.UserRoleNameResult;
 import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.common.enums.AppSourceEnum;
 
@@ -41,6 +42,14 @@ public interface SysUserService extends IService<SysUser> {
      */
     public Boolean removeUserInfo(Long userId, boolean all) throws NoSuchAlgorithmException;
 
+    /**
+     * 批量删除用户信息
+     *
+     * @param userIds
+     * @param all
+     */
+    public void removeUserInfoBatch(List<Long> userIds, boolean all);
+
     /**
      * 根据机构id查询用户
      *
@@ -96,4 +105,11 @@ public interface SysUserService extends IService<SysUser> {
 
     List<SysUser> listEnable();
 
+    /**
+     * 查找用户角色名
+     *
+     * @param userIds
+     * @return
+     */
+    List<UserRoleNameResult> selectRoleNames(List<Long> userIds);
 }

+ 57 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysRolePrivilegeServiceImpl.java

@@ -1,10 +1,20 @@
 package com.qmth.sop.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.sop.business.cache.CommonCacheService;
+import com.qmth.sop.business.entity.SysPrivilege;
+import com.qmth.sop.business.entity.SysRole;
 import com.qmth.sop.business.entity.SysRolePrivilege;
 import com.qmth.sop.business.mapper.SysRolePrivilegeMapper;
+import com.qmth.sop.business.service.SysPrivilegeService;
 import com.qmth.sop.business.service.SysRolePrivilegeService;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -17,4 +27,51 @@ import org.springframework.stereotype.Service;
 @Service
 public class SysRolePrivilegeServiceImpl extends ServiceImpl<SysRolePrivilegeMapper, SysRolePrivilege> implements SysRolePrivilegeService {
 
+    @Resource
+    CommonCacheService commonCacheService;
+
+    @Resource
+    SysPrivilegeService sysPrivilegeService;
+
+    /**
+     * 批量保存角色权限
+     *
+     * @param role
+     * @return
+     */
+    @Override
+    @Transactional
+    public Boolean saveBatch(SysRole role) {
+        List<SysRolePrivilege> sysRolePrivilegeList = commonCacheService.rolePrivilegeCache(role.getId());
+        List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(new QueryWrapper<SysPrivilege>().lambda().in(SysPrivilege::getId, role.getPrivilegeIds()));
+
+        Set<String> relatedSet = sysPrivilegeList.stream().filter(s -> Objects.nonNull(s.getRelated())).map(s -> s.getRelated()).collect(Collectors.toSet());
+        Set<Long> finalRelatedSet = new HashSet<>(role.getPrivilegeIds());
+        for (String s : relatedSet) {
+            if (s.contains(",")) {
+                String[] arrays = s.split(",");
+                for (int i = 0; i < arrays.length; i++) {
+                    finalRelatedSet.add(Long.parseLong(arrays[i].trim()));
+                }
+            } else {
+                finalRelatedSet.add(Long.parseLong(s));
+            }
+        }
+        // 修改后权限集合
+        List<Long> relatedList = new ArrayList<>(finalRelatedSet);
+        List<Long> finalRelatedList = relatedList;
+        int count = (int) sysRolePrivilegeList.stream().filter(s -> finalRelatedList.contains(s.getPrivilegeId())).count();
+        if (count != sysRolePrivilegeList.size() || count != finalRelatedSet.size()) {
+            //学校角色编辑超管
+            List<Long> sysRolePrivilegeIdList = sysRolePrivilegeList.stream().map(SysRolePrivilege::getPrivilegeId).collect(Collectors.toList());
+            relatedList = relatedList.stream().filter(m -> !sysRolePrivilegeIdList.contains(m)).collect(Collectors.toList());
+            List<SysRolePrivilege> list = new ArrayList<>();
+            for (Long privilegeId : relatedList) {
+                list.add(new SysRolePrivilege(role.getId(), privilegeId));
+            }
+            this.saveBatch(list);
+            return true;
+        }
+        return false;
+    }
 }

+ 127 - 1
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysRoleServiceImpl.java

@@ -1,13 +1,34 @@
 package com.qmth.sop.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.api.exception.ApiException;
 import com.qmth.sop.business.bean.dto.RoleDto;
+import com.qmth.sop.business.bean.params.SysRolePrivilegeParams;
+import com.qmth.sop.business.cache.CommonCacheService;
 import com.qmth.sop.business.entity.SysRole;
+import com.qmth.sop.business.entity.SysRolePrivilege;
+import com.qmth.sop.business.entity.SysUser;
+import com.qmth.sop.business.entity.SysUserRole;
 import com.qmth.sop.business.mapper.SysRoleMapper;
-import com.qmth.sop.business.service.SysRoleService;
+import com.qmth.sop.business.service.*;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import com.qmth.sop.common.enums.FieldUniqueEnum;
+import com.qmth.sop.common.util.ResultUtil;
+import com.qmth.sop.common.util.ServletUtil;
+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;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -20,6 +41,18 @@ import java.util.List;
 @Service
 public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
 
+    @Resource
+    CommonCacheService commonCacheService;
+
+    @Resource
+    SysRolePrivilegeService sysRolePrivilegeService;
+
+    @Resource
+    SysUserRoleService sysUserRoleService;
+
+    @Resource
+    SysUserService sysUserService;
+
     /**
      * 根据userId查询角色
      *
@@ -30,4 +63,97 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
     public List<RoleDto> listRolesByUserId(Long userId) {
         return this.baseMapper.listRolesByUserId(userId);
     }
+
+    /**
+     * 查询角色列表
+     *
+     * @param iPage
+     * @param name
+     * @param enable
+     * @return
+     */
+    @Override
+    public IPage<RoleDto> query(IPage<Map> iPage, String name, Boolean enable) {
+        return this.baseMapper.query(iPage, name, enable);
+    }
+
+    /**
+     * 新增/修改角色
+     *
+     * @param sysRolePrivilegeParams
+     * @return
+     */
+    @Override
+    @Transactional
+    public Boolean saveRole(SysRolePrivilegeParams sysRolePrivilegeParams) {
+        try {
+            SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+            SysRole role = new SysRole(sysRolePrivilegeParams);
+            //编辑
+            if (Objects.nonNull(sysRolePrivilegeParams.getId())) {
+                SysRole sysRoleDb = this.getById(sysRolePrivilegeParams.getId());
+                Optional.ofNullable(sysRoleDb).orElseThrow(() -> ExceptionResultEnum.ROLE_NO_EXISTS.exception());
+
+                role.setType(sysRoleDb.getType());
+                role.setDefaultRole(sysRoleDb.getDefaultRole());
+                role.setInterpret(sysRoleDb.getType().getTitle());
+                role.updateInfo(sysUser.getId());
+                this.updateById(role);
+                commonCacheService.updateRoleCache(role.getId());
+                boolean isChange = sysRolePrivilegeService.saveBatch(role);//角色权限
+                if (isChange) {
+                    commonCacheService.updateRolePrivilegeCache(role.getId());
+                    //绑定该角色的用户都需要清除鉴权缓存
+                    List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(role.getId());
+                    sysUserService.removeUserInfoBatch(sysUserRoleList.stream().map(SysUserRole::getUserId).collect(Collectors.toList()), true);
+                }
+            } else {
+                role.insertInfo(sysUser.getId());
+                this.save(role);
+                sysRolePrivilegeService.saveBatch(role);//角色权限
+            }
+        } catch (Exception e) {
+            if (e instanceof DuplicateKeyException) {
+                String errorColumn = e.getCause().toString();
+                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
+                throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
+            } else if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return true;
+    }
+
+    /**
+     * 根据id删除角色
+     *
+     * @param roleId
+     * @return
+     * @throws NoSuchAlgorithmException
+     */
+    @Override
+    @Transactional
+    public Boolean deleteRole(Long roleId) throws NoSuchAlgorithmException {
+        SysRole sysRole = this.getById(roleId);
+        Optional.ofNullable(sysRole).orElseThrow(() -> ExceptionResultEnum.ROLE_NO_EXISTS.exception());
+        if (sysRole.getDefaultRole()) {
+            throw ExceptionResultEnum.EXCEPTION_ERROR.exception("系统默认角色不允许删除");
+        }
+
+        List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(roleId);
+        if (!CollectionUtils.isEmpty(sysUserRoleList)) {
+            throw ExceptionResultEnum.EXCEPTION_ERROR.exception("该角色已绑定用户,不允许删除");
+        }
+        boolean success = this.removeById(roleId);
+        if (success) {
+            sysRolePrivilegeService.remove(new QueryWrapper<SysRolePrivilege>().lambda().eq(SysRolePrivilege::getRoleId, roleId));
+            commonCacheService.removeRoleCache(roleId);
+            sysUserRoleList.forEach(s -> {
+                commonCacheService.removeUserRolePrivilegeCache(s.getUserId());
+            });
+        }
+        return success;
+    }
 }

+ 11 - 1
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysUserRoleServiceImpl.java

@@ -13,7 +13,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.List;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -62,4 +61,15 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
         }
         this.saveBatch(sysUserRoleList);
     }
+
+    /**
+     * 根据角色id查询用户信息
+     *
+     * @param roleId
+     * @return
+     */
+    @Override
+    public List<SysUserRole> listByRoleId(Long roleId) {
+        return this.baseMapper.listByRoleId(roleId);
+    }
 }

+ 72 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysUserServiceImpl.java

@@ -12,6 +12,7 @@ import com.qmth.sop.business.bean.dto.UserDto;
 import com.qmth.sop.business.bean.dto.VerifyCodeCheckDto;
 import com.qmth.sop.business.bean.result.LoginResult;
 import com.qmth.sop.business.bean.result.SysUserResult;
+import com.qmth.sop.business.bean.result.UserRoleNameResult;
 import com.qmth.sop.business.cache.CommonCacheService;
 import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.mapper.SysUserMapper;
@@ -129,10 +130,71 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         }
         commonCacheService.removeUserCache(userId);
         commonCacheService.removeUserAuthCache(userId);
+        commonCacheService.removeUserMenuCache(userId);
         commonCacheService.removeUserRolePrivilegeCache(userId);
         return true;
     }
 
+    /**
+     * 批量删除用户信息
+     *
+     * @param userIds
+     * @param all
+     */
+    @Override
+    public void removeUserInfoBatch(List<Long> userIds, boolean all) {
+        if (!CollectionUtils.isEmpty(userIds)) {
+            new Thread(() -> {
+                if (all) {
+                    Set<String> sessionIdSet = new HashSet<>(Platform.values().length * userIds.size());
+                    int min = 0;
+                    int max = SystemConstant.IN_SIZE_MAX, size = userIds.size();
+                    if (max >= size) {
+                        max = size;
+                    }
+                    while (max <= size) {
+                        List<UserRoleNameResult> userRoleNameResultList = this.selectRoleNames(userIds.subList(min, max));
+                        for (UserRoleNameResult userRoleNameResult : userRoleNameResultList) {
+                            List<String> roleNames = Arrays.asList(userRoleNameResult.getRoleNames().split(","));
+                            Collections.sort(roleNames);
+                            for (Platform p : Platform.values()) {
+                                String sessionId = null;
+                                try {
+                                    sessionId = SessionUtil.digest(userRoleNameResult.getUserId(), Math.abs(roleNames.toString().hashCode()), p.name());
+                                } catch (NoSuchAlgorithmException e) {
+                                    e.printStackTrace();
+                                }
+                                sessionIdSet.add(sessionId);
+                            }
+                        }
+                        if (max == size) {
+                            break;
+                        }
+                        min = max;
+                        max += SystemConstant.IN_SIZE_MAX;
+                        if (max >= size) {
+                            max = size;
+                        }
+                    }
+                    tbSessionService.removeByIds(sessionIdSet);
+                    for (String s : sessionIdSet) {
+                        commonCacheService.deleteUserSession(s);
+                    }
+                } else {
+                    TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
+                    tbSessionService.removeById(tbSession.getId());
+                    commonCacheService.deleteUserSession(tbSession.getId());
+                }
+                for (Long l : userIds) {
+                    commonCacheService.removeUserCache(l);
+                    commonCacheService.removeUserAuthCache(l);
+                    commonCacheService.removeUserMenuCache(l);
+                    commonCacheService.removeUserRolePrivilegeCache(l);
+                }
+            }).start();
+        }
+    }
+
     /**
      * 根据机构id查询用户
      *
@@ -319,6 +381,16 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
     @Override
     public List<SysUser> listEnable() {
         return this.list(new QueryWrapper<SysUser>().lambda().eq(SysUser::getEnable, true));
+    }
 
+    /**
+     * 查找用户角色名
+     *
+     * @param userIds
+     * @return
+     */
+    @Override
+    public List<UserRoleNameResult> selectRoleNames(List<Long> userIds) {
+        return this.baseMapper.selectRoleNames(userIds);
     }
 }

+ 214 - 0
sop-business/src/main/resources/db/log/wangliang_update_log.sql

@@ -69,3 +69,217 @@ VALUES(286, '获取所有用户', '/api/admin/common/get_user_list', 'URL', 64,
 INSERT INTO sys_privilege
 (id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
 VALUES(287, '获取所有机构', '/api/admin/common/get_org_list', 'URL', 64, 12, 'SYS', NULL, 1, 1, 0);
+INSERT INTO sys_privilege
+(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
+VALUES(288, '角色查询', '/api/admin/role/list', 'URL', 16, 1, 'AUTH', '123', 1, 1, 0);
+INSERT INTO sys_privilege
+(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
+VALUES(289, '角色新增/修改', '/api/admin/role/save', 'URL', 16, 2, 'AUTH', '124,125', 1, 1, 0);
+INSERT INTO sys_privilege
+(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
+VALUES(290, '角色删除', '/api/admin/role/delete', 'URL', 16, 3, 'AUTH', '126', 1, 1, 0);
+
+ALTER TABLE sys_org ADD CONSTRAINT sys_org_UN_name UNIQUE KEY (name);
+ALTER TABLE sys_user ADD CONSTRAINT sys_user_UN_login_name UNIQUE KEY (org_id,login_name);
+ALTER TABLE sys_user ADD CONSTRAINT sys_user_UN_moblie_number UNIQUE KEY (org_id,mobile_number);
+ALTER TABLE sys_role ADD CONSTRAINT sys_role_UN_type UNIQUE KEY (name,`type`);
+
+UPDATE sys_privilege
+SET name='列表', url='List', `type`='LIST', parent_id=6, `sequence`=1, property='AUTH', related='256', enable=1, default_auth=0, front_display=1
+WHERE id=89;
+UPDATE sys_privilege
+SET name='新增', url='Add', `type`='BUTTON', parent_id=6, `sequence`=1, property='AUTH', related='254', enable=1, default_auth=0, front_display=1
+WHERE id=90;
+UPDATE sys_privilege
+SET name='修改', url='Update', `type`='LINK', parent_id=6, `sequence`=1, property='AUTH', related='254,257', enable=1, default_auth=0, front_display=1
+WHERE id=91;
+UPDATE sys_privilege
+SET name='删除', url='Delete', `type`='LINK', parent_id=6, `sequence`=2, property='AUTH', related='253', enable=1, default_auth=0, front_display=1
+WHERE id=92;
+UPDATE sys_privilege
+SET name='查询', url='Select', `type`='BUTTON', parent_id=15, `sequence`=2, property='AUTH', related='252', enable=1, default_auth=0, front_display=1
+WHERE id=122;
+UPDATE sys_privilege
+SET name='用户查询', url='/api/admin/user/list', `type`='URL', parent_id=15, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=252;
+UPDATE sys_privilege
+SET name='服务档位删除', url='/api/sys/level/delete', `type`='URL', parent_id=6, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=253;
+UPDATE sys_privilege
+SET name='服务档位', url='/api/sys/level/get', `type`='URL', parent_id=6, `sequence`=3, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=254;
+UPDATE sys_privilege
+SET name='服务档位列表', url='/api/sys/level/query', `type`='URL', parent_id=6, `sequence`=5, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=256;
+UPDATE sys_privilege
+SET name='服务档位修改', url='/api/sys/level/update', `type`='URL', parent_id=6, `sequence`=6, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=257;
+UPDATE sys_privilege
+SET name='客户新增', url='/api/sys/custom/add', `type`='URL', parent_id=3, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=258;
+UPDATE sys_privilege
+SET name='客户删除', url='/api/sys/custom/delete', `type`='URL', parent_id=3, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=259;
+UPDATE sys_privilege
+SET name='客户查询', url='/api/sys/custom/get', `type`='URL', parent_id=3, `sequence`=3, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=260;
+UPDATE sys_privilege
+SET name='客户批量导入', url='/api/sys/custom/import', `type`='URL', parent_id=3, `sequence`=4, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=261;
+UPDATE sys_privilege
+SET name='客户查询条件', url='/api/sys/custom/query', `type`='URL', parent_id=3, `sequence`=5, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=262;
+UPDATE sys_privilege
+SET name='客户修改', url='/api/sys/custom/update', `type`='URL', parent_id=3, `sequence`=6, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=263;
+UPDATE sys_privilege
+SET name='查询', url='Select', `type`='BUTTON', parent_id=3, `sequence`=3, property='AUTH', related='262', enable=1, default_auth=0, front_display=1
+WHERE id=75;
+UPDATE sys_privilege
+SET name='修改', url='Update', `type`='LINK', parent_id=3, `sequence`=1, property='AUTH', related='260,263', enable=1, default_auth=0, front_display=1
+WHERE id=77;
+UPDATE sys_privilege
+SET name='删除', url='Delete', `type`='LINK', parent_id=3, `sequence`=2, property='AUTH', related='259,260', enable=1, default_auth=0, front_display=1
+WHERE id=78;
+UPDATE sys_privilege
+SET name='新增', url='Add', `type`='BUTTON', parent_id=3, `sequence`=1, property='AUTH', related='258', enable=1, default_auth=0, front_display=1
+WHERE id=79;
+UPDATE sys_privilege
+SET name='批量导入', url='BatchImport', `type`='BUTTON', parent_id=3, `sequence`=2, property='AUTH', related='261', enable=1, default_auth=0, front_display=1
+WHERE id=80;
+UPDATE sys_privilege
+SET name='供应商新增', url='/api/sys/supplier/add', `type`='URL', parent_id=4, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=264;
+UPDATE sys_privilege
+SET name='供应商启用/禁用', url='/api/sys/supplier/enable', `type`='URL', parent_id=4, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=265;
+UPDATE sys_privilege
+SET name='供应商列表', url='/api/sys/supplier/get', `type`='URL', parent_id=4, `sequence`=3, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=266;
+UPDATE sys_privilege
+SET name='供应商列表', url='/api/sys/supplier/query', `type`='URL', parent_id=4, `sequence`=5, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=268;
+UPDATE sys_privilege
+SET name='供应商修改', url='/api/sys/supplier/update', `type`='URL', parent_id=4, `sequence`=6, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=269;
+UPDATE sys_privilege
+SET name='设备新增', url='/api/sys/device/add', `type`='URL', parent_id=5, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=270;
+UPDATE sys_privilege
+SET name='设备作废', url='/api/sys/device/delete', `type`='URL', parent_id=5, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=271;
+UPDATE sys_privilege
+SET name='设备作废', url='/api/sys/device/disable', `type`='URL', parent_id=5, `sequence`=3, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=272;
+UPDATE sys_privilege
+SET name='设备查询条件', url='/api/sys/device/get', `type`='URL', parent_id=5, `sequence`=4, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=273;
+UPDATE sys_privilege
+SET name='设备查询条件', url='/api/sys/device/query', `type`='URL', parent_id=5, `sequence`=6, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=275;
+UPDATE sys_privilege
+SET name='设备新增', url='/api/sys/device/update', `type`='URL', parent_id=5, `sequence`=7, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=276;
+UPDATE sys_privilege
+SET name='考勤新增', url='/api/sys/ding/group/add', `type`='URL', parent_id=7, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=277;
+UPDATE sys_privilege
+SET name='考勤删除', url='/api/sys/ding/group/delete', `type`='URL', parent_id=7, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=278;
+UPDATE sys_privilege
+SET name='考勤查询', url='/api/sys/ding/group/get', `type`='URL', parent_id=7, `sequence`=3, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=279;
+UPDATE sys_privilege
+SET name='考勤查询条件', url='/api/sys/ding/group/query', `type`='URL', parent_id=7, `sequence`=5, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=281;
+UPDATE sys_privilege
+SET name='考勤修改', url='/api/sys/ding/group/update', `type`='URL', parent_id=7, `sequence`=6, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=282;
+UPDATE sys_privilege
+SET name='用户新增/修改', url='/api/admin/user/save', `type`='URL', parent_id=15, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=283;
+UPDATE sys_privilege
+SET name='用户启用/禁用', url='/api/admin/user/enable', `type`='URL', parent_id=15, `sequence`=3, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=284;
+UPDATE sys_privilege
+SET name='角色查询', url='/api/admin/role/list', `type`='URL', parent_id=16, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=288;
+UPDATE sys_privilege
+SET name='角色新增/修改', url='/api/admin/role/save', `type`='URL', parent_id=16, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=289;
+UPDATE sys_privilege
+SET name='角色删除', url='/api/admin/role/delete', `type`='URL', parent_id=16, `sequence`=3, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
+WHERE id=290;
+UPDATE sys_privilege
+SET name='新增', url='Add', `type`='BUTTON', parent_id=4, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=81;
+UPDATE sys_privilege
+SET name='列表', url='List', `type`='LIST', parent_id=4, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=82;
+UPDATE sys_privilege
+SET name='修改', url='Update', `type`='LINK', parent_id=4, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=83;
+UPDATE sys_privilege
+SET name='启用/禁用', url='Enable', `type`='LINK', parent_id=4, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=84;
+UPDATE sys_privilege
+SET name='列表', url='List', `type`='LIST', parent_id=5, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=85;
+UPDATE sys_privilege
+SET name='查询条件', url='Condition', `type`='CONDITION', parent_id=5, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=86;
+UPDATE sys_privilege
+SET name='新增', url='Add', `type`='BUTTON', parent_id=5, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=87;
+UPDATE sys_privilege
+SET name='作废', url='Cancel', `type`='BUTTON', parent_id=5, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=88;
+UPDATE sys_privilege
+SET name='新增', url='Add', `type`='BUTTON', parent_id=7, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=94;
+UPDATE sys_privilege
+SET name='修改', url='Update', `type`='LINK', parent_id=7, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=95;
+UPDATE sys_privilege
+SET name='删除', url='Delete', `type`='LINK', parent_id=7, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=96;
+UPDATE sys_privilege
+SET name='查询', url='Select', `type`='BUTTON', parent_id=7, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=106;
+UPDATE sys_privilege
+SET name='修改', url='Update', `type`='LINK', parent_id=15, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=120;
+UPDATE sys_privilege
+SET name='启用/禁用', url='Enable', `type`='LINK', parent_id=15, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=121;
+UPDATE sys_privilege
+SET name='列表', url='List', `type`='LIST', parent_id=16, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=123;
+UPDATE sys_privilege
+SET name='新增', url='Add', `type`='BUTTON', parent_id=16, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=124;
+UPDATE sys_privilege
+SET name='修改', url='Update', `type`='LINK', parent_id=16, `sequence`=1, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=125;
+UPDATE sys_privilege
+SET name='删除', url='Delete', `type`='LINK', parent_id=16, `sequence`=2, property='AUTH', related=NULL, enable=1, default_auth=0, front_display=1
+WHERE id=126;
+UPDATE sys_privilege
+SET name='列表', url='List', `type`='LIST', parent_id=16, `sequence`=1, property='AUTH', related='288', enable=1, default_auth=0, front_display=1
+WHERE id=123;
+UPDATE sys_privilege
+SET name='新增', url='Add', `type`='BUTTON', parent_id=16, `sequence`=1, property='AUTH', related='289', enable=1, default_auth=0, front_display=1
+WHERE id=124;
+UPDATE sys_privilege
+SET name='修改', url='Update', `type`='LINK', parent_id=16, `sequence`=1, property='AUTH', related='289', enable=1, default_auth=0, front_display=1
+WHERE id=125;
+UPDATE sys_privilege
+SET name='删除', url='Delete', `type`='LINK', parent_id=16, `sequence`=2, property='AUTH', related='290', enable=1, default_auth=0, front_display=1
+WHERE id=126;
+
+
+
+
+
+
+

+ 14 - 0
sop-business/src/main/resources/mapper/SysRoleMapper.xml

@@ -21,4 +21,18 @@
             and a.type <![CDATA[ <> ]]> 'ADMIN'
         </where>
     </select>
+
+    <select id="query" resultType="com.qmth.sop.business.bean.dto.RoleDto">
+        select t.id, t.name, t.enable, t.type, t.default_role from sys_role t
+        <where>
+            <if test="name != null and name != ''">
+                and t.name like concat('%', #{name}, '%')
+            </if>
+            <if test="enable != null and enable != '' or enable == 0">
+                and t.enable = #{enable}
+            </if>
+                and t.type <![CDATA[ <> ]]> 'ADMIN'
+        </where>
+        ORDER BY t.create_time
+    </select>
 </mapper>

+ 15 - 0
sop-business/src/main/resources/mapper/SysUserMapper.xml

@@ -104,4 +104,19 @@
         </where>
         order by a.create_time desc
     </select>
+
+    <select id="selectRoleNames" resultType="com.qmth.sop.business.bean.result.UserRoleNameResult">
+        select group_concat(sr.name) as roleNames,sur.user_id as userId from sys_role sr
+        join sys_user_role sur on sur.role_id = sr.id
+        <where>
+            <if test="userIds != null and userIds != '' and userIds.size > 0">
+                AND sur.user_id IN
+                <foreach collection="userIds" item="item" index="index" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+            and sur.user_id > 1
+        </where>
+        group by sur.user_id
+    </select>
 </mapper>

+ 12 - 11
sop-business/src/main/resources/mapper/SysUserRoleMapper.xml

@@ -3,16 +3,17 @@
 <mapper namespace="com.qmth.sop.business.mapper.SysUserRoleMapper">
 
     <select id="listRoleByUserId" resultType="com.qmth.sop.business.entity.SysRole">
-        SELECT
-            *
-        FROM
-            sys_role a
-        WHERE
-            EXISTS( SELECT
-                        1
-                    FROM
-                        sys_user_role b
-                    WHERE
-                        a.id = b.role_id AND b.user_id = #{userId})
+        SELECT * FROM sys_role a
+        WHERE EXISTS(SELECT 1 FROM sys_user_role b WHERE a.id = b.role_id AND b.user_id = #{userId})
+    </select>
+
+    <select id="listByRoleId" resultType="com.qmth.sop.business.entity.SysUserRole">
+        select * from sys_user_role sur
+        join sys_user su on su.id = sur.user_id
+        <where>
+            <if test="roleId != null and roleId != ''">
+                and sur.role_id = #{roleId}
+            </if>
+        </where>
     </select>
 </mapper>

+ 2 - 0
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -82,6 +82,7 @@ public class SystemConstant {
     public static final int PAGE_SIZE_MIN = 10;
     public static final int PAGE_SIZE_MAX = 500;
     public static final int PAGE_SIZE_MAX_SELECT = 100000;
+    public static final int IN_SIZE_MAX = 1000;
     public static final int PAGE_NUMBER_MIN = 1;
     public static final String STATIC = "static";
     public static final String CATALOG_LINK = "->";
@@ -130,6 +131,7 @@ public class SystemConstant {
     public static final String PREFIX_URL_LOG = "/sys/log";
     public static final String PREFIX_URL_NOTICE = "/sys/notice";
     public static final String PREFIX_URL_MESSAGE = "/sys/message";
+    public static final String PREFIX_URL_ROLE = "/admin/role";
 
     /**
      * 缓存配置

+ 2 - 0
sop-common/src/main/java/com/qmth/sop/common/enums/ExceptionResultEnum.java

@@ -45,6 +45,8 @@ public enum ExceptionResultEnum {
 
     USER_NO_EXISTS(HttpStatus.INTERNAL_SERVER_ERROR, 5000006, "没有用户数据"),
 
+    ROLE_NO_EXISTS(HttpStatus.INTERNAL_SERVER_ERROR, 5000007, "没有角色数据"),
+
     USER_NO_DATA(HttpStatus.INTERNAL_SERVER_ERROR, 5000009, "用户或密码不正确"),
 
     USER_ENABLE(HttpStatus.INTERNAL_SERVER_ERROR, 5000011, "用户已禁用"),

+ 3 - 1
sop-common/src/main/java/com/qmth/sop/common/enums/FieldUniqueEnum.java

@@ -15,7 +15,9 @@ public enum FieldUniqueEnum {
 
     sys_user_UN_login_name("登录名"),
 
-    sys_org_UN_name("机构名称");
+    sys_org_UN_name("机构名称"),
+
+    sys_role_UN_type("角色类型");
 
     private String title;
 

+ 3 - 1
sop-common/src/main/java/com/qmth/sop/common/enums/RoleTypeEnum.java

@@ -23,7 +23,9 @@ public enum RoleTypeEnum {
 
     QA("QA", "系统角色"),
 
-    CUSTOM("技术客服", "系统角色");
+    CUSTOM("技术客服", "系统角色"),
+
+    DEFINED("自定义", "自定义角色");
 
     RoleTypeEnum(String desc, String title) {
         this.desc = desc;

+ 48 - 3
sop-server/src/main/java/com/qmth/sop/server/api/SysRoleController.java

@@ -1,8 +1,23 @@
 package com.qmth.sop.server.api;
 
 
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.sop.business.bean.dto.UserDto;
+import com.qmth.sop.business.bean.params.SysRolePrivilegeParams;
+import com.qmth.sop.business.service.SysRoleService;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.util.Result;
+import com.qmth.sop.common.util.ResultUtil;
+import io.swagger.annotations.*;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.validation.Valid;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import java.security.NoSuchAlgorithmException;
 
 /**
  * <p>
@@ -12,8 +27,38 @@ import org.springframework.web.bind.annotation.RestController;
  * @author wangliang
  * @since 2023-07-17
  */
+@Api(tags = "角色Controller")
 @RestController
-@RequestMapping("/sys-role")
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_ROLE)
 public class SysRoleController {
 
+    @Resource
+    SysRoleService sysRoleService;
+
+    @ApiOperation(value = "查询")
+    @RequestMapping(value = "/list", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = UserDto.class)})
+    public Result list(@ApiParam(value = "角色名称") @RequestParam(required = false) String name,
+                       @ApiParam(value = "是否启用") @RequestParam(required = false) Boolean enable,
+                       @ApiParam(value = "页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                       @ApiParam(value = "页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        return ResultUtil.ok(sysRoleService.query(new Page<>(pageNumber, pageSize), name, enable));
+    }
+
+    @ApiOperation(value = "新增/修改")
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
+    public Result save(@Valid @RequestBody SysRolePrivilegeParams sysRolePrivilegeParams, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        return ResultUtil.ok(sysRoleService.saveRole(sysRolePrivilegeParams));
+    }
+
+    @ApiOperation(value = "删除")
+    @RequestMapping(value = "/delete", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
+    public Result delete(@ApiParam(value = "角色id", required = true) @RequestParam Long roleId) throws NoSuchAlgorithmException {
+        return ResultUtil.ok(sysRoleService.deleteRole(roleId));
+    }
 }