角色切换
This commit is contained in:
+35
-17
@@ -52,13 +52,13 @@ import java.util.*;
|
||||
public class SysRoleController {
|
||||
@Autowired
|
||||
private ISysRoleService sysRoleService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionDataRuleService sysPermissionDataRuleService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ISysRolePermissionService sysRolePermissionService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
|
||||
@@ -85,7 +85,7 @@ public class SysRoleController {
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param role
|
||||
@@ -106,7 +106,7 @@ public class SysRoleController {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param role
|
||||
@@ -128,10 +128,10 @@ public class SysRoleController {
|
||||
result.success("修改成功!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param id
|
||||
@@ -144,7 +144,7 @@ public class SysRoleController {
|
||||
sysRoleService.deleteRole(id);
|
||||
return Result.OK("删除角色成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
@@ -163,7 +163,7 @@ public class SysRoleController {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
@@ -195,7 +195,7 @@ public class SysRoleController {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验角色编码唯一
|
||||
*/
|
||||
@@ -303,7 +303,7 @@ public class SysRoleController {
|
||||
}
|
||||
return Result.error("文件导入失败!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询数据规则数据
|
||||
*/
|
||||
@@ -333,7 +333,7 @@ public class SysRoleController {
|
||||
//TODO 以后按钮权限的查询也走这个请求 无非在map中多加两个key
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存数据规则至角色菜单关联表
|
||||
*/
|
||||
@@ -361,8 +361,8 @@ public class SysRoleController {
|
||||
}
|
||||
return Result.OK("保存成功!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户角色授权功能,查询菜单权限树
|
||||
* @param request
|
||||
@@ -410,9 +410,27 @@ public class SysRoleController {
|
||||
getTreeModelList(treeList, metaList, tree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 当前登录用户角色
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "当前登录用户角色")
|
||||
@RequestMapping(value = "/getRoleByUserId", method = RequestMethod.GET)
|
||||
public Result<List<SysRole>> getRoleByUserId() {
|
||||
Result<List<SysRole>> result = new Result<>();
|
||||
List<SysRole> list = sysRoleService.getRoleByUserId();
|
||||
if(list==null||list.size()<=0) {
|
||||
result.error500("未找到角色信息");
|
||||
}else {
|
||||
result.setResult(list);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.jero.modules.system.enums;
|
||||
|
||||
/**
|
||||
* 项目角色枚举类
|
||||
*/
|
||||
public enum ProjectRoleEnum {
|
||||
STUDIO_ENGINEER("studio工程师","0","R&H Studio"),
|
||||
REGULATI_ENGINEER("法规工程师","1","studio"),
|
||||
HOMOLOGATION_ENGINEER("认证工程师","2","homo"),
|
||||
REGULATI_AND_HOMOLOGATION_ENGINEER("法规工程师/认证工程师","4",""),
|
||||
MANAGER("领导角色","11","R&H Manager"),
|
||||
ADMIN("系统管理员","12","admin"),
|
||||
;
|
||||
|
||||
String name;
|
||||
String value;
|
||||
String code;
|
||||
|
||||
private ProjectRoleEnum(String name, String value, String code) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static String getTextByValue(String value) {
|
||||
ProjectRoleEnum[] values = values();
|
||||
for (ProjectRoleEnum projectRoleEnum : values) {
|
||||
if (projectRoleEnum.value.equals(value)) {
|
||||
return projectRoleEnum.name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+9
@@ -2,11 +2,14 @@ package com.jero.modules.system.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import com.jero.modules.system.entity.SysRole;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色表 Mapper 接口
|
||||
@@ -34,4 +37,10 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||
@Delete("delete from sys_role_permission where role_id = #{roleId}")
|
||||
void deleteRolePermissionRelation(@Param("roleId") String roleId);
|
||||
|
||||
@Select("SELECT * FROM sys_role \n" +
|
||||
"left join sys_user_role\n" +
|
||||
"on sys_role.id = sys_user_role.role_id\n" +
|
||||
"where user_id = #{userId}")
|
||||
List<SysRole> getRoleByUserId(@Param("userId") String userId);
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -49,4 +49,6 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
*/
|
||||
List<SysRole> queryByRoleCode(String roleCode);
|
||||
|
||||
List<SysRole> getRoleByUserId();
|
||||
|
||||
}
|
||||
|
||||
+47
@@ -3,6 +3,8 @@ package com.jero.modules.system.service.impl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.modules.system.enums.ProjectRoleEnum;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import com.jero.common.api.vo.Result;
|
||||
@@ -14,6 +16,7 @@ import com.jero.modules.system.entity.SysRole;
|
||||
import com.jero.modules.system.mapper.SysRoleMapper;
|
||||
import com.jero.modules.system.mapper.SysUserMapper;
|
||||
import com.jero.modules.system.service.ISysRoleService;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,7 +27,9 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -99,4 +104,46 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
queryWrapper.eq(SysRole::getRoleCode, roleCode);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> getRoleByUserId() {
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
List<SysRole> roleList = sysRoleMapper.getRoleByUserId(loginUser.getId());
|
||||
List<String> roleCodeList = new ArrayList<>();
|
||||
if(roleList.size() != 0){
|
||||
roleCodeList = roleList.stream().map(SysRole::getRoleCode).collect(Collectors.toList());
|
||||
}
|
||||
List<SysRole> sysRoleNew = new ArrayList<>();
|
||||
if(roleCodeList.size() != 0 && (roleCodeList.contains(ProjectRoleEnum.REGULATI_ENGINEER.getCode()) || roleCodeList.contains(ProjectRoleEnum.HOMOLOGATION_ENGINEER.getCode()))){
|
||||
sysRoleNew = roleList.stream().filter(e -> !ProjectRoleEnum.REGULATI_ENGINEER.getCode().equals(e.getRoleCode()) && !ProjectRoleEnum.HOMOLOGATION_ENGINEER.getCode().equals(e.getRoleCode())).collect(Collectors.toList());
|
||||
SysRole sysRole = new SysRole();
|
||||
sysRole.setRoleName(ProjectRoleEnum.REGULATI_AND_HOMOLOGATION_ENGINEER.getName());
|
||||
sysRole.setRoleCode(ProjectRoleEnum.REGULATI_AND_HOMOLOGATION_ENGINEER.getValue());
|
||||
sysRoleNew.add(sysRole);
|
||||
}
|
||||
//studio角色,法规工程师/认证工程师,领导角色,管理员角色
|
||||
List<SysRole> sysRoles = new LinkedList<>();
|
||||
if(sysRoleNew.size() != 0){
|
||||
List<SysRole> studio = sysRoleNew.stream().filter(e -> ProjectRoleEnum.STUDIO_ENGINEER.getCode().equals(e.getRoleCode())).collect(Collectors.toList());
|
||||
List<SysRole> regulatiAndHomo = sysRoleNew.stream().filter(e -> ProjectRoleEnum.REGULATI_AND_HOMOLOGATION_ENGINEER.getValue().equals(e.getRoleCode())).collect(Collectors.toList());
|
||||
List<SysRole> manager = sysRoleNew.stream().filter(e -> ProjectRoleEnum.MANAGER.getCode().equals(e.getRoleCode())).collect(Collectors.toList());
|
||||
List<SysRole> admin = sysRoleNew.stream().filter(e -> ProjectRoleEnum.ADMIN.getCode().equals(e.getRoleCode())).collect(Collectors.toList());
|
||||
if(studio.size() != 0){
|
||||
studio.get(0).setRoleCode(ProjectRoleEnum.STUDIO_ENGINEER.getValue());
|
||||
sysRoles.addAll(studio);
|
||||
}
|
||||
if(regulatiAndHomo.size() != 0){
|
||||
sysRoles.addAll(regulatiAndHomo);
|
||||
}
|
||||
if(manager.size() != 0){
|
||||
manager.get(0).setRoleCode(ProjectRoleEnum.MANAGER.getValue());
|
||||
sysRoles.addAll(manager);
|
||||
}
|
||||
if(admin.size() != 0){
|
||||
admin.get(0).setRoleCode(ProjectRoleEnum.ADMIN.getValue());
|
||||
sysRoles.addAll(admin);
|
||||
}
|
||||
}
|
||||
return sysRoles;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user