Skip to content

Commit 402fb19

Browse files
committed
优化资源crud接口
1 parent 1dcbc32 commit 402fb19

5 files changed

Lines changed: 42 additions & 20 deletions

File tree

sysadmin/db/db.sql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ VALUES (101, '新增用户', 'user_manager:btn_add', 'button', '/user', 'POST',
217217
(309, '删除网关路由', 'gateway_manager:adel', 'url', '/gateway/routes/{id}', 'DELETE', '删除网关路由', now(), now(), 'system', 'system'),
218218
(310, '查看网关路由', 'gateway_manager:view', 'url', '/gateway/routes/{id}', 'GET', '查看网关路由', now(), now(), 'system', 'system'),
219219
(311, '搜索网关路由', 'gateway_manager:query', 'url', '/gateway/routes/conditions', 'POST', '搜索网关路由', now(), now(), 'system', 'system'),
220-
(312, '全局加载路由', 'gateway_manager:overload', 'url', '/gateway/routes/overload', 'POST', '全局加载路由', now(), now(), 'system', 'system');
220+
(312, '全局加载路由', 'gateway_manager:overload', 'url', '/gateway/routes/overload', 'POST', '全局加载路由', now(), now(), 'system', 'system'),
221+
(313, '新增网关路由', 'resource_manager:add', 'url', '/resource', 'POST', '新增资源路由', now(), now(), 'system', 'system'),
222+
(314, '修改网关路由', 'resource_manager:edit', 'url', '/resource/{id}', 'PUT', '修改资源', now(), now(), 'system', 'system'),
223+
(315, '删除网关路由', 'resource_manager:adel', 'url', '/resource/{id}', 'DELETE', '删除资源', now(), now(), 'system', 'system'),
224+
(316, '查看网关路由', 'resource_manager:view', 'url', '/resource/{id}', 'GET', '查看资源', now(), now(), 'system', 'system'),
225+
(317, '搜索网关路由', 'resource_manager:query', 'url', '/resource/conditions', 'POST', '搜索资源', now(), now(), 'system', 'system'),
226+
(318, '全局加载路由', 'resource_manager:all', 'url', '/resource/all', 'GET', '查询全部资源', now(), now(), 'system', 'system');
221227

222228
-- 用户关系授权
223229
INSERT INTO user_role_relation (id, user_id, role_id, created_time, updated_time, created_by, updated_by)
@@ -269,7 +275,13 @@ VALUES (101, 101, 101, now(), now(), 'system', 'system'),
269275
(403, 101, 309, now(), now(), 'system', 'system'),
270276
(404, 101, 310, now(), now(), 'system', 'system'),
271277
(405, 101, 311, now(), now(), 'system', 'system'),
272-
(406, 101, 312, now(), now(), 'system', 'system');
278+
(406, 101, 312, now(), now(), 'system', 'system'),
279+
(501, 101, 313, now(), now(), 'system', 'system'),
280+
(502, 101, 314, now(), now(), 'system', 'system'),
281+
(503, 101, 315, now(), now(), 'system', 'system'),
282+
(504, 101, 316, now(), now(), 'system', 'system'),
283+
(505, 101, 317, now(), now(), 'system', 'system'),
284+
(506, 101, 318, now(), now(), 'system', 'system');
273285

274286
-- 岗位
275287
INSERT INTO position (id, name, description, created_time, updated_time, created_by, updated_by)

sysadmin/organization/src/main/java/com/springboot/cloud/sysadmin/organization/entity/form/ResourceQueryForm.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,22 @@
77
import lombok.Data;
88
import org.springframework.format.annotation.DateTimeFormat;
99

10-
import javax.validation.constraints.NotBlank;
1110
import javax.validation.constraints.Past;
1211
import java.util.Date;
1312

1413
@ApiModel
1514
@Data
1615
public class ResourceQueryForm extends BaseQueryForm<ResourceQueryParam> {
1716

18-
@NotBlank(message = "资源名称不能为空")
1917
@ApiModelProperty(value = "资源名称")
2018
private String name;
2119

22-
@NotBlank(message = "资源编码不能为空")
2320
@ApiModelProperty(value = "资源编码")
2421
private String code;
2522

26-
@NotBlank(message = "资源路径不能为空")
2723
@ApiModelProperty(value = "资源路径")
2824
private String url;
2925

30-
@NotBlank(message = "资源方法不能为空")
3126
@ApiModelProperty(value = "资源方法")
3227
private String method;
3328

sysadmin/organization/src/main/java/com/springboot/cloud/sysadmin/organization/rest/ResourceController.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.springboot.cloud.common.core.entity.vo.Result;
44
import com.springboot.cloud.sysadmin.organization.entity.form.ResourceForm;
5+
import com.springboot.cloud.sysadmin.organization.entity.form.ResourceQueryForm;
56
import com.springboot.cloud.sysadmin.organization.entity.param.ResourceQueryParam;
67
import com.springboot.cloud.sysadmin.organization.entity.po.Resource;
78
import com.springboot.cloud.sysadmin.organization.service.IResourceService;
@@ -74,19 +75,17 @@ public Result queryByUsername(@PathVariable String username) {
7475
)
7576
@GetMapping(value = "/all")
7677
public Result queryAll() {
77-
return Result.success(resourceService.query(new ResourceQueryParam()));
78+
return Result.success(resourceService.queryAll());
7879
}
7980

80-
@ApiOperation(value = "查询资源", notes = "根据条件查询资源信息,简单查询")
81-
@ApiImplicitParam(paramType = "query", name = "name", value = "资源名称", required = true, dataType = "string")
81+
@ApiOperation(value = "搜索资源", notes = "根据条件搜索资源信息")
82+
@ApiImplicitParam(name = "resourceQueryForm", value = "资源查询参数", required = true, dataType = "RoleQueryForm")
8283
@ApiResponses(
8384
@ApiResponse(code = 200, message = "处理成功", response = Result.class)
8485
)
85-
@GetMapping
86-
public Result query(@RequestParam String name) {
87-
log.debug("query with name:{}", name);
88-
ResourceQueryParam resourceQueryParam = new ResourceQueryParam();
89-
resourceQueryParam.setName(name);
90-
return Result.success(resourceService.query(resourceQueryParam));
86+
@PostMapping(value = "/conditions")
87+
public Result query(@Valid @RequestBody ResourceQueryForm resourceQueryForm) {
88+
log.debug("query with name:{}", resourceQueryForm);
89+
return Result.success(resourceService.query(resourceQueryForm.getPage(), resourceQueryForm.toParam(ResourceQueryParam.class)));
9190
}
9291
}

sysadmin/organization/src/main/java/com/springboot/cloud/sysadmin/organization/service/IResourceService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.springboot.cloud.sysadmin.organization.service;
22

3+
import com.baomidou.mybatisplus.core.metadata.IPage;
4+
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
35
import com.springboot.cloud.sysadmin.organization.entity.param.ResourceQueryParam;
46
import com.springboot.cloud.sysadmin.organization.entity.po.Resource;
57

@@ -23,11 +25,18 @@ public interface IResourceService {
2325
boolean add(Resource resource);
2426

2527
/**
26-
* 查询资源
28+
* 查询资源,分页
2729
*
2830
* @return
2931
*/
30-
List<Resource> query(ResourceQueryParam resourceQueryParam);
32+
IPage<Resource> query(Page page, ResourceQueryParam resourceQueryParam);
33+
34+
/**
35+
* 查询所有资源
36+
*
37+
* @return
38+
*/
39+
List<Resource> queryAll();
3140

3241
/**
3342
* 根据username查询角色拥有的资源

sysadmin/organization/src/main/java/com/springboot/cloud/sysadmin/organization/service/impl/ResourceService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.alicp.jetcache.anno.CacheType;
44
import com.alicp.jetcache.anno.Cached;
55
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
6+
import com.baomidou.mybatisplus.core.metadata.IPage;
7+
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
68
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
79
import com.springboot.cloud.sysadmin.organization.config.BusConfig;
810
import com.springboot.cloud.sysadmin.organization.dao.ResourceMapper;
@@ -66,13 +68,18 @@ public Resource get(String id) {
6668
}
6769

6870
@Override
69-
public List<Resource> query(ResourceQueryParam resourceQueryParam) {
71+
public IPage<Resource> query(Page page, ResourceQueryParam resourceQueryParam) {
7072
QueryWrapper<Resource> queryWrapper = resourceQueryParam.build();
7173
queryWrapper.eq(StringUtils.isNotBlank(resourceQueryParam.getName()), "name", resourceQueryParam.getName());
7274
queryWrapper.eq(StringUtils.isNotBlank(resourceQueryParam.getType()), "type", resourceQueryParam.getType());
7375
queryWrapper.eq(StringUtils.isNotBlank(resourceQueryParam.getUrl()), "url", resourceQueryParam.getUrl());
7476
queryWrapper.eq(StringUtils.isNotBlank(resourceQueryParam.getMethod()), "method", resourceQueryParam.getMethod());
75-
return this.list(queryWrapper);
77+
return this.page(page, queryWrapper);
78+
}
79+
80+
@Override
81+
public List<Resource> queryAll() {
82+
return this.list();
7683
}
7784

7885
@Override

0 commit comments

Comments
 (0)