完成资源模块的改造

This commit is contained in:
YunaiV
2020-07-07 21:14:35 +08:00
parent 8af7b252aa
commit 4c4708cc8f
41 changed files with 1272 additions and 439 deletions

View File

@@ -0,0 +1,33 @@
### /resource/create 成功
POST {{baseUrl}}/resource/create
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}
name=测试菜单&permission=resource:add&type=1&sort=1&pid=0&route=/resource/list&icon=test
### /admin/update 成功
POST {{baseUrl}}/resource/update
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}
id=61&name=测试菜单2&permission=resource:add&type=1&sort=1&pid=0&route=/resource/list&icon=test
### /resource/delete 成功
POST {{baseUrl}}/resource/delete
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}
resourceId=61
### /resource/get 成功
GET {{baseUrl}}/resource/get?resourceId=61
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}
### /resource/list 成功
GET {{baseUrl}}/resource/list?resourceIds=61,63
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}
###

View File

@@ -0,0 +1,67 @@
package cn.iocoder.mall.managementweb.controller.permission;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO;
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO;
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO;
import cn.iocoder.mall.managementweb.manager.permission.ResourceManager;
import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* 资源 Controller
*/
@RestController
@RequestMapping("/resource")
@Api(tags = "资源")
@Validated
public class ResourceController {
@Autowired
private ResourceManager resourceManager;
@PostMapping("/create")
@ApiOperation("创建资源")
public CommonResult<Integer> createResource(@Valid ResourceCreateDTO createDTO) {
return success(resourceManager.createResource(createDTO, AdminSecurityContextHolder.getAdminId()));
}
@PostMapping("/update")
@ApiOperation("更新资源")
public CommonResult<Boolean> updateResource(@Valid ResourceUpdateDTO updateDTO) {
resourceManager.updateResource(updateDTO);
return success(true);
}
@PostMapping("/delete")
@ApiOperation("删除资源")
@ApiImplicitParam(name = "resourceId", value = "资源编号", required = true)
public CommonResult<Boolean> deleteResource(@RequestParam("resourceId") Integer resourceId) {
resourceManager.deleteResource(resourceId);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得资源")
public CommonResult<ResourceVO> getResource(@RequestParam("resourceId") Integer resourceId) {
return success(resourceManager.getResource(resourceId));
}
@GetMapping("/list")
@ApiOperation("获得资源列表")
@ApiImplicitParam(name = "resourceId", value = "资源编号列表", required = true)
public CommonResult<List<ResourceVO>> getResources(@RequestParam("resourceIds") List<Integer> resourceIds) {
return success(resourceManager.listResource(resourceIds));
}
}

View File

@@ -0,0 +1,36 @@
package cn.iocoder.mall.managementweb.controller.permission.dto;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("资源创建 DTO")
@Data
public class ResourceCreateDTO {
@ApiModelProperty(value = "菜单名", required = true, example = "商品管理")
@NotEmpty(message = "菜单名不能为空")
private String name;
@ApiModelProperty(value = "权限标识", example = "resource:add")
private String permission;
@ApiModelProperty(value = "资源类型", required = true, example = "1")
@NotNull(message = "资源类型不能为空")
@InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}")
private Integer type;
@ApiModelProperty(value = "排序", required = true, example = "1")
@NotNull(message = "排序不能为空")
private Integer sort;
@ApiModelProperty(value = "父级资源编号", required = true, example = "1", notes = "如果无父资源,则值为 0")
@NotNull(message = "父级资源编号不能为空")
private Integer pid;
@ApiModelProperty(value = "前端路由", example = "/resource/list")
private String route;
@ApiModelProperty(value = "菜单图标", example = "add")
private String icon;
}

View File

@@ -0,0 +1,39 @@
package cn.iocoder.mall.managementweb.controller.permission.dto;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("资源创建 DTO")
@Data
public class ResourceUpdateDTO {
@ApiModelProperty(value = "资源编号", required = true, example = "1")
@NotNull(message = "资源编号不能为空")
private Integer id;
@ApiModelProperty(value = "菜单名", required = true, example = "商品管理")
@NotEmpty(message = "菜单名不能为空")
private String name;
@ApiModelProperty(value = "权限标识", example = "resource:add")
private String permission;
@ApiModelProperty(value = "资源类型", required = true, example = "1")
@NotNull(message = "资源类型不能为空")
@InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}")
private Integer type;
@ApiModelProperty(value = "排序", required = true, example = "1")
@NotNull(message = "排序不能为空")
private Integer sort;
@ApiModelProperty(value = "父级资源编号", required = true, example = "1", notes = "如果无父资源,则值为 0")
@NotNull(message = "父级资源编号不能为空")
private Integer pid;
@ApiModelProperty(value = "前端路由", example = "/resource/list")
private String route;
@ApiModelProperty(value = "菜单图标", example = "add")
private String icon;
}

View File

@@ -0,0 +1,41 @@
package cn.iocoder.mall.managementweb.controller.permission.vo;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum;
import lombok.*;
import io.swagger.annotations.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.*;
@ApiModel("资源 VO")
@Data
public class ResourceVO {
@ApiModelProperty(value = "资源编号", required = true, example = "1")
@NotNull(message = "资源编号不能为空")
private Integer id;
@ApiModelProperty(value = "菜单名", required = true, example = "商品管理")
@NotEmpty(message = "菜单名不能为空")
private String name;
@ApiModelProperty(value = "权限标识", example = "resource:add")
private String permission;
@ApiModelProperty(value = "资源类型", required = true, example = "1")
@NotNull(message = "资源类型不能为空")
@InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}")
private Integer type;
@ApiModelProperty(value = "排序", required = true, example = "1")
@NotNull(message = "排序不能为空")
private Integer sort;
@ApiModelProperty(value = "父级资源编号", required = true, example = "1", notes = "如果无父资源,则值为 0")
@NotNull(message = "父级资源编号不能为空")
private Integer pid;
@ApiModelProperty(value = "前端路由", example = "/resource/list")
private String route;
@ApiModelProperty(value = "菜单图标", example = "add")
private String icon;
@ApiModelProperty(value = "添加时间", required = true)
private Date createTime;
}