|
@@ -1,10 +1,13 @@
|
1
|
1
|
package com.example.civilizedcity.controller;
|
2
|
2
|
|
|
3
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
3
|
4
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
4
|
5
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
5
|
6
|
import com.example.civilizedcity.common.BaseController;
|
|
7
|
+import com.example.civilizedcity.common.Constants;
|
6
|
8
|
import com.example.civilizedcity.common.ResponseBean;
|
7
|
9
|
import com.example.civilizedcity.common.StringUtils;
|
|
10
|
+import com.example.civilizedcity.entity.TdQuAnswer;
|
8
|
11
|
import com.example.civilizedcity.service.TaCheckItemAnService;
|
9
|
12
|
import com.example.civilizedcity.service.TdQuAnswerService;
|
10
|
13
|
import io.swagger.annotations.Api;
|
|
@@ -15,8 +18,11 @@ import org.springframework.web.bind.annotation.*;
|
15
|
18
|
import com.example.civilizedcity.entity.TdQuestion;
|
16
|
19
|
import com.example.civilizedcity.service.TdQuestionService;
|
17
|
20
|
|
18
|
|
- /**
|
|
21
|
+import java.util.List;
|
|
22
|
+
|
|
23
|
+/**
|
19
|
24
|
* 点位问题;(td_question)表控制层
|
|
25
|
+ *
|
20
|
26
|
* @author : http://njyunzhi.com
|
21
|
27
|
* @date : 2022-12-13
|
22
|
28
|
*/
|
|
@@ -24,15 +30,15 @@ import com.example.civilizedcity.service.TdQuestionService;
|
24
|
30
|
@RestController
|
25
|
31
|
@RequestMapping("/")
|
26
|
32
|
public class TdQuestionController extends BaseController {
|
27
|
|
-
|
|
33
|
+
|
28
|
34
|
@Autowired
|
29
|
35
|
private TdQuestionService tdQuestionService;
|
30
|
36
|
|
31
|
|
- @Autowired
|
32
|
|
- private TdQuAnswerService tdQuAnswerService;
|
33
|
|
-
|
34
|
|
- /**
|
35
|
|
- * 通过ID查询单条数据
|
|
37
|
+ @Autowired
|
|
38
|
+ private TdQuAnswerService tdQuAnswerService;
|
|
39
|
+
|
|
40
|
+ /**
|
|
41
|
+ * 通过ID查询单条数据
|
36
|
42
|
*
|
37
|
43
|
* @param quId 主键
|
38
|
44
|
* @return 实例对象
|
|
@@ -42,28 +48,39 @@ public class TdQuestionController extends BaseController {
|
42
|
48
|
public ResponseBean queryById(@ApiParam("对象ID") @PathVariable String id) throws Exception {
|
43
|
49
|
return ResponseBean.success(tdQuestionService.getById(id));
|
44
|
50
|
}
|
45
|
|
-
|
46
|
|
- /**
|
|
51
|
+
|
|
52
|
+ /**
|
47
|
53
|
* 分页查询
|
48
|
54
|
*
|
49
|
|
- * @param pageNum 当前页码
|
|
55
|
+ * @param pageNum 当前页码
|
50
|
56
|
* @param pageSize 每页条数
|
51
|
57
|
* @return 查询结果
|
52
|
58
|
*/
|
53
|
59
|
@ApiOperation("分页查询")
|
54
|
60
|
@GetMapping("/tdQuestion")
|
55
|
|
- public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
56
|
|
- @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
|
57
|
|
-
|
|
61
|
+ public ResponseBean list(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
|
62
|
+ @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
|
63
|
+ @ApiParam("标题") @RequestParam(value = "title", required = false) String title) throws Exception {
|
|
64
|
+
|
58
|
65
|
IPage<TdQuestion> pg = new Page<>(pageNum, pageSize);
|
59
|
|
- // QueryWrapper<TdQuestion> queryWrapper = new QueryWrapper<>();
|
60
|
|
- // queryWrapper.orderByDesc("create_date");
|
61
|
|
- IPage<TdQuestion> result = tdQuestionService.page(pg);
|
62
|
|
-
|
|
66
|
+ QueryWrapper<TdQuestion> queryWrapper = new QueryWrapper<>();
|
|
67
|
+ queryWrapper.like(!StringUtils.isEmpty(title), "title", title);
|
|
68
|
+ queryWrapper.gt("status", Constants.STATUS_DELETE);
|
|
69
|
+ queryWrapper.orderByDesc("create_date");
|
|
70
|
+ IPage<TdQuestion> result = tdQuestionService.page(pg, queryWrapper);
|
|
71
|
+
|
|
72
|
+ List<TdQuestion> records = result.getRecords();
|
|
73
|
+ if (null != records || records.size() > 0) {
|
|
74
|
+ for (TdQuestion tdQuestion : records) {
|
|
75
|
+ List<TdQuAnswer> answerList = tdQuAnswerService.getListByQuId(tdQuestion.getQuId());
|
|
76
|
+ tdQuestion.setQuAnswerList(answerList);
|
|
77
|
+ }
|
|
78
|
+ }
|
|
79
|
+
|
63
|
80
|
return ResponseBean.success(result);
|
64
|
81
|
}
|
65
|
|
-
|
66
|
|
- /**
|
|
82
|
+
|
|
83
|
+ /**
|
67
|
84
|
* 新增数据
|
68
|
85
|
*
|
69
|
86
|
* @param tdQuestion 实例对象
|
|
@@ -84,8 +101,8 @@ public class TdQuestionController extends BaseController {
|
84
|
101
|
tdQuAnswerService.mergeData(tdQuestion.getQuId(), tdQuestion.getQuAnswerList());
|
85
|
102
|
return ResponseBean.success(tdQuestion);
|
86
|
103
|
}
|
87
|
|
-
|
88
|
|
- /**
|
|
104
|
+
|
|
105
|
+ /**
|
89
|
106
|
* 更新数据
|
90
|
107
|
*
|
91
|
108
|
* @param tdQuestion 实例对象
|
|
@@ -94,12 +111,12 @@ public class TdQuestionController extends BaseController {
|
94
|
111
|
@ApiOperation("更新数据")
|
95
|
112
|
@PutMapping("/tdQuestion/{id}")
|
96
|
113
|
public ResponseBean edit(@ApiParam("对象实体") @RequestBody TdQuestion tdQuestion,
|
97
|
|
- @ApiParam("对象ID") @PathVariable String id ) throws Exception {
|
|
114
|
+ @ApiParam("对象ID") @PathVariable String id) throws Exception {
|
98
|
115
|
tdQuestionService.updateById(tdQuestion);
|
99
|
116
|
return ResponseBean.success(tdQuestion);
|
100
|
117
|
}
|
101
|
|
-
|
102
|
|
- /**
|
|
118
|
+
|
|
119
|
+ /**
|
103
|
120
|
* 通过主键删除数据
|
104
|
121
|
*
|
105
|
122
|
* @param quId 主键
|
|
@@ -107,7 +124,7 @@ public class TdQuestionController extends BaseController {
|
107
|
124
|
*/
|
108
|
125
|
@ApiOperation("通过主键删除数据")
|
109
|
126
|
@DeleteMapping("/tdQuestion/{id}")
|
110
|
|
- public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id){
|
|
127
|
+ public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id) {
|
111
|
128
|
tdQuestionService.removeLogicById(id);
|
112
|
129
|
return ResponseBean.success("success");
|
113
|
130
|
}
|