feat: 角色权限分配功能全部完成
This commit is contained in:
parent
701fd52d45
commit
b7d9a2036d
@ -5,7 +5,9 @@ import cn.dev33.satoken.util.SaResult;
|
|||||||
import com.guaiguailang.harmony.domain.dto.ParamLogin;
|
import com.guaiguailang.harmony.domain.dto.ParamLogin;
|
||||||
import com.guaiguailang.harmony.domain.entity.MenuDataItem;
|
import com.guaiguailang.harmony.domain.entity.MenuDataItem;
|
||||||
import com.guaiguailang.harmony.domain.entity.SystemRole;
|
import com.guaiguailang.harmony.domain.entity.SystemRole;
|
||||||
|
import com.guaiguailang.harmony.domain.entity.SystemRoleMenu;
|
||||||
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||||
|
import com.guaiguailang.harmony.domain.vo.SystemRoleMenuVO;
|
||||||
import com.guaiguailang.harmony.service.AuthService;
|
import com.guaiguailang.harmony.service.AuthService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@ -91,7 +93,7 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "角色列表(所有)",
|
summary = "角色列表(所有)",
|
||||||
description = "获取所有角色列表,仅限管理员操作的接口",
|
description = "获取所有角色列表",
|
||||||
tags = {"权限相关接口"}
|
tags = {"权限相关接口"}
|
||||||
)
|
)
|
||||||
@GetMapping("/role-all")
|
@GetMapping("/role-all")
|
||||||
@ -124,4 +126,26 @@ public class AuthController {
|
|||||||
public ResponseEntity delRoleRealy(@RequestBody SystemRole systemRole) {
|
public ResponseEntity delRoleRealy(@RequestBody SystemRole systemRole) {
|
||||||
return ResponseEntity.ok(authService.delRoleRealy(systemRole));
|
return ResponseEntity.ok(authService.delRoleRealy(systemRole));
|
||||||
}
|
}
|
||||||
|
@GetMapping("/role-menu-list")
|
||||||
|
public ResponseEntity getMenuByRole(@RequestParam String roleId) {
|
||||||
|
return ResponseEntity.ok(authService.getMenuByRole(roleId));
|
||||||
|
}
|
||||||
|
@Operation(
|
||||||
|
summary = "角色功能 删除",
|
||||||
|
description = "删除角色拥有的功能",
|
||||||
|
tags = {"权限相关接口"}
|
||||||
|
)
|
||||||
|
@DeleteMapping("/role-menu-del")
|
||||||
|
public ResponseEntity delRoleMenu(@RequestBody SystemRoleMenu srm) {
|
||||||
|
return ResponseEntity.ok(authService.delRoleMenu(srm));
|
||||||
|
}
|
||||||
|
@Operation(
|
||||||
|
summary = "角色功能新增",
|
||||||
|
description = "新增角色可以用的菜单",
|
||||||
|
tags = {"权限相关接口"}
|
||||||
|
)
|
||||||
|
@PostMapping("/role-menu-add")
|
||||||
|
public ResponseEntity addRoleMenu(@RequestBody SystemRoleMenu srm) {
|
||||||
|
return ResponseEntity.ok(authService.addRoleMenu(srm));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package com.guaiguailang.harmony.domain.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class SystemMenu {
|
|
||||||
|
|
||||||
private Long id;
|
|
||||||
private String title;
|
|
||||||
private String key;
|
|
||||||
private String name;
|
|
||||||
private String component;
|
|
||||||
private String redirect;
|
|
||||||
private String icon;
|
|
||||||
private int status;
|
|
||||||
private String parent;
|
|
||||||
private int order;
|
|
||||||
}
|
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.guaiguailang.harmony.domain.entity;
|
||||||
|
|
||||||
|
|
||||||
|
public class SystemRoleMenu {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
private String roleId;
|
||||||
|
private String menuId;
|
||||||
|
private String actionIds;
|
||||||
|
private String about;
|
||||||
|
private long status;
|
||||||
|
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getRoleId() {
|
||||||
|
return roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleId(String roleId) {
|
||||||
|
this.roleId = roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getMenuId() {
|
||||||
|
return menuId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMenuId(String menuId) {
|
||||||
|
this.menuId = menuId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getActionIds() {
|
||||||
|
return actionIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActionIds(String actionIds) {
|
||||||
|
this.actionIds = actionIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getAbout() {
|
||||||
|
return about;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAbout(String about) {
|
||||||
|
this.about = about;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public long getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(long status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
package com.guaiguailang.harmony.domain.vo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class MenuVO {
|
|
||||||
//暂时作废
|
|
||||||
private Long id;
|
|
||||||
private String title;
|
|
||||||
private String key;
|
|
||||||
private String name;
|
|
||||||
private String component;
|
|
||||||
private String redirect;
|
|
||||||
private String icon;
|
|
||||||
private int status;
|
|
||||||
private String parent;
|
|
||||||
private int order;
|
|
||||||
|
|
||||||
private List<MenuVO> children;
|
|
||||||
}
|
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.guaiguailang.harmony.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SystemRoleMenuVO {
|
||||||
|
private long id;
|
||||||
|
private String roleId;
|
||||||
|
private String menuId;
|
||||||
|
private String actionIds;
|
||||||
|
private String about;
|
||||||
|
private long status;
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -11,4 +11,6 @@ import java.util.List;
|
|||||||
public interface RoleMapper extends BaseMapper<SystemRole> {
|
public interface RoleMapper extends BaseMapper<SystemRole> {
|
||||||
@Select("SELECT * FROM system_role")
|
@Select("SELECT * FROM system_role")
|
||||||
List<SystemRole> getRoleAll();
|
List<SystemRole> getRoleAll();
|
||||||
|
@Select("SELECT * FROM system_role where level>system_role.level")
|
||||||
|
List<SystemRole> getRole(int level);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,12 @@ package com.guaiguailang.harmony.mapper;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.guaiguailang.harmony.domain.entity.MenuDataItem;
|
import com.guaiguailang.harmony.domain.entity.MenuDataItem;
|
||||||
import com.guaiguailang.harmony.domain.entity.SystemMenu;
|
import com.guaiguailang.harmony.domain.entity.SystemRole;
|
||||||
|
import com.guaiguailang.harmony.domain.entity.SystemRoleMenu;
|
||||||
|
import com.guaiguailang.harmony.domain.vo.SystemRoleMenuVO;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
@ -24,5 +29,13 @@ public interface SystemMapper extends BaseMapper<MenuDataItem> {
|
|||||||
*/
|
*/
|
||||||
@Select("SELECT * from menu_data_item")
|
@Select("SELECT * from menu_data_item")
|
||||||
List<MenuDataItem> getMenusAll();
|
List<MenuDataItem> getMenusAll();
|
||||||
|
@Select("SELECT * from system_role_menu join menu_data_item on menu_id=menu_data_item.id where role_id=#{roleId}")
|
||||||
|
List<SystemRoleMenuVO> getMneuByRoleId(String roleId);
|
||||||
|
@Delete("delete from system_role_menu where id=#{id}")
|
||||||
|
int deleteRoleMenuById(long id);
|
||||||
|
@Insert("INSERT INTO system_role_menu ( role_id, menu_id, action_ids, about, status) " +
|
||||||
|
"VALUES (#{roleId}, #{menuId}, #{actionIds}, #{about}, #{status})")
|
||||||
|
int addRoleMenu(SystemRoleMenu srm);
|
||||||
|
@Select("SELECT * from system_role_menu where role_id=#{roleId} and menu_id=#{menuId}")
|
||||||
|
List<SystemRoleMenu> roleMenuIsin(String roleId, String menuId);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.guaiguailang.harmony.service;
|
|||||||
|
|
||||||
import com.guaiguailang.harmony.domain.dto.ParamLogin;
|
import com.guaiguailang.harmony.domain.dto.ParamLogin;
|
||||||
import com.guaiguailang.harmony.domain.entity.SystemRole;
|
import com.guaiguailang.harmony.domain.entity.SystemRole;
|
||||||
|
import com.guaiguailang.harmony.domain.entity.SystemRoleMenu;
|
||||||
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
@ -19,4 +20,10 @@ public interface AuthService {
|
|||||||
ResponseResult delRole(SystemRole systemRole);
|
ResponseResult delRole(SystemRole systemRole);
|
||||||
|
|
||||||
ResponseResult delRoleRealy(SystemRole systemRole);
|
ResponseResult delRoleRealy(SystemRole systemRole);
|
||||||
|
|
||||||
|
ResponseResult getMenuByRole(String roleId);
|
||||||
|
|
||||||
|
ResponseResult delRoleMenu(SystemRoleMenu srm);
|
||||||
|
|
||||||
|
ResponseResult addRoleMenu(SystemRoleMenu srm);
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,13 @@ import cn.dev33.satoken.util.SaResult;
|
|||||||
import com.github.yitter.idgen.YitIdHelper;
|
import com.github.yitter.idgen.YitIdHelper;
|
||||||
import com.guaiguailang.harmony.domain.dto.ParamLogin;
|
import com.guaiguailang.harmony.domain.dto.ParamLogin;
|
||||||
import com.guaiguailang.harmony.domain.entity.SystemRole;
|
import com.guaiguailang.harmony.domain.entity.SystemRole;
|
||||||
|
import com.guaiguailang.harmony.domain.entity.SystemRoleMenu;
|
||||||
import com.guaiguailang.harmony.domain.entity.UserInfo;
|
import com.guaiguailang.harmony.domain.entity.UserInfo;
|
||||||
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||||
import com.guaiguailang.harmony.domain.vo.UserInfoLogin;
|
import com.guaiguailang.harmony.domain.vo.UserInfoLogin;
|
||||||
import com.guaiguailang.harmony.mapper.AuthMapper;
|
import com.guaiguailang.harmony.mapper.AuthMapper;
|
||||||
import com.guaiguailang.harmony.mapper.RoleMapper;
|
import com.guaiguailang.harmony.mapper.RoleMapper;
|
||||||
|
import com.guaiguailang.harmony.mapper.SystemMapper;
|
||||||
import com.guaiguailang.harmony.mapper.UserMapper;
|
import com.guaiguailang.harmony.mapper.UserMapper;
|
||||||
import com.guaiguailang.harmony.service.AuthService;
|
import com.guaiguailang.harmony.service.AuthService;
|
||||||
import com.guaiguailang.harmony.utils.PasswordEncryptor;
|
import com.guaiguailang.harmony.utils.PasswordEncryptor;
|
||||||
@ -34,12 +36,15 @@ public class AuthServiceImpl implements AuthService {
|
|||||||
private final AuthMapper authMapper;
|
private final AuthMapper authMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
|
@Autowired
|
||||||
|
private final SystemMapper systemMapper;
|
||||||
|
|
||||||
private final RoleMapper roleMapper;
|
private final RoleMapper roleMapper;
|
||||||
|
|
||||||
public AuthServiceImpl(AuthMapper authMapper, UserMapper userMapper, RoleMapper roleMapper) {
|
public AuthServiceImpl(AuthMapper authMapper, UserMapper userMapper, SystemMapper systemMapper, RoleMapper roleMapper) {
|
||||||
this.authMapper = authMapper;
|
this.authMapper = authMapper;
|
||||||
this.userMapper = userMapper;
|
this.userMapper = userMapper;
|
||||||
|
this.systemMapper = systemMapper;
|
||||||
this.roleMapper = roleMapper;
|
this.roleMapper = roleMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +88,17 @@ public class AuthServiceImpl implements AuthService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseResult getRoleAll() {
|
public ResponseResult getRoleAll() {
|
||||||
List<SystemRole> result = roleMapper.getRoleAll();
|
// 判断是不是管理员,是管理员就加载所有,不是管理员就加载有权限的
|
||||||
|
Long id = Long.parseLong(StpUtil.getLoginId().toString());// 获取用户id
|
||||||
|
// 获取level
|
||||||
|
SystemRole systemRoleCreator = userMapper.getRoleLevelByUserId(id);
|
||||||
|
List<SystemRole> result;
|
||||||
|
if(systemRoleCreator.getLevel() ==1) {
|
||||||
|
// root 加载所有权限
|
||||||
|
result = roleMapper.getRoleAll();
|
||||||
|
}else{
|
||||||
|
result = roleMapper.getRole(systemRoleCreator.getLevel());
|
||||||
|
}
|
||||||
return ResponseResult.success(result);
|
return ResponseResult.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,5 +148,29 @@ public class AuthServiceImpl implements AuthService {
|
|||||||
return ResponseResult.success(roleMapper.deleteById(systemRole.getId()));
|
return ResponseResult.success(roleMapper.deleteById(systemRole.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseResult getMenuByRole(String roleId) {
|
||||||
|
return ResponseResult.success(systemMapper.getMneuByRoleId(roleId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseResult delRoleMenu(SystemRoleMenu srm) {
|
||||||
|
int result = systemMapper.deleteRoleMenuById(srm.getId());
|
||||||
|
return ResponseResult.info(result,result==1?"成功":"失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseResult addRoleMenu(SystemRoleMenu srm) {
|
||||||
|
// 查询是否已被添加
|
||||||
|
List<SystemRoleMenu> systemRoleMenuList = systemMapper.roleMenuIsin(srm.getRoleId(),srm.getMenuId());
|
||||||
|
if(systemRoleMenuList.size()>0){
|
||||||
|
return ResponseResult.error("该功能已拥有,无需再次添加");
|
||||||
|
}
|
||||||
|
srm.setStatus(1);
|
||||||
|
srm.setAbout("操作人:"+StpUtil.getLoginId().toString());
|
||||||
|
int result = systemMapper.addRoleMenu(srm);
|
||||||
|
return ResponseResult.info(result,result==1?"成功":"失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,16 @@ package com.guaiguailang.harmony.service.impl;
|
|||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.guaiguailang.harmony.domain.entity.MenuDataItem;
|
import com.guaiguailang.harmony.domain.entity.MenuDataItem;
|
||||||
import com.guaiguailang.harmony.domain.entity.SystemMenu;
|
|
||||||
import com.guaiguailang.harmony.domain.entity.UserInfo;
|
import com.guaiguailang.harmony.domain.entity.UserInfo;
|
||||||
import com.guaiguailang.harmony.domain.vo.MenuVO;
|
|
||||||
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||||
import com.guaiguailang.harmony.mapper.SystemMapper;
|
import com.guaiguailang.harmony.mapper.SystemMapper;
|
||||||
import com.guaiguailang.harmony.mapper.UserMapper;
|
import com.guaiguailang.harmony.mapper.UserMapper;
|
||||||
import com.guaiguailang.harmony.service.SystemService;
|
import com.guaiguailang.harmony.service.SystemService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
@ -177,11 +177,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
userAddParam.setTelphone(userAddParam.getTelphone()==null?"":userAddParam.getTelphone());
|
userAddParam.setTelphone(userAddParam.getTelphone()==null?"":userAddParam.getTelphone());
|
||||||
userAddParam.setAvatar(userAddParam.getAvatar()==null?"":userAddParam.getAvatar());
|
userAddParam.setAvatar(userAddParam.getAvatar()==null?"":userAddParam.getAvatar());
|
||||||
userAddParam.setCode(userAddParam.getCode()==null?"":userAddParam.getCode());
|
userAddParam.setCode(userAddParam.getCode()==null?"":userAddParam.getCode());
|
||||||
|
|
||||||
System.out.println("===========用户信息");
|
|
||||||
System.out.println(userAddParam.toString());
|
|
||||||
System.out.println("===================");
|
|
||||||
|
|
||||||
int result = userMapper.addUser(userAddParam);
|
int result = userMapper.addUser(userAddParam);
|
||||||
if (result == 1) {
|
if (result == 1) {
|
||||||
return ResponseResult.success(userAddParam);
|
return ResponseResult.success(userAddParam);
|
||||||
|
Loading…
Reference in New Issue
Block a user