角色模块的 CRUD + 分配资源

This commit is contained in:
YunaiV
2019-03-01 19:03:13 +08:00
parent 814ca633aa
commit 16d33b25be
26 changed files with 824 additions and 85 deletions

View File

@@ -14,11 +14,11 @@ public interface ResourceService {
/**
* 查询指定类型 + 指定角色的资源列表
*
* @param type 指定类型。
* @param type 指定类型。可以为空,此时不作为过滤条件
* @param roleIds 指定角色的数组。
* @return 资源列表
*/
List<ResourceBO> getResourcesByTypeAndRoleIds(Integer type, Set<Integer> roleIds);
List<ResourceBO> getResourcesByTypeAndRoleIds(@Nullable Integer type, Set<Integer> roleIds);
/**
* 查询指定类型的资源列表

View File

@@ -1,4 +1,24 @@
package cn.iocoder.mall.admin.api;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.admin.api.bo.RoleBO;
import cn.iocoder.mall.admin.api.bo.RolePageBO;
import cn.iocoder.mall.admin.api.dto.RoleAddDTO;
import cn.iocoder.mall.admin.api.dto.RolePageDTO;
import cn.iocoder.mall.admin.api.dto.RoleUpdateDTO;
import java.util.Set;
public interface RoleService {
}
CommonResult<RolePageBO> getRolePage(RolePageDTO rolePageDTO);
CommonResult<RoleBO> addRole(Integer adminId, RoleAddDTO roleAddDTO);
CommonResult<Boolean> updateRole(Integer adminId, RoleUpdateDTO roleUpdateDTO);
CommonResult<Boolean> deleteRole(Integer adminId, Integer roleId);
CommonResult<Boolean> assignResource(Integer adminId, Integer roleId, Set<Integer> resourceIds);
}

View File

@@ -0,0 +1,50 @@
package cn.iocoder.mall.admin.api.bo;
import java.util.Date;
/**
* 角色 BO
*/
public class RoleBO {
/**
* 角色编号
*/
private Integer id;
/**
* 角色名字
*/
private String name;
/**
* 添加时间
*/
private Date createTime;
public Integer getId() {
return id;
}
public RoleBO setId(Integer id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public RoleBO setName(String name) {
this.name = name;
return this;
}
public Date getCreateTime() {
return createTime;
}
public RoleBO setCreateTime(Date createTime) {
this.createTime = createTime;
return this;
}
}

View File

@@ -0,0 +1,34 @@
package cn.iocoder.mall.admin.api.bo;
import java.util.List;
public class RolePageBO {
/**
* 角色数组
*/
private List<RoleBO> roles;
/**
* 总量
*/
private Integer count;
public List<RoleBO> getRoles() {
return roles;
}
public RolePageBO setRoles(List<RoleBO> roles) {
this.roles = roles;
return this;
}
public Integer getCount() {
return count;
}
public RolePageBO setCount(Integer count) {
this.count = count;
return this;
}
}

View File

@@ -31,6 +31,10 @@ public enum AdminErrorCodeEnum {
RESOURCE_PARENT_ERROR(1002003002, "不能设置自己为父资源"),
RESOURCE_NOT_EXISTS(1002003003, "资源不存在"),
RESOURCE_EXISTS_CHILDREN(1002003004, "存在子资源,无法删除"),
// ========== 角色模块 1002004000 ==========
ROLE_NOT_EXISTS(1002004000, "角色不存在"),
ROLE_ASSIGN_RESOURCE_NOT_EXISTS(1002004001, "分配角色资源时,有资源不存在"),
;
private final int code;

View File

@@ -0,0 +1,25 @@
package cn.iocoder.mall.admin.api.dto;
import javax.validation.constraints.NotEmpty;
/**
* 角色添加 DTO
*/
public class RoleAddDTO {
/**
* 角色名字(标识)
*/
@NotEmpty(message = "角色名字不能为空")
private String name;
public String getName() {
return name;
}
public RoleAddDTO setName(String name) {
this.name = name;
return this;
}
}

View File

@@ -0,0 +1,35 @@
package cn.iocoder.mall.admin.api.dto;
public class RolePageDTO {
private Integer pageNo;
private Integer pageSize;
private String name;
public Integer getPageNo() {
return pageNo;
}
public RolePageDTO setPageNo(Integer pageNo) {
this.pageNo = pageNo;
return this;
}
public Integer getPageSize() {
return pageSize;
}
public RolePageDTO setPageSize(Integer pageSize) {
this.pageSize = pageSize;
return this;
}
public String getName() {
return name;
}
public RolePageDTO setName(String name) {
this.name = name;
return this;
}
}

View File

@@ -0,0 +1,40 @@
package cn.iocoder.mall.admin.api.dto;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 角色添加 DTO
*/
public class RoleUpdateDTO {
/**
* 角色编号
*/
@NotNull(message = "角色编号不能为空")
private Integer id;
/**
* 角色名字(标识)
*/
@NotEmpty(message = "角色名字不能为空")
private String name;
public Integer getId() {
return id;
}
public RoleUpdateDTO setId(Integer id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public RoleUpdateDTO setName(String name) {
this.name = name;
return this;
}
}