xiangpei
2024-05-31 c9d04bc519b73f7fc4841c34e2f15fca9db7aad2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.ycl.jxkg.controller.student;
 
import com.ycl.jxkg.base.BaseApiController;
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.domain.question.QuestionObject;
import com.ycl.jxkg.service.ExamPaperQuestionCustomerAnswerService;
import com.ycl.jxkg.service.QuestionService;
import com.ycl.jxkg.service.SubjectService;
import com.ycl.jxkg.service.TextContentService;
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 ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService;
    private final QuestionService questionService;
    private final TextContentService textContentService;
    private final SubjectService subjectService;
 
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public Result<PageInfo<QuestionPageStudentResponseVO>> pageList(@RequestBody QuestionPageStudentRequestVO model) {
        model.setCreateUser(getCurrentUser().getId());
        PageInfo<ExamPaperQuestionCustomerAnswer> pageInfo = examPaperQuestionCustomerAnswerService.studentPage(model);
        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());
            vo.setShortTitle(clearHtml);
            vo.setSubjectName(subject.getName());
            return vo;
        });
        return Result.ok(page);
    }
 
 
    @RequestMapping(value = "/select/{id}", method = RequestMethod.POST)
    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 Result.ok(vm);
    }
 
}