qirong
2023-08-17 81dfe248054eaa3c2751ba32576f48598adcd04f
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
package com.mindskip.xzs.controller.student;
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.base.BaseApiController;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.ExamPaperAnswer;
import com.mindskip.xzs.domain.ExamTemplatesUserCount;
import com.mindskip.xzs.domain.User;
import com.mindskip.xzs.domain.vo.ExamTemplatesUserCountVO;
import com.mindskip.xzs.repository.ExamTemplatesMapper;
import com.mindskip.xzs.service.ExamPaperAnswerService;
import com.mindskip.xzs.service.ExamTemplatesUserCountService;
import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperPageRequestVM;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.stream.Collectors;
 
@RestController("StudentExamTemplatesUserCountController")
@RequestMapping(value = "/api/student/exam/count")
public class ExamTemplatesUserCountController extends BaseApiController {
 
    private final ExamTemplatesUserCountService examTemplatesUserCountService;
    private final ExamTemplatesMapper examTemplatesMapper;
    private final ExamPaperAnswerService examPaperAnswerService;
 
    public ExamTemplatesUserCountController(ExamTemplatesUserCountService examTemplatesUserCountService, ExamTemplatesMapper examTemplatesMapper, ExamPaperAnswerService examPaperAnswerService) {
        this.examTemplatesUserCountService = examTemplatesUserCountService;
        this.examTemplatesMapper = examTemplatesMapper;
        this.examPaperAnswerService = examPaperAnswerService;
    }
 
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public RestResponse<PageInfo<ExamTemplatesUserCountVO>> select(@RequestBody ExamPaperPageRequestVM model) throws Exception {
        User user = getCurrentUser();
        model.setUserId(user.getId());
        PageInfo<ExamTemplatesUserCountVO> info = examTemplatesUserCountService.list(model);
        info.setList(info.getList().stream().map(e->{
            e.setName(examTemplatesMapper.getById(e.getId()).getName());
            return e;
        }).collect(Collectors.toList()));
        return RestResponse.ok(info);
    }
 
    @RequestMapping(value = "/sourceList", method = RequestMethod.POST)
    public RestResponse<PageInfo<ExamPaperAnswer>> selectSource(@RequestBody ExamTemplatesUserCountVO examTemplatesUserCountVO) throws Exception {
        List<ExamTemplatesUserCount> pageInfo = examTemplatesUserCountService.getByUserIdAndTemplatesId(examTemplatesUserCountVO);
        PageInfo<ExamPaperAnswer> idDesc = PageHelper.startPage(examTemplatesUserCountVO.getPageIndex(), examTemplatesUserCountVO.getPageSize(), "id desc").doSelectPageInfo(() ->
                examPaperAnswerService.getByExamPaperIdAndUserId(pageInfo));
        return RestResponse.ok(idDesc);
    }
}