qirong
2023-06-20 983a2d36e9d3ca4ff2da89bbaca687fc55e92610
src/main/java/com/mindskip/xzs/controller/admin/ExamPaperAnswerController.java
@@ -3,6 +3,7 @@
import com.mindskip.xzs.base.BaseApiController;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.ExamPaperAnswer;
import com.mindskip.xzs.domain.ExamPaperSubject;
import com.mindskip.xzs.domain.Subject;
import com.mindskip.xzs.domain.User;
import com.mindskip.xzs.service.*;
@@ -15,6 +16,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.stream.Collectors;
@RestController("AdminExamPaperAnswerController")
@RequestMapping(value = "/api/admin/examPaperAnswer")
public class ExamPaperAnswerController extends BaseApiController {
@@ -22,12 +25,14 @@
    private final ExamPaperAnswerService examPaperAnswerService;
    private final SubjectService subjectService;
    private final UserService userService;
    private final ExamPaperSubjectService examPaperSubjectService;
    @Autowired
    public ExamPaperAnswerController(ExamPaperAnswerService examPaperAnswerService, SubjectService subjectService, UserService userService) {
    public ExamPaperAnswerController(ExamPaperAnswerService examPaperAnswerService, SubjectService subjectService, UserService userService, ExamPaperSubjectService examPaperSubjectService) {
        this.examPaperAnswerService = examPaperAnswerService;
        this.subjectService = subjectService;
        this.userService = userService;
        this.examPaperSubjectService = examPaperSubjectService;
    }
@@ -35,20 +40,36 @@
    public RestResponse<PageInfo<ExamPaperAnswerPageResponseVM>> pageJudgeList(@RequestBody ExamPaperAnswerPageRequestVM model) {
        PageInfo<ExamPaperAnswer> pageInfo = examPaperAnswerService.adminPage(model);
        PageInfo<ExamPaperAnswerPageResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> {
            User user = userService.selectById(e.getCreateUser());
//            if(user.getUserName().)
            ExamPaperAnswerPageResponseVM vm = modelMapper.map(e, ExamPaperAnswerPageResponseVM.class);
            Subject subject = subjectService.selectById(vm.getSubjectId());
            User user = userService.selectByIdName(e.getCreateUser(), model.getUserName());
            if (user == null) {
                return null;
            }
//            Subject subject = subjectService.selectById(vm.getSubjectId());
            ExamPaperAnswer examPaperAnswer = examPaperAnswerService.getById(vm.getId());
            Integer[] ids = examPaperSubjectService.getByExamPaperId(examPaperAnswer.getExamPaperId())
                    .stream().map(ExamPaperSubject::getSubjectId).toArray(Integer[]::new);
            String name = "";
            if(ids.length>0){
                name = subjectService.selectByIds(ids)
                        .stream().map(Subject::getName).collect(Collectors.joining(","));
            }
            vm.setDoTime(ExamUtil.secondToVM(e.getDoTime()));
            vm.setSystemScore(ExamUtil.scoreToVM(e.getSystemScore()));
            vm.setUserScore(ExamUtil.scoreToVM(e.getUserScore()));
            vm.setPaperScore(ExamUtil.scoreToVM(e.getPaperScore()));
            vm.setSubjectName(subject.getName());
            vm.setSubjectName(name);
            vm.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime()));
            vm.setUserName(user.getUserName());
            return vm;
        });
        page.setList(page.getList().stream().filter(e -> e != null).collect(Collectors.toList()));
        if(page.getSize()>0){
            Double avg = page.getList().stream().mapToInt(ExamPaperAnswerPageResponseVM -> Integer.parseInt(ExamPaperAnswerPageResponseVM.getUserScore())).average().getAsDouble();
            page.getList().get(0).setAvgSource(avg);
        }
        return RestResponse.ok(page);
    }