| | |
| | | package com.ycl.jxkg.controller.student; |
| | | |
| | | import com.ycl.jxkg.base.BaseApiController; |
| | | import com.ycl.jxkg.base.RestResponse; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.domain.ExamPaperQuestionCustomerAnswer; |
| | | import com.ycl.jxkg.domain.Subject; |
| | | import com.ycl.jxkg.domain.TextContent; |
| | |
| | | import com.ycl.jxkg.service.QuestionService; |
| | | import com.ycl.jxkg.service.SubjectService; |
| | | import com.ycl.jxkg.service.TextContentService; |
| | | import com.ycl.jxkg.utility.DateTimeUtil; |
| | | import com.ycl.jxkg.utility.HtmlUtil; |
| | | import com.ycl.jxkg.utility.JsonUtil; |
| | | import com.ycl.jxkg.utility.PageInfoHelper; |
| | | import com.ycl.jxkg.viewmodel.admin.question.QuestionEditRequestVM; |
| | | import com.ycl.jxkg.viewmodel.student.exam.ExamPaperSubmitItemVM; |
| | | import com.ycl.jxkg.viewmodel.student.question.answer.QuestionAnswerVM; |
| | | import com.ycl.jxkg.viewmodel.student.question.answer.QuestionPageStudentRequestVM; |
| | | import com.ycl.jxkg.viewmodel.student.question.answer.QuestionPageStudentResponseVM; |
| | | import com.ycl.jxkg.utils.DateTimeUtil; |
| | | import com.ycl.jxkg.utils.HtmlUtil; |
| | | import com.ycl.jxkg.utils.JsonUtil; |
| | | import com.ycl.jxkg.utils.PageInfoHelper; |
| | | import com.ycl.jxkg.vo.admin.question.QuestionEditRequestVO; |
| | | import com.ycl.jxkg.vo.student.exam.ExamPaperSubmitItemVO; |
| | | import com.ycl.jxkg.vo.student.question.answer.QuestionAnswerVO; |
| | | import com.ycl.jxkg.vo.student.question.answer.QuestionPageStudentRequestVO; |
| | | import com.ycl.jxkg.vo.student.question.answer.QuestionPageStudentResponseVO; |
| | | import com.github.pagehelper.PageInfo; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | @RequiredArgsConstructor |
| | | @RestController("StudentQuestionAnswerController") |
| | | @RequestMapping(value = "/api/student/question/answer") |
| | | public class QuestionAnswerController extends BaseApiController { |
| | |
| | | private final TextContentService textContentService; |
| | | private final SubjectService subjectService; |
| | | |
| | | @Autowired |
| | | public QuestionAnswerController(ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService, QuestionService questionService, TextContentService textContentService, SubjectService subjectService) { |
| | | this.examPaperQuestionCustomerAnswerService = examPaperQuestionCustomerAnswerService; |
| | | this.questionService = questionService; |
| | | this.textContentService = textContentService; |
| | | this.subjectService = subjectService; |
| | | } |
| | | |
| | | @RequestMapping(value = "/page", method = RequestMethod.POST) |
| | | public RestResponse<PageInfo<QuestionPageStudentResponseVM>> pageList(@RequestBody QuestionPageStudentRequestVM model) { |
| | | public Result<PageInfo<QuestionPageStudentResponseVO>> pageList(@RequestBody QuestionPageStudentRequestVO model) { |
| | | model.setCreateUser(getCurrentUser().getId()); |
| | | PageInfo<ExamPaperQuestionCustomerAnswer> pageInfo = examPaperQuestionCustomerAnswerService.studentPage(model); |
| | | PageInfo<QuestionPageStudentResponseVM> page = PageInfoHelper.copyMap(pageInfo, q -> { |
| | | Subject subject = subjectService.selectById(q.getSubjectId()); |
| | | QuestionPageStudentResponseVM vm = modelMapper.map(q, QuestionPageStudentResponseVM.class); |
| | | vm.setCreateTime(DateTimeUtil.dateFormat(q.getCreateTime())); |
| | | TextContent textContent = textContentService.selectById(q.getQuestionTextContentId()); |
| | | PageInfo<QuestionPageStudentResponseVO> page = PageInfoHelper.copyMap(pageInfo, q -> { |
| | | Subject subject = subjectService.getById(q.getSubjectId()); |
| | | QuestionPageStudentResponseVO vo = new QuestionPageStudentResponseVO(); |
| | | BeanUtils.copyProperties(q, vo); |
| | | vo.setCreateTime(DateTimeUtil.dateFormat(q.getCreateTime())); |
| | | TextContent textContent = textContentService.getById(q.getQuestionTextContentId()); |
| | | QuestionObject questionObject = JsonUtil.toJsonObject(textContent.getContent(), QuestionObject.class); |
| | | String clearHtml = HtmlUtil.clear(questionObject.getTitleContent()); |
| | | vm.setShortTitle(clearHtml); |
| | | vm.setSubjectName(subject.getName()); |
| | | return vm; |
| | | vo.setShortTitle(clearHtml); |
| | | vo.setSubjectName(subject.getName()); |
| | | return vo; |
| | | }); |
| | | return RestResponse.ok(page); |
| | | return Result.ok(page); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/select/{id}", method = RequestMethod.POST) |
| | | public RestResponse<QuestionAnswerVM> select(@PathVariable Integer id) { |
| | | QuestionAnswerVM vm = new QuestionAnswerVM(); |
| | | ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer = examPaperQuestionCustomerAnswerService.selectById(id); |
| | | ExamPaperSubmitItemVM questionAnswerVM = examPaperQuestionCustomerAnswerService.examPaperQuestionCustomerAnswerToVM(examPaperQuestionCustomerAnswer); |
| | | QuestionEditRequestVM questionVM = questionService.getQuestionEditRequestVM(examPaperQuestionCustomerAnswer.getQuestionId()); |
| | | public Result<QuestionAnswerVO> select(@PathVariable Integer id) { |
| | | QuestionAnswerVO vm = new QuestionAnswerVO(); |
| | | ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer = examPaperQuestionCustomerAnswerService.getById(id); |
| | | ExamPaperSubmitItemVO questionAnswerVM = examPaperQuestionCustomerAnswerService.examPaperQuestionCustomerAnswerToVM(examPaperQuestionCustomerAnswer); |
| | | QuestionEditRequestVO questionVM = questionService.getQuestionEditRequestVM(examPaperQuestionCustomerAnswer.getQuestionId()); |
| | | vm.setQuestionVM(questionVM); |
| | | vm.setQuestionAnswerVM(questionAnswerVM); |
| | | return RestResponse.ok(vm); |
| | | return Result.ok(vm); |
| | | } |
| | | |
| | | } |