|
@@ -4,7 +4,11 @@ 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.yunzhi.training.common.BaseController;
|
|
7
|
+import com.yunzhi.training.common.Constants;
|
7
|
8
|
import com.yunzhi.training.common.ResponseBean;
|
|
9
|
+import com.yunzhi.training.common.StringUtils;
|
|
10
|
+import com.yunzhi.training.entity.TaAnswer;
|
|
11
|
+import com.yunzhi.training.service.ITaAnswerService;
|
8
|
12
|
import io.swagger.annotations.Api;
|
9
|
13
|
import io.swagger.annotations.ApiOperation;
|
10
|
14
|
import io.swagger.annotations.ApiParam;
|
|
@@ -20,6 +24,8 @@ import com.yunzhi.training.service.ITaQuestionService;
|
20
|
24
|
import com.yunzhi.training.entity.TaQuestion;
|
21
|
25
|
import org.springframework.web.bind.annotation.RestController;
|
22
|
26
|
|
|
27
|
+import java.util.List;
|
|
28
|
+
|
23
|
29
|
/**
|
24
|
30
|
* <p>
|
25
|
31
|
* 问卷问题 前端控制器
|
|
@@ -39,6 +45,9 @@ public class TaQuestionController extends BaseController {
|
39
|
45
|
@Autowired
|
40
|
46
|
public ITaQuestionService iTaQuestionService;
|
41
|
47
|
|
|
48
|
+ @Autowired
|
|
49
|
+ public ITaAnswerService iTaAnswerService;
|
|
50
|
+
|
42
|
51
|
|
43
|
52
|
/**
|
44
|
53
|
* 分页查询列表
|
|
@@ -46,17 +55,28 @@ public class TaQuestionController extends BaseController {
|
46
|
55
|
* @param pageSize
|
47
|
56
|
* @return
|
48
|
57
|
*/
|
49
|
|
- @RequestMapping(value="/taQuestion",method= RequestMethod.GET)
|
|
58
|
+ @RequestMapping(value="/{client}/question",method= RequestMethod.GET)
|
50
|
59
|
@ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
|
51
|
|
- public ResponseBean taQuestionList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
52
|
|
- @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
|
|
60
|
+ public ResponseBean taQuestionList(@ApiParam(value = "客户端",allowableValues = "admin,wx") @PathVariable String client,
|
|
61
|
+ @ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
|
62
|
+ @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
|
|
63
|
+ @ApiParam("问卷ID") @RequestParam(value ="queId", required = false) String queId,
|
|
64
|
+ @ApiParam("内容") @RequestParam(value ="content", required = false) String content) throws Exception{
|
53
|
65
|
|
54
|
|
- IPage<TaQuestion> pg = new Page<>(pageNum, pageSize);
|
55
|
|
- QueryWrapper<TaQuestion> queryWrapper = new QueryWrapper<>();
|
56
|
|
- queryWrapper.orderByDesc("create_date");
|
|
66
|
+ if (!"admin".equals(client) && !"wx".equals(client)) {
|
|
67
|
+ return ResponseBean.error("不支持的请求", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ IPage<TaQuestion> pg = new Page<>(pageNum, pageSize);
|
|
71
|
+ QueryWrapper<TaQuestion> queryWrapper = new QueryWrapper<>();
|
|
72
|
+ queryWrapper.eq(!StringUtils.isEmpty(queId), "que_id", queId);
|
|
73
|
+ queryWrapper.like(!StringUtils.isEmpty(content), "content", "%"+content+"%");
|
|
74
|
+ queryWrapper.gt("state", Constants.STATUS_DELETED);
|
|
75
|
+ queryWrapper.eq("wx".equals(client), "state", Constants.STATUS_NORMAL);
|
|
76
|
+ queryWrapper.orderByDesc("sort_no");
|
57
|
77
|
|
58
|
|
- IPage<TaQuestion> result = iTaQuestionService.page(pg, queryWrapper);
|
59
|
|
- return ResponseBean.success(result);
|
|
78
|
+ IPage<TaQuestion> result = iTaQuestionService.page(pg, queryWrapper);
|
|
79
|
+ return ResponseBean.success(result);
|
60
|
80
|
}
|
61
|
81
|
|
62
|
82
|
/**
|
|
@@ -64,9 +84,14 @@ public class TaQuestionController extends BaseController {
|
64
|
84
|
* @param taQuestion 实体对象
|
65
|
85
|
* @return
|
66
|
86
|
*/
|
67
|
|
- @RequestMapping(value="/taQuestion",method= RequestMethod.POST)
|
|
87
|
+ @RequestMapping(value="/admin/question",method= RequestMethod.POST)
|
68
|
88
|
@ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
|
69
|
89
|
public ResponseBean taQuestionAdd(@ApiParam("保存内容") @RequestBody TaQuestion taQuestion) throws Exception{
|
|
90
|
+ if (StringUtils.isEmpty(taQuestion.getQueId())) {
|
|
91
|
+ return ResponseBean.error("请设置归属问卷", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ taQuestion.setQuestionId(null);
|
70
|
95
|
|
71
|
96
|
if (iTaQuestionService.save(taQuestion)){
|
72
|
97
|
return ResponseBean.success(taQuestion);
|
|
@@ -79,10 +104,10 @@ public class TaQuestionController extends BaseController {
|
79
|
104
|
* 根据id删除对象
|
80
|
105
|
* @param id 实体ID
|
81
|
106
|
*/
|
82
|
|
- @RequestMapping(value="/taQuestion/{id}", method= RequestMethod.DELETE)
|
|
107
|
+ @RequestMapping(value="/admin/question/{id}", method= RequestMethod.DELETE)
|
83
|
108
|
@ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
|
84
|
|
- public ResponseBean taQuestionDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
85
|
|
- if(iTaQuestionService.removeById(id)){
|
|
109
|
+ public ResponseBean taQuestionDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
|
|
110
|
+ if(iTaQuestionService.removeLogicById(id)){
|
86
|
111
|
return ResponseBean.success("success");
|
87
|
112
|
}else {
|
88
|
113
|
return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
@@ -95,10 +120,15 @@ public class TaQuestionController extends BaseController {
|
95
|
120
|
* @param taQuestion 实体对象
|
96
|
121
|
* @return
|
97
|
122
|
*/
|
98
|
|
- @RequestMapping(value="/taQuestion/{id}",method= RequestMethod.PUT)
|
|
123
|
+ @RequestMapping(value="/admin/question/{id}",method= RequestMethod.PUT)
|
99
|
124
|
@ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
|
100
|
|
- public ResponseBean taQuestionUpdate(@ApiParam("对象ID") @PathVariable Integer id,
|
|
125
|
+ public ResponseBean taQuestionUpdate(@ApiParam("对象ID") @PathVariable String id,
|
101
|
126
|
@ApiParam("更新内容") @RequestBody TaQuestion taQuestion) throws Exception{
|
|
127
|
+ if (StringUtils.isEmpty(taQuestion.getQueId())) {
|
|
128
|
+ return ResponseBean.error("请设置归属问卷", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ taQuestion.setQuestionId(id);
|
102
|
132
|
|
103
|
133
|
if (iTaQuestionService.updateById(taQuestion)){
|
104
|
134
|
return ResponseBean.success(iTaQuestionService.getById(id));
|
|
@@ -111,9 +141,15 @@ public class TaQuestionController extends BaseController {
|
111
|
141
|
* 根据id查询对象
|
112
|
142
|
* @param id 实体ID
|
113
|
143
|
*/
|
114
|
|
- @RequestMapping(value="/taQuestion/{id}",method= RequestMethod.GET)
|
|
144
|
+ @RequestMapping(value="/{client}/question/{id}",method= RequestMethod.GET)
|
115
|
145
|
@ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
|
116
|
|
- public ResponseBean taQuestionGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
117
|
|
- return ResponseBean.success(iTaQuestionService.getById(id));
|
|
146
|
+ public ResponseBean taQuestionGet(@ApiParam(value = "客户端",allowableValues = "admin,wx") @PathVariable String client,
|
|
147
|
+ @ApiParam("对象ID") @PathVariable String id) throws Exception{
|
|
148
|
+ TaQuestion taQuestion = iTaQuestionService.getExistBy("question_id", id, "wx".equals(client), true);
|
|
149
|
+
|
|
150
|
+ List<TaAnswer> answerList = iTaAnswerService.getListByQuestion(taQuestion, "wx".equals(client));
|
|
151
|
+ taQuestion.setAnswerList(answerList);
|
|
152
|
+
|
|
153
|
+ return ResponseBean.success(taQuestion);
|
118
|
154
|
}
|
119
|
155
|
}
|