完成角色权限分配功能的迁移
This commit is contained in:
parent
d34e555aa0
commit
99c591d6f9
@ -0,0 +1,6 @@
|
|||||||
|
### /permission/list 成功
|
||||||
|
GET {{baseUrl}}/permission/list-role-resource?roleId=1
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{accessToken}}
|
||||||
|
|
||||||
|
###
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.mall.managementweb.controller.permission;
|
package cn.iocoder.mall.managementweb.controller.permission;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.permission.dto.PermissionAssignRoleResourceDTO;
|
||||||
import cn.iocoder.mall.managementweb.manager.permission.PermissionManager;
|
import cn.iocoder.mall.managementweb.manager.permission.PermissionManager;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
@ -8,6 +9,7 @@ import io.swagger.annotations.ApiOperation;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@ -34,7 +36,10 @@ public class PermissionController {
|
|||||||
return success(permissionManager.listRoleResource(roleId));
|
return success(permissionManager.listRoleResource(roleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommonResult<Boolean> assignRoleResource() {
|
@PostMapping("/assign-role-resource")
|
||||||
|
@ApiOperation("赋予角色资源")
|
||||||
|
public CommonResult<Boolean> assignRoleResource(PermissionAssignRoleResourceDTO assignRoleResourceDTO) {
|
||||||
|
permissionManager.assignRoleResource(assignRoleResourceDTO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import lombok.Data;
|
|||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,7 +12,7 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class PermissionAssignRoleResourceDTO {
|
public class PermissionAssignRoleResourceDTO implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色编号
|
* 角色编号
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
package cn.iocoder.mall.systemservice.manager.permission;
|
package cn.iocoder.mall.systemservice.manager.permission;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||||
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO;
|
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO;
|
||||||
import cn.iocoder.mall.systemservice.service.permission.PermissionService;
|
import cn.iocoder.mall.systemservice.service.permission.PermissionService;
|
||||||
|
import cn.iocoder.mall.systemservice.service.permission.ResourceService;
|
||||||
|
import cn.iocoder.mall.systemservice.service.permission.RoleService;
|
||||||
|
import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,6 +20,10 @@ public class PermissionManager {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
|
@Autowired
|
||||||
|
private RoleService roleService;
|
||||||
|
@Autowired
|
||||||
|
private ResourceService resourceService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得角色拥有的资源编号
|
* 获得角色拥有的资源编号
|
||||||
@ -23,6 +32,11 @@ public class PermissionManager {
|
|||||||
* @return 资源编号列表
|
* @return 资源编号列表
|
||||||
*/
|
*/
|
||||||
public Set<Integer> listRoleResourceId(Integer roleId) {
|
public Set<Integer> listRoleResourceId(Integer roleId) {
|
||||||
|
// 超级管理员,拥有所有资源
|
||||||
|
if (roleService.hasSuperAdmin(Collections.singleton(roleId))) {
|
||||||
|
return CollectionUtils.convertSet(resourceService.listResource(), ResourceBO::getId);
|
||||||
|
}
|
||||||
|
// 非超级管理员,查询拥有资源
|
||||||
return permissionService.listRoleResourceId(roleId);
|
return permissionService.listRoleResourceId(roleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
<mapper namespace="cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.AdminRoleMapper">
|
<mapper namespace="cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.AdminRoleMapper">
|
||||||
|
|
||||||
<insert id="insertList">
|
<insert id="insertList">
|
||||||
INSERT INTO account_role (
|
INSERT INTO permission_admin_role (
|
||||||
account_id, role_id, create_time, deleted
|
admin_id, role_id, create_time, deleted
|
||||||
) VALUES
|
) VALUES
|
||||||
<foreach collection="accountRoleDOs" item="accountRole" separator=",">
|
<foreach collection="adminRoleDOs" item="adminRole" separator=",">
|
||||||
(#{accountRole.accountId}, #{accountRole.roleId}, #{accountRole.createTime}, #{accountRole.deleted})
|
(#{adminRole.adminId}, #{adminRole.roleId}, #{adminRole.createTime}, #{adminRole.deleted})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<mapper namespace="cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleResourceMapper">
|
<mapper namespace="cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleResourceMapper">
|
||||||
|
|
||||||
<insert id="insertList">
|
<insert id="insertList">
|
||||||
INSERT INTO role_resource (
|
INSERT INTO permission_role_resource (
|
||||||
resource_id, role_id, create_time, deleted
|
resource_id, role_id, create_time, deleted
|
||||||
) VALUES
|
) VALUES
|
||||||
<foreach collection="roleResources" item="roleResource" separator=",">
|
<foreach collection="roleResources" item="roleResource" separator=",">
|
||||||
|
Loading…
Reference in New Issue
Block a user