|
@@ -1,8 +1,11 @@
|
|
|
package vip.xiaonuo.exam.controller.admin;
|
|
package vip.xiaonuo.exam.controller.admin;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import vip.xiaonuo.common.pojo.CommonResult;
|
|
|
import vip.xiaonuo.exam.base.BaseApiController;
|
|
import vip.xiaonuo.exam.base.BaseApiController;
|
|
|
import vip.xiaonuo.exam.base.RestResponse;
|
|
import vip.xiaonuo.exam.base.RestResponse;
|
|
|
import vip.xiaonuo.exam.base.SystemCode;
|
|
import vip.xiaonuo.exam.base.SystemCode;
|
|
|
|
|
+import vip.xiaonuo.exam.domain.ExamPaper;
|
|
|
import vip.xiaonuo.exam.domain.Question;
|
|
import vip.xiaonuo.exam.domain.Question;
|
|
|
import vip.xiaonuo.exam.domain.TextContent;
|
|
import vip.xiaonuo.exam.domain.TextContent;
|
|
|
import vip.xiaonuo.exam.domain.enums.QuestionTypeEnum;
|
|
import vip.xiaonuo.exam.domain.enums.QuestionTypeEnum;
|
|
@@ -35,25 +38,14 @@ public class QuestionController extends BaseApiController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/page", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/page", method = RequestMethod.POST)
|
|
|
- public RestResponse<PageInfo<QuestionResponseVM>> pageList(@RequestBody QuestionPageRequestVM model) {
|
|
|
|
|
- PageInfo<Question> pageInfo = questionService.page(model);
|
|
|
|
|
- PageInfo<QuestionResponseVM> page = PageInfoHelper.copyMap(pageInfo, q -> {
|
|
|
|
|
- QuestionResponseVM vm = modelMapper.map(q, QuestionResponseVM.class);
|
|
|
|
|
- vm.setCreateTime(DateTimeUtil.dateFormat(q.getCreateTime()));
|
|
|
|
|
- vm.setScore(ExamUtil.scoreToVM(q.getScore()));
|
|
|
|
|
- TextContent textContent = textContentService.selectById(q.getInfoTextContentId());
|
|
|
|
|
- QuestionObject questionObject = JsonUtil.toJsonObject(textContent.getContent(), QuestionObject.class);
|
|
|
|
|
- String clearHtml = HtmlUtil.clear(questionObject.getTitleContent());
|
|
|
|
|
- vm.setShortTitle(clearHtml);
|
|
|
|
|
- return vm;
|
|
|
|
|
- });
|
|
|
|
|
- return RestResponse.ok(page);
|
|
|
|
|
|
|
+ public CommonResult<Page<Question>> pageList(@RequestBody QuestionPageRequestVM model) {
|
|
|
|
|
+ return CommonResult.data(questionService.page(model));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/edit", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/edit", method = RequestMethod.POST)
|
|
|
- public RestResponse edit(@RequestBody @Valid QuestionEditRequestVM model) {
|
|
|
|
|
- RestResponse validQuestionEditRequestResult = validQuestionEditRequestVM(model);
|
|
|
|
|
- if (validQuestionEditRequestResult.getCode() != SystemCode.OK.getCode()) {
|
|
|
|
|
|
|
+ public CommonResult edit(@RequestBody @Valid QuestionEditRequestVM model) {
|
|
|
|
|
+ CommonResult validQuestionEditRequestResult = validQuestionEditRequestVM(model);
|
|
|
|
|
+ if (validQuestionEditRequestResult.getCode() != 200) {
|
|
|
return validQuestionEditRequestResult;
|
|
return validQuestionEditRequestResult;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -63,31 +55,30 @@ public class QuestionController extends BaseApiController {
|
|
|
questionService.updateFullQuestion(model);
|
|
questionService.updateFullQuestion(model);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return RestResponse.ok();
|
|
|
|
|
|
|
+ return CommonResult.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/select/{id}", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/select/{id}", method = RequestMethod.POST)
|
|
|
- public RestResponse<QuestionEditRequestVM> select(@PathVariable Integer id) {
|
|
|
|
|
- QuestionEditRequestVM newVM = questionService.getQuestionEditRequestVM(id);
|
|
|
|
|
- return RestResponse.ok(newVM);
|
|
|
|
|
|
|
+ public CommonResult<QuestionEditRequestVM> select(@PathVariable Integer id) {
|
|
|
|
|
+ return CommonResult.data(questionService.getQuestionEditRequestVM(id));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
|
|
|
- public RestResponse delete(@PathVariable Integer id) {
|
|
|
|
|
|
|
+ public CommonResult delete(@PathVariable Integer id) {
|
|
|
Question question = questionService.selectById(id);
|
|
Question question = questionService.selectById(id);
|
|
|
question.setDeleted(true);
|
|
question.setDeleted(true);
|
|
|
questionService.updateByIdFilter(question);
|
|
questionService.updateByIdFilter(question);
|
|
|
- return RestResponse.ok();
|
|
|
|
|
|
|
+ return CommonResult.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private RestResponse validQuestionEditRequestVM(QuestionEditRequestVM model) {
|
|
|
|
|
|
|
+ private CommonResult validQuestionEditRequestVM(QuestionEditRequestVM model) {
|
|
|
int qType = model.getQuestionType().intValue();
|
|
int qType = model.getQuestionType().intValue();
|
|
|
boolean requireCorrect = qType == QuestionTypeEnum.SingleChoice.getCode() || qType == QuestionTypeEnum.TrueFalse.getCode();
|
|
boolean requireCorrect = qType == QuestionTypeEnum.SingleChoice.getCode() || qType == QuestionTypeEnum.TrueFalse.getCode();
|
|
|
if (requireCorrect) {
|
|
if (requireCorrect) {
|
|
|
if (StringUtils.isBlank(model.getCorrect())) {
|
|
if (StringUtils.isBlank(model.getCorrect())) {
|
|
|
String errorMsg = ErrorUtil.parameterErrorFormat("correct", "不能为空");
|
|
String errorMsg = ErrorUtil.parameterErrorFormat("correct", "不能为空");
|
|
|
- return new RestResponse<>(SystemCode.ParameterValidError.getCode(), errorMsg);
|
|
|
|
|
|
|
+ return new CommonResult(SystemCode.ParameterValidError.getCode(),errorMsg,null);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -96,9 +87,9 @@ public class QuestionController extends BaseApiController {
|
|
|
Integer questionScore = ExamUtil.scoreFromVM(model.getScore());
|
|
Integer questionScore = ExamUtil.scoreFromVM(model.getScore());
|
|
|
if (!fillSumScore.equals(questionScore)) {
|
|
if (!fillSumScore.equals(questionScore)) {
|
|
|
String errorMsg = ErrorUtil.parameterErrorFormat("score", "空分数和与题目总分不相等");
|
|
String errorMsg = ErrorUtil.parameterErrorFormat("score", "空分数和与题目总分不相等");
|
|
|
- return new RestResponse<>(SystemCode.ParameterValidError.getCode(), errorMsg);
|
|
|
|
|
|
|
+ return new CommonResult(SystemCode.ParameterValidError.getCode(),errorMsg,null);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return RestResponse.ok();
|
|
|
|
|
|
|
+ return CommonResult.ok();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|