|
@@ -4,8 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
4
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
5
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
6
|
import com.example.civilizedcity.common.BaseController;
|
|
7
|
+import com.example.civilizedcity.common.Constants;
|
7
|
8
|
import com.example.civilizedcity.common.ResponseBean;
|
|
9
|
+
|
|
10
|
+import java.time.LocalDateTime;
|
8
|
11
|
import java.util.List;
|
|
12
|
+
|
|
13
|
+import com.example.civilizedcity.common.StringUtils;
|
9
|
14
|
import io.swagger.annotations.Api;
|
10
|
15
|
import io.swagger.annotations.ApiOperation;
|
11
|
16
|
import io.swagger.annotations.ApiParam;
|
|
@@ -14,8 +19,9 @@ import org.springframework.web.bind.annotation.*;
|
14
|
19
|
import com.example.civilizedcity.entity.TaNotice;
|
15
|
20
|
import com.example.civilizedcity.service.TaNoticeService;
|
16
|
21
|
|
17
|
|
- /**
|
|
22
|
+/**
|
18
|
23
|
* 通知公告;(ta_notice)表控制层
|
|
24
|
+ *
|
19
|
25
|
* @author : http://njyunzhi.com
|
20
|
26
|
* @date : 2022-12-12
|
21
|
27
|
*/
|
|
@@ -23,14 +29,14 @@ import com.example.civilizedcity.service.TaNoticeService;
|
23
|
29
|
@RestController
|
24
|
30
|
@RequestMapping("/")
|
25
|
31
|
public class TaNoticeController extends BaseController {
|
26
|
|
-
|
|
32
|
+
|
27
|
33
|
@Autowired
|
28
|
34
|
private TaNoticeService taNoticeService;
|
29
|
|
-
|
30
|
|
- /**
|
31
|
|
- * 通过ID查询单条数据
|
|
35
|
+
|
|
36
|
+ /**
|
|
37
|
+ * 通过ID查询单条数据
|
32
|
38
|
*
|
33
|
|
- * @param noticeId 主键
|
|
39
|
+ * @param id 主键
|
34
|
40
|
* @return 实例对象
|
35
|
41
|
*/
|
36
|
42
|
@ApiOperation("通过ID查询单条数据")
|
|
@@ -38,28 +44,32 @@ public class TaNoticeController extends BaseController {
|
38
|
44
|
public ResponseBean queryById(@ApiParam("对象ID") @PathVariable String id) throws Exception {
|
39
|
45
|
return ResponseBean.success(taNoticeService.getById(id));
|
40
|
46
|
}
|
41
|
|
-
|
42
|
|
- /**
|
|
47
|
+
|
|
48
|
+ /**
|
43
|
49
|
* 分页查询
|
44
|
50
|
*
|
45
|
|
- * @param pageNum 当前页码
|
|
51
|
+ * @param pageNum 当前页码
|
46
|
52
|
* @param pageSize 每页条数
|
47
|
53
|
* @return 查询结果
|
48
|
54
|
*/
|
49
|
55
|
@ApiOperation("分页查询")
|
50
|
56
|
@GetMapping("/taNotice")
|
51
|
|
- public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
52
|
|
- @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
|
53
|
|
-
|
|
57
|
+ public ResponseBean list(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
|
58
|
+ @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
|
59
|
+ @ApiParam("发布状态") @RequestParam(value = "status", required = false) Integer status) throws Exception {
|
|
60
|
+
|
54
|
61
|
IPage<TaNotice> pg = new Page<>(pageNum, pageSize);
|
55
|
|
- // QueryWrapper<TaNotice> queryWrapper = new QueryWrapper<>();
|
56
|
|
- // queryWrapper.orderByDesc("create_date");
|
57
|
|
- IPage<TaNotice> result = taNoticeService.page(pg);
|
58
|
|
-
|
|
62
|
+ QueryWrapper<TaNotice> queryWrapper = new QueryWrapper<>();
|
|
63
|
+ queryWrapper.eq(null != status, "status", status);
|
|
64
|
+ queryWrapper.gt("status", Constants.STATUS_DELETE);
|
|
65
|
+ queryWrapper.orderByDesc("weight");
|
|
66
|
+ queryWrapper.orderByDesc("create_date");
|
|
67
|
+ IPage<TaNotice> result = taNoticeService.page(pg, queryWrapper);
|
|
68
|
+
|
59
|
69
|
return ResponseBean.success(result);
|
60
|
70
|
}
|
61
|
|
-
|
62
|
|
- /**
|
|
71
|
+
|
|
72
|
+ /**
|
63
|
73
|
* 新增数据
|
64
|
74
|
*
|
65
|
75
|
* @param taNotice 实例对象
|
|
@@ -68,11 +78,19 @@ public class TaNoticeController extends BaseController {
|
68
|
78
|
@ApiOperation("新增数据")
|
69
|
79
|
@PostMapping("/taNotice")
|
70
|
80
|
public ResponseBean add(@ApiParam("对象实体") @RequestBody TaNotice taNotice) throws Exception {
|
|
81
|
+ taNotice.setNoticeId(null);
|
|
82
|
+
|
|
83
|
+ if (StringUtils.isEmpty(taNotice.getTitle())) {
|
|
84
|
+ return ResponseBean.error("公告标题不能为空");
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ taNotice.setCreateDate(LocalDateTime.now());
|
|
88
|
+
|
71
|
89
|
taNoticeService.save(taNotice);
|
72
|
90
|
return ResponseBean.success(taNotice);
|
73
|
91
|
}
|
74
|
|
-
|
75
|
|
- /**
|
|
92
|
+
|
|
93
|
+ /**
|
76
|
94
|
* 更新数据
|
77
|
95
|
*
|
78
|
96
|
* @param taNotice 实例对象
|
|
@@ -81,20 +99,26 @@ public class TaNoticeController extends BaseController {
|
81
|
99
|
@ApiOperation("更新数据")
|
82
|
100
|
@PutMapping("/taNotice/{id}")
|
83
|
101
|
public ResponseBean edit(@ApiParam("对象实体") @RequestBody TaNotice taNotice,
|
84
|
|
- @ApiParam("对象ID") @PathVariable String id ) throws Exception {
|
|
102
|
+ @ApiParam("对象ID") @PathVariable String id) throws Exception {
|
|
103
|
+ taNotice.setNoticeId(id);
|
|
104
|
+
|
|
105
|
+ if (StringUtils.isEmpty(taNotice.getTitle())) {
|
|
106
|
+ return ResponseBean.error("公告标题不能为空");
|
|
107
|
+ }
|
|
108
|
+
|
85
|
109
|
taNoticeService.updateById(taNotice);
|
86
|
110
|
return ResponseBean.success(taNotice);
|
87
|
111
|
}
|
88
|
|
-
|
89
|
|
- /**
|
|
112
|
+
|
|
113
|
+ /**
|
90
|
114
|
* 通过主键删除数据
|
91
|
115
|
*
|
92
|
|
- * @param noticeId 主键
|
|
116
|
+ * @param id 主键
|
93
|
117
|
* @return 是否成功
|
94
|
118
|
*/
|
95
|
119
|
@ApiOperation("通过主键删除数据")
|
96
|
120
|
@DeleteMapping("/taNotice/{id}")
|
97
|
|
- public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id){
|
|
121
|
+ public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id) {
|
98
|
122
|
taNoticeService.removeLogicById(id);
|
99
|
123
|
return ResponseBean.success("success");
|
100
|
124
|
}
|