fix: 优化角色编辑功能
This commit is contained in:
parent
efdde4e4e4
commit
19300abbd4
@ -3,6 +3,7 @@ package com.guaiguailang.harmony.controller;
|
|||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.dev33.satoken.util.SaResult;
|
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.SystemRole;
|
||||||
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||||
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;
|
||||||
@ -87,4 +88,17 @@ public class AuthController {
|
|||||||
StpUtil.logout();
|
StpUtil.logout();
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
@Operation(
|
||||||
|
summary = "角色列表(所有)",
|
||||||
|
description = "获取所有角色列表,仅限管理员操作的接口",
|
||||||
|
tags = {"权限相关接口"}
|
||||||
|
)
|
||||||
|
@GetMapping("/role-all")
|
||||||
|
public ResponseEntity getRoleAll() {
|
||||||
|
return ResponseEntity.ok(authService.getRoleAll());
|
||||||
|
}
|
||||||
|
@PostMapping("/role-update")
|
||||||
|
public ResponseEntity updateRole(@RequestBody SystemRole role) {
|
||||||
|
return ResponseEntity.ok(authService.updateRole(role));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.guaiguailang.harmony.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.guaiguailang.harmony.domain.entity.SystemRole;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface RoleMapper extends BaseMapper<SystemRole> {
|
||||||
|
@Select("SELECT * FROM system_role")
|
||||||
|
List<SystemRole> getRoleAll();
|
||||||
|
}
|
@ -26,9 +26,17 @@ public interface UserMapper extends BaseMapper<UserInfo> {
|
|||||||
List<UserInfo> getUserListAll(int limit,int end, String merchantCode, Map<String, Object> queryConditions);
|
List<UserInfo> getUserListAll(int limit,int end, String merchantCode, Map<String, Object> queryConditions);
|
||||||
|
|
||||||
UserListNum getUserListNum(String merchantCode);
|
UserListNum getUserListNum(String merchantCode);
|
||||||
@Select("SELECT * FROM system_role WHERE level > (SELECT level FROM system_role WHERE role_id = #{roleId})")
|
@Select("SELECT * FROM system_role WHERE level > (SELECT level FROM system_role WHERE role_id = #{roleId} and status=1)")
|
||||||
List<SystemRole> getRoleListWhenAddUser(String role);
|
List<SystemRole> getRoleListWhenAddUser(String role);
|
||||||
|
|
||||||
|
|
||||||
int addUser(ParamUserAdd userAddParam);
|
int addUser(ParamUserAdd userAddParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户 的 角色信息
|
||||||
|
* @param id 用户id
|
||||||
|
* @return 用户角色信息
|
||||||
|
*/
|
||||||
|
@Select("select * from system_role where role_id = (select role_id from user_info where user_info.id=#{id})")
|
||||||
|
SystemRole getRoleLevelByUserId(Long id);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.guaiguailang.harmony.service;
|
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.vo.ResponseResult;
|
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
@ -8,4 +9,8 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
|
|
||||||
public interface AuthService {
|
public interface AuthService {
|
||||||
ResponseResult loginByAccount(ParamLogin loginParam) throws NoSuchAlgorithmException;
|
ResponseResult loginByAccount(ParamLogin loginParam) throws NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
ResponseResult getRoleAll();
|
||||||
|
|
||||||
|
ResponseResult updateRole(SystemRole systemRole);
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,12 @@ package com.guaiguailang.harmony.service.impl;
|
|||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.dev33.satoken.util.SaResult;
|
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.SystemRole;
|
||||||
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.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;
|
||||||
@ -32,9 +34,12 @@ public class AuthServiceImpl implements AuthService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
|
|
||||||
public AuthServiceImpl(AuthMapper authMapper, UserMapper userMapper) {
|
private final RoleMapper roleMapper;
|
||||||
|
|
||||||
|
public AuthServiceImpl(AuthMapper authMapper, UserMapper userMapper, RoleMapper roleMapper) {
|
||||||
this.authMapper = authMapper;
|
this.authMapper = authMapper;
|
||||||
this.userMapper = userMapper;
|
this.userMapper = userMapper;
|
||||||
|
this.roleMapper = roleMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,4 +79,33 @@ public class AuthServiceImpl implements AuthService {
|
|||||||
userInfoLogin.setRoles(rs);
|
userInfoLogin.setRoles(rs);
|
||||||
return ResponseResult.info(1,"ok",userInfoLogin);
|
return ResponseResult.info(1,"ok",userInfoLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseResult getRoleAll() {
|
||||||
|
List<SystemRole> result = roleMapper.getRoleAll();
|
||||||
|
return ResponseResult.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseResult updateRole(SystemRole systemRole) {
|
||||||
|
// todo 此处可以进行性能优化,获取level从redis中获取
|
||||||
|
// 做一个校验,更新的level不能小于操作人的level
|
||||||
|
Long id = Long.parseLong(StpUtil.getLoginId().toString());// 获取用户id
|
||||||
|
// 获取level
|
||||||
|
SystemRole systemRoleCreator = userMapper.getRoleLevelByUserId(id);
|
||||||
|
// if(userInfo.getLevel()!=1){
|
||||||
|
// // 仅限超级管理员(1)能操作所有
|
||||||
|
// }
|
||||||
|
// 算了,先不给超级管理员特权
|
||||||
|
|
||||||
|
if(systemRole.getLevel()<=systemRoleCreator.getLevel()){
|
||||||
|
return ResponseResult.error("权限不足");
|
||||||
|
}
|
||||||
|
int result = roleMapper.updateById(systemRole);
|
||||||
|
if(result == 1) {
|
||||||
|
return ResponseResult.success(systemRole);
|
||||||
|
}else{
|
||||||
|
return ResponseResult.error("更新失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
39
src/main/resources/mapper/RoleMapper.xml
Normal file
39
src/main/resources/mapper/RoleMapper.xml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?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.guaiguailang.harmony.mapper.RoleMapper">
|
||||||
|
|
||||||
|
<!-- <!– 插入新角色 –>-->
|
||||||
|
<!-- <insert id="insertRole" parameterType="com.guaiguailang.harmony.domain.entity.SystemRole">-->
|
||||||
|
<!-- INSERT INTO system_role (role_name, role_id, status, description, level)-->
|
||||||
|
<!-- VALUES (#{roleName}, #{roleId}, #{status}, #{description}, #{level})-->
|
||||||
|
<!-- </insert>-->
|
||||||
|
|
||||||
|
<!-- <!– 更新角色信息 –>-->
|
||||||
|
<!-- <update id="updateRole" parameterType="com.guaiguailang.harmony.domain.entity.SystemRole">-->
|
||||||
|
<!-- UPDATE system_role-->
|
||||||
|
<!-- SET role_name = #{roleName},-->
|
||||||
|
<!-- role_id = #{roleId},-->
|
||||||
|
<!-- status = #{status},-->
|
||||||
|
<!-- description = #{description},-->
|
||||||
|
<!-- level = #{level}-->
|
||||||
|
<!-- WHERE id = #{id}-->
|
||||||
|
<!-- </update>-->
|
||||||
|
|
||||||
|
<!-- <!– 删除角色 –>-->
|
||||||
|
<!-- <delete id="deleteRole" parameterType="long">-->
|
||||||
|
<!-- DELETE FROM system_role WHERE id = #{id}-->
|
||||||
|
<!-- </delete>-->
|
||||||
|
|
||||||
|
<!-- <!– 查询所有角色 –>-->
|
||||||
|
<!-- <select id="selectAllRoles" resultType="com.guaiguailang.harmony.domain.entity.SystemRole">-->
|
||||||
|
<!-- SELECT * FROM system_role-->
|
||||||
|
<!-- </select>-->
|
||||||
|
|
||||||
|
<!-- <!– 根据ID查询角色 –>-->
|
||||||
|
<!-- <select id="selectRoleById" parameterType="long" resultType="com.guaiguailang.harmony.domain.entity.SystemRole">-->
|
||||||
|
<!-- SELECT * FROM system_role WHERE id = #{id}-->
|
||||||
|
<!-- </select>-->
|
||||||
|
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue
Block a user