|
@@ -3,26 +3,25 @@ package com.example.civilizedcity.controller;
|
3
|
3
|
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
|
|
-import com.example.civilizedcity.common.BaseController;
|
7
|
|
-import com.example.civilizedcity.common.Constants;
|
8
|
|
-import com.example.civilizedcity.common.ResponseBean;
|
|
6
|
+import com.example.civilizedcity.common.*;
|
9
|
7
|
|
10
|
8
|
import java.time.LocalDateTime;
|
11
|
9
|
import java.util.List;
|
12
|
10
|
|
13
|
|
-import com.example.civilizedcity.common.StringUtils;
|
14
|
|
-import com.example.civilizedcity.entity.TdLocType;
|
|
11
|
+import com.example.civilizedcity.entity.*;
|
|
12
|
+import com.example.civilizedcity.service.TaCheckAnswerService;
|
|
13
|
+import com.example.civilizedcity.service.TaCheckService;
|
15
|
14
|
import com.example.civilizedcity.service.TdLocTypeService;
|
16
|
15
|
import io.swagger.annotations.Api;
|
17
|
16
|
import io.swagger.annotations.ApiOperation;
|
18
|
17
|
import io.swagger.annotations.ApiParam;
|
19
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
19
|
import org.springframework.web.bind.annotation.*;
|
21
|
|
-import com.example.civilizedcity.entity.TaCheckItem;
|
22
|
20
|
import com.example.civilizedcity.service.TaCheckItemService;
|
23
|
21
|
|
24
|
|
- /**
|
|
22
|
+/**
|
25
|
23
|
* 测评点位;(ta_check_item)表控制层
|
|
24
|
+ *
|
26
|
25
|
* @author : http://njyunzhi.com
|
27
|
26
|
* @date : 2022-12-13
|
28
|
27
|
*/
|
|
@@ -30,13 +29,19 @@ import com.example.civilizedcity.service.TaCheckItemService;
|
30
|
29
|
@RestController
|
31
|
30
|
@RequestMapping("/")
|
32
|
31
|
public class TaCheckItemController extends BaseController {
|
33
|
|
-
|
|
32
|
+
|
34
|
33
|
@Autowired
|
35
|
34
|
private TaCheckItemService taCheckItemService;
|
36
|
35
|
|
37
|
36
|
@Autowired
|
38
|
37
|
private TdLocTypeService tdLocTypeService;
|
39
|
|
-
|
|
38
|
+
|
|
39
|
+ @Autowired
|
|
40
|
+ private TaCheckService taCheckService;
|
|
41
|
+
|
|
42
|
+ @Autowired
|
|
43
|
+ private TaCheckAnswerService taCheckAnswerService;
|
|
44
|
+
|
40
|
45
|
/**
|
41
|
46
|
* 通过ID查询单条数据
|
42
|
47
|
*
|
|
@@ -49,52 +54,52 @@ public class TaCheckItemController extends BaseController {
|
49
|
54
|
return ResponseBean.success(taCheckItemService.getById(id));
|
50
|
55
|
}
|
51
|
56
|
|
52
|
|
- /**
|
53
|
|
- * 通过测评以及点位查询数据
|
54
|
|
- *
|
55
|
|
- * @param checkId 测评ID
|
56
|
|
- * @param typeId 点位ID
|
57
|
|
- * @return 实例对象
|
58
|
|
- */
|
59
|
|
- @ApiOperation("通过测评以及点位查询数据")
|
60
|
|
- @GetMapping("/taCheck/{checkId}/item/{typeId}")
|
61
|
|
- public ResponseBean queryByCheckId(@ApiParam("测评ID") @PathVariable String checkId,
|
62
|
|
- @ApiParam("点位ID") @PathVariable String typeId) throws Exception {
|
63
|
|
-
|
64
|
|
- return ResponseBean.success(getByCheckAndType(checkId, typeId));
|
65
|
|
- }
|
66
|
|
-
|
67
|
|
- private TaCheckItem getByCheckAndType(String checkId, String typeId) {
|
68
|
|
- QueryWrapper<TaCheckItem> queryWrapper = new QueryWrapper<>();
|
69
|
|
- queryWrapper.eq("check_id", checkId);
|
70
|
|
- queryWrapper.eq("item_type", Constants.CHECK_OF_LOC); // 只查点位
|
71
|
|
- queryWrapper.eq("type_id", typeId);
|
72
|
|
- queryWrapper.gt("status", Constants.STATUS_DELETE);
|
|
57
|
+ /**
|
|
58
|
+ * 通过测评以及点位查询数据
|
|
59
|
+ *
|
|
60
|
+ * @param checkId 测评ID
|
|
61
|
+ * @param typeId 点位ID
|
|
62
|
+ * @return 实例对象
|
|
63
|
+ */
|
|
64
|
+ @ApiOperation("通过测评以及点位查询数据")
|
|
65
|
+ @GetMapping("/taCheck/{checkId}/item/{typeId}")
|
|
66
|
+ public ResponseBean queryByCheckId(@ApiParam("测评ID") @PathVariable String checkId,
|
|
67
|
+ @ApiParam("点位ID") @PathVariable String typeId) throws Exception {
|
|
68
|
+
|
|
69
|
+ return ResponseBean.success(getByCheckAndType(checkId, typeId));
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ private TaCheckItem getByCheckAndType(String checkId, String typeId) {
|
|
73
|
+ QueryWrapper<TaCheckItem> queryWrapper = new QueryWrapper<>();
|
|
74
|
+ queryWrapper.eq("check_id", checkId);
|
|
75
|
+ queryWrapper.eq("item_type", Constants.CHECK_OF_LOC); // 只查点位
|
|
76
|
+ queryWrapper.eq("type_id", typeId);
|
|
77
|
+ queryWrapper.gt("status", Constants.STATUS_DELETE);
|
73
|
78
|
|
74
|
79
|
return taCheckItemService.getOne(queryWrapper);
|
75
|
|
- }
|
76
|
|
-
|
77
|
|
- /**
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ /**
|
78
|
83
|
* 分页查询
|
79
|
84
|
*
|
80
|
|
- * @param pageNum 当前页码
|
|
85
|
+ * @param pageNum 当前页码
|
81
|
86
|
* @param pageSize 每页条数
|
82
|
87
|
* @return 查询结果
|
83
|
88
|
*/
|
84
|
89
|
@ApiOperation("分页查询")
|
85
|
90
|
@GetMapping("/taCheckItem")
|
86
|
|
- public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
87
|
|
- @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
|
88
|
|
- @ApiParam("模拟测评ID") @RequestParam(value ="checkId") String checkId,
|
89
|
|
- @ApiParam("项目类型") @RequestParam(value ="itemType") String itemType) throws Exception {
|
90
|
|
-
|
|
91
|
+ public ResponseBean list(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
|
92
|
+ @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
|
93
|
+ @ApiParam("模拟测评ID") @RequestParam(value = "checkId") String checkId,
|
|
94
|
+ @ApiParam("项目类型") @RequestParam(value = "itemType") String itemType) throws Exception {
|
|
95
|
+
|
91
|
96
|
IPage<TaCheckItem> pg = new Page<>(pageNum, pageSize);
|
92
|
97
|
IPage<TaCheckItem> result = taCheckItemService.getPageBy(pg, checkId, itemType);
|
93
|
|
-
|
|
98
|
+
|
94
|
99
|
return ResponseBean.success(result);
|
95
|
100
|
}
|
96
|
|
-
|
97
|
|
- /**
|
|
101
|
+
|
|
102
|
+ /**
|
98
|
103
|
* 新增数据
|
99
|
104
|
*
|
100
|
105
|
* @param taCheckItem 实例对象
|
|
@@ -135,22 +140,84 @@ public class TaCheckItemController extends BaseController {
|
135
|
140
|
|
136
|
141
|
return ResponseBean.success(taCheckItem);
|
137
|
142
|
}
|
138
|
|
-
|
139
|
|
-// /**
|
140
|
|
-// * 更新数据
|
141
|
|
-// *
|
142
|
|
-// * @param taCheckItem 实例对象
|
143
|
|
-// * @return 实例对象
|
144
|
|
-// */
|
145
|
|
-// @ApiOperation("更新数据")
|
146
|
|
-// @PutMapping("/taCheckItem/{id}")
|
147
|
|
-// public ResponseBean edit(@ApiParam("对象实体") @RequestBody TaCheckItem taCheckItem,
|
148
|
|
-// @ApiParam("对象ID") @PathVariable String id ) throws Exception {
|
149
|
|
-// taCheckItemService.updateById(taCheckItem);
|
150
|
|
-// return ResponseBean.success(taCheckItem);
|
151
|
|
-// }
|
152
|
|
-
|
153
|
|
- /**
|
|
143
|
+
|
|
144
|
+ @ApiOperation("答卷检测")
|
|
145
|
+ @PutMapping("/taCheckItem/{id}/answer/pre-check")
|
|
146
|
+ public ResponseBean checkAnswer(@ApiParam("对象ID") @PathVariable String id) throws Exception {
|
|
147
|
+ TaCheckItem taCheckItem = taCheckItemService.getById(id);
|
|
148
|
+ if (null == taCheckItem || taCheckItem.getStatus() == Constants.STATUS_DELETE) {
|
|
149
|
+ return ResponseBean.error("未找到有效的答题信息");
|
|
150
|
+ }
|
|
151
|
+
|
|
152
|
+ TaCheck taCheck = taCheckService.getById(taCheckItem.getCheckId());
|
|
153
|
+ if (null == taCheck || taCheck.getStatus() == Constants.STATUS_DELETE) {
|
|
154
|
+ return ResponseBean.error("未找到有效的测评信息");
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ if (LocalDateTime.now().isAfter(DateUtils.day2LocalDateime(taCheck.getEndDate()))) {
|
|
158
|
+ return ResponseBean.error("本次测评已结束");
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ SysUser sysUser = currentUser();
|
|
162
|
+ int count = taCheckAnswerService.getCountByUser(taCheckItem.getItemId(), sysUser.getUserId());
|
|
163
|
+ if (count > 0) {
|
|
164
|
+ return ResponseBean.error("本次测题您已作答完毕");
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ if (Constants.CHECK_OF_LOC.equals(taCheckItem.getItemType())) {
|
|
168
|
+ // 如果是实地问卷
|
|
169
|
+ int cnt = taCheckAnswerService.countByItem(taCheckItem.getItemId());
|
|
170
|
+ if (cnt >= taCheckItem.getNum()) {
|
|
171
|
+ return ResponseBean.error("当前实地问卷已收齐, 无须作答");
|
|
172
|
+ }
|
|
173
|
+ }
|
|
174
|
+
|
|
175
|
+ return ResponseBean.success(null);
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ /**
|
|
179
|
+ * 回答问题
|
|
180
|
+ *
|
|
181
|
+ * @param taCheckAnswer 实例对象
|
|
182
|
+ * @return 实例对象
|
|
183
|
+ */
|
|
184
|
+ @ApiOperation("更新数据")
|
|
185
|
+ @PutMapping("/taCheckItem/{id}/answer")
|
|
186
|
+ public ResponseBean answer(@ApiParam("对象实体") @RequestBody TaCheckAnswer taCheckAnswer,
|
|
187
|
+ @ApiParam("对象ID") @PathVariable String id) throws Exception {
|
|
188
|
+
|
|
189
|
+ TaCheckItem taCheckItem = taCheckItemService.getById(id);
|
|
190
|
+ if (null == taCheckItem || taCheckItem.getStatus() == Constants.STATUS_DELETE) {
|
|
191
|
+ return ResponseBean.error("未找到有效的答题信息");
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ TaCheck taCheck = taCheckService.getById(taCheckItem.getCheckId());
|
|
195
|
+ if (null == taCheck || taCheck.getStatus() == Constants.STATUS_DELETE) {
|
|
196
|
+ return ResponseBean.error("未找到有效的测评信息");
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ if (LocalDateTime.now().isAfter(DateUtils.day2LocalDateime(taCheck.getEndDate()))) {
|
|
200
|
+ return ResponseBean.error("本次测评已结束");
|
|
201
|
+ }
|
|
202
|
+
|
|
203
|
+ if (StringUtils.isEmpty(taCheckAnswer.getAddr())) {
|
|
204
|
+ return ResponseBean.error("测评地点详情或小区名称未填写");
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ SysUser sysUser = currentUser();
|
|
208
|
+ taCheckAnswer.setAnswerId(StringUtils.uuid());
|
|
209
|
+ taCheckAnswer.setCheckId(taCheck.getCheckId());
|
|
210
|
+ taCheckAnswer.setItemId(id);
|
|
211
|
+ taCheckAnswer.setStatus(Constants.STATUS_NORMAL);
|
|
212
|
+ taCheckAnswer.setOrgId(sysUser.getOrgId());
|
|
213
|
+ taCheckAnswer.setCreateUser(sysUser.getUserId());
|
|
214
|
+ taCheckAnswer.setCreateDate(LocalDateTime.now());
|
|
215
|
+
|
|
216
|
+ taCheckItemService.answer(taCheckItem, taCheckAnswer);
|
|
217
|
+ return null;
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+ /**
|
154
|
221
|
* 通过主键删除数据
|
155
|
222
|
*
|
156
|
223
|
* @param itemId 主键
|
|
@@ -158,7 +225,7 @@ public class TaCheckItemController extends BaseController {
|
158
|
225
|
*/
|
159
|
226
|
@ApiOperation("通过主键删除数据")
|
160
|
227
|
@DeleteMapping("/taCheckItem/{id}")
|
161
|
|
- public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id){
|
|
228
|
+ public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id) {
|
162
|
229
|
taCheckItemService.removeLogicById(id);
|
163
|
230
|
return ResponseBean.success("success");
|
164
|
231
|
}
|