完成角色权限分配功能的迁移

pull/3/head
YunaiV 2020-07-13 09:26:00 +08:00
parent d34e555aa0
commit 99c591d6f9
6 changed files with 33 additions and 7 deletions

View File

@ -0,0 +1,6 @@
### /permission/list 成功
GET {{baseUrl}}/permission/list-role-resource?roleId=1
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}
###

View File

@ -1,6 +1,7 @@
package cn.iocoder.mall.managementweb.controller.permission;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -8,6 +9,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.RestController;
@ -34,7 +36,10 @@ public class PermissionController {
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);
}

View File

@ -4,6 +4,7 @@ import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Set;
/**
@ -11,7 +12,7 @@ import java.util.Set;
*/
@Data
@Accessors(chain = true)
public class PermissionAssignRoleResourceDTO {
public class PermissionAssignRoleResourceDTO implements Serializable {
/**
*

View File

@ -1,10 +1,15 @@
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.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.stereotype.Service;
import java.util.Collections;
import java.util.Set;
/**
@ -15,6 +20,10 @@ public class PermissionManager {
@Autowired
private PermissionService permissionService;
@Autowired
private RoleService roleService;
@Autowired
private ResourceService resourceService;
/**
*
@ -23,6 +32,11 @@ public class PermissionManager {
* @return
*/
public Set<Integer> listRoleResourceId(Integer roleId) {
// 超级管理员,拥有所有资源
if (roleService.hasSuperAdmin(Collections.singleton(roleId))) {
return CollectionUtils.convertSet(resourceService.listResource(), ResourceBO::getId);
}
// 非超级管理员,查询拥有资源
return permissionService.listRoleResourceId(roleId);
}

View File

@ -3,11 +3,11 @@
<mapper namespace="cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.AdminRoleMapper">
<insert id="insertList">
INSERT INTO account_role (
account_id, role_id, create_time, deleted
INSERT INTO permission_admin_role (
admin_id, role_id, create_time, deleted
) VALUES
<foreach collection="accountRoleDOs" item="accountRole" separator=",">
(#{accountRole.accountId}, #{accountRole.roleId}, #{accountRole.createTime}, #{accountRole.deleted})
<foreach collection="adminRoleDOs" item="adminRole" separator=",">
(#{adminRole.adminId}, #{adminRole.roleId}, #{adminRole.createTime}, #{adminRole.deleted})
</foreach>
</insert>

View File

@ -3,7 +3,7 @@
<mapper namespace="cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleResourceMapper">
<insert id="insertList">
INSERT INTO role_resource (
INSERT INTO permission_role_resource (
resource_id, role_id, create_time, deleted
) VALUES
<foreach collection="roleResources" item="roleResource" separator=",">