Skip to content

Commit 4b0d9b5

Browse files
committed
refactor: 使用dto代替接口的查询参数形参列表
1 parent d773d83 commit 4b0d9b5

4 files changed

Lines changed: 63 additions & 46 deletions

File tree

src/main/java/io/github/talelin/latticy/controller/cms/AdminController.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,11 @@
1313
import io.github.talelin.latticy.model.UserDO;
1414
import io.github.talelin.latticy.service.AdminService;
1515
import io.github.talelin.latticy.service.GroupService;
16-
import io.github.talelin.latticy.vo.CreatedVO;
17-
import io.github.talelin.latticy.vo.DeletedVO;
18-
import io.github.talelin.latticy.vo.PageResponseVO;
19-
import io.github.talelin.latticy.vo.UpdatedVO;
20-
import io.github.talelin.latticy.vo.UserInfoVO;
16+
import io.github.talelin.latticy.vo.*;
2117
import org.springframework.beans.factory.annotation.Autowired;
2218
import org.springframework.validation.annotation.Validated;
23-
import org.springframework.web.bind.annotation.DeleteMapping;
24-
import org.springframework.web.bind.annotation.GetMapping;
25-
import org.springframework.web.bind.annotation.PathVariable;
26-
import org.springframework.web.bind.annotation.PostMapping;
27-
import org.springframework.web.bind.annotation.PutMapping;
28-
import org.springframework.web.bind.annotation.RequestBody;
29-
import org.springframework.web.bind.annotation.RequestMapping;
30-
import org.springframework.web.bind.annotation.RequestParam;
31-
import org.springframework.web.bind.annotation.RestController;
32-
33-
import javax.validation.constraints.Max;
34-
import javax.validation.constraints.Min;
19+
import org.springframework.web.bind.annotation.*;
20+
3521
import javax.validation.constraints.Positive;
3622
import java.util.List;
3723
import java.util.Map;

src/main/java/io/github/talelin/latticy/controller/cms/LogController.java

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,17 @@
55
import io.github.talelin.core.annotation.PermissionMeta;
66
import io.github.talelin.core.annotation.PermissionModule;
77
import io.github.talelin.latticy.common.util.PageUtil;
8+
import io.github.talelin.latticy.dto.log.QueryLogDTO;
89
import io.github.talelin.latticy.dto.query.BasePageDTO;
910
import io.github.talelin.latticy.model.LogDO;
1011
import io.github.talelin.latticy.service.LogService;
1112
import io.github.talelin.latticy.vo.PageResponseVO;
1213
import org.springframework.beans.factory.annotation.Autowired;
13-
import org.springframework.format.annotation.DateTimeFormat;
1414
import org.springframework.validation.annotation.Validated;
1515
import org.springframework.web.bind.annotation.GetMapping;
1616
import org.springframework.web.bind.annotation.RequestMapping;
17-
import org.springframework.web.bind.annotation.RequestParam;
1817
import org.springframework.web.bind.annotation.RestController;
1918

20-
import javax.validation.constraints.Max;
21-
import javax.validation.constraints.Min;
22-
import java.util.Date;
23-
2419
/**
2520
* @author pedro@TaleLin
2621
* @author Juzi@TaleLin
@@ -36,33 +31,24 @@ public class LogController {
3631
@GetMapping("")
3732
@GroupRequired
3833
@PermissionMeta(value = "查询所有日志")
39-
public PageResponseVO<LogDO> getLogs(
40-
@RequestParam(name = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
41-
@RequestParam(name = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end,
42-
@RequestParam(name = "name", required = false) String name,
43-
@RequestParam(name = "count", required = false, defaultValue = "15")
44-
@Min(value = 1, message = "{page.count.min}")
45-
@Max(value = 30, message = "{page.count.max}") Integer count,
46-
@RequestParam(name = "page", required = false, defaultValue = "0")
47-
@Min(value = 0, message = "{page.number.min}") Integer page) {
48-
IPage<LogDO> iPage = logService.getLogPage(page, count, name, start, end);
34+
public PageResponseVO<LogDO> getLogs(QueryLogDTO dto) {
35+
IPage<LogDO> iPage = logService.getLogPage(
36+
dto.getPage(), dto.getCount(),
37+
dto.getName(), dto.getStart(),
38+
dto.getEnd()
39+
);
4940
return PageUtil.build(iPage);
5041
}
5142

5243
@GetMapping("/search")
5344
@GroupRequired
5445
@PermissionMeta(value = "搜索日志")
55-
public PageResponseVO<LogDO> searchLogs(
56-
@RequestParam(name = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
57-
@RequestParam(name = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end,
58-
@RequestParam(name = "name", required = false) String name,
59-
@RequestParam(name = "keyword", required = false, defaultValue = "") String keyword,
60-
@RequestParam(name = "count", required = false, defaultValue = "15")
61-
@Min(value = 1, message = "{page.count.min}")
62-
@Max(value = 30, message = "{page.count.max}") Integer count,
63-
@RequestParam(name = "page", required = false, defaultValue = "0")
64-
@Min(value = 0, message = "{page.number.min}") Integer page) {
65-
IPage<LogDO> iPage = logService.searchLogPage(page, count, name, keyword, start, end);
46+
public PageResponseVO<LogDO> searchLogs(QueryLogDTO dto) {
47+
IPage<LogDO> iPage = logService.searchLogPage(
48+
dto.getPage(), dto.getCount(),
49+
dto.getName(), dto.getKeyword(),
50+
dto.getStart(), dto.getEnd()
51+
);
6652
return PageUtil.build(iPage);
6753
}
6854

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.github.talelin.latticy.dto.log;
2+
3+
import io.github.talelin.latticy.dto.query.BasePageDTO;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import org.springframework.format.annotation.DateTimeFormat;
7+
8+
import java.util.Date;
9+
10+
/**
11+
* @author colorful@TaleLin
12+
*/
13+
@Data
14+
@EqualsAndHashCode(callSuper = true)
15+
public class QueryLogDTO extends BasePageDTO {
16+
17+
protected static Integer defaultCount = 12;
18+
19+
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
20+
private Date start;
21+
22+
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
23+
private Date end;
24+
25+
private String name;
26+
27+
private String keyword;
28+
29+
30+
}
31+

src/main/java/io/github/talelin/latticy/dto/query/BasePageDTO.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,23 @@ public class BasePageDTO {
1414

1515
@Min(value = 1, message = "{page.count.min}")
1616
@Max(value = 30, message = "{page.count.max}")
17-
private Integer count = 10;
17+
private Integer count;
1818

1919
@Min(value = 0, message = "{page.number.min}")
20-
private Integer page = 0;
20+
private Integer page;
21+
22+
public Integer getCount() {
23+
if (null == count) {
24+
return 10;
25+
}
26+
return count;
27+
}
28+
29+
public Integer getPage() {
30+
if (null == page) {
31+
return 0;
32+
}
33+
return page;
34+
}
2135

2236
}

0 commit comments

Comments
 (0)