| | |
| | | package com.ycl.jxkg.controller.admin; |
| | | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.ycl.jxkg.base.BaseApiController; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.base.SystemCode; |
| | | import com.ycl.jxkg.domain.entity.Question; |
| | | import com.ycl.jxkg.domain.entity.TextContent; |
| | | import com.ycl.jxkg.domain.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.domain.question.QuestionObject; |
| | | import com.ycl.jxkg.domain.vo.admin.question.QuestionEditRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.question.QuestionPageRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.question.QuestionResponseVO; |
| | | import com.ycl.jxkg.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.service.QuestionService; |
| | | import com.ycl.jxkg.service.TextContentService; |
| | | import com.ycl.jxkg.utils.*; |
| | | import com.ycl.jxkg.vo.admin.question.QuestionEditRequestVO; |
| | | import com.ycl.jxkg.vo.admin.question.QuestionPageRequestVO; |
| | | import com.ycl.jxkg.vo.admin.question.QuestionResponseVO; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.ycl.jxkg.utils.ErrorUtil; |
| | | import com.ycl.jxkg.utils.HtmlUtil; |
| | | import com.ycl.jxkg.utils.JsonUtil; |
| | | import com.ycl.jxkg.utils.PageInfoHelper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | |
| | | @RequiredArgsConstructor |
| | |
| | | public class QuestionController extends BaseApiController { |
| | | |
| | | private final QuestionService questionService; |
| | | private final TextContentService textContentService; |
| | | |
| | | @RequestMapping(value = "/page", method = RequestMethod.POST) |
| | | public Result<PageInfo<QuestionResponseVO>> pageList(@RequestBody QuestionPageRequestVO model) { |
| | | PageInfo<Question> pageInfo = questionService.page(model); |
| | | model.setTitle(model.getContent()); |
| | | model.setContent(null); |
| | | PageInfo<QuestionResponseVO> pageInfo = questionService.page(model); |
| | | PageInfo<QuestionResponseVO> page = PageInfoHelper.copyMap(pageInfo, q -> { |
| | | QuestionResponseVO vo = new QuestionResponseVO(); |
| | | BeanUtils.copyProperties(q, vo); |
| | | vo.setCreateTime(DateTimeUtil.dateFormat(q.getCreateTime())); |
| | | vo.setScore(ExamUtil.scoreToVM(q.getScore())); |
| | | TextContent textContent = textContentService.getById(q.getInfoTextContentId()); |
| | | QuestionObject questionObject = JsonUtil.toJsonObject(textContent.getContent(), QuestionObject.class); |
| | | QuestionObject questionObject = JsonUtil.toJsonObject(q.getContent(), QuestionObject.class); |
| | | String clearHtml = HtmlUtil.clear(questionObject.getTitleContent()); |
| | | vo.setShortTitle(clearHtml); |
| | | return vo; |
| | |
| | | |
| | | @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST) |
| | | public Result delete(@PathVariable Integer id) { |
| | | Question question = questionService.getById(id); |
| | | questionService.updateById(question); |
| | | questionService.removeById(id); |
| | | return Result.ok(); |
| | | } |
| | | |
| | |
| | | return new Result<>(SystemCode.ParameterValidError.getCode(), errorMsg); |
| | | } |
| | | } |
| | | |
| | | if (qType == QuestionTypeEnum.GapFilling.getCode()) { |
| | | Integer fillSumScore = model.getItems().stream().mapToInt(d -> ExamUtil.scoreFromVM(d.getScore())).sum(); |
| | | Integer questionScore = ExamUtil.scoreFromVM(model.getScore()); |
| | | if (!fillSumScore.equals(questionScore)) { |
| | | String errorMsg = ErrorUtil.parameterErrorFormat("score", "空分数和与题目总分不相等"); |
| | | return new Result<>(SystemCode.ParameterValidError.getCode(), errorMsg); |
| | | } |
| | | } |
| | | return Result.ok(); |
| | | } |
| | | |
| | | @PostMapping(value = "/status") |
| | | public Result<String> status(@RequestBody QuestionResponseVO question) { |
| | | questionService.updateStatus(question); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @GetMapping("/download/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) { |
| | | questionService.importTemplate(response); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | public Result<Boolean> importPaper(MultipartFile file) { |
| | | return questionService.importQuestion(file); |
| | | } |
| | | |
| | | } |