package com.ycl.jxkg.controller.admin; import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageInfo; import com.ycl.jxkg.base.BaseApiController; import com.ycl.jxkg.base.Result; import com.ycl.jxkg.domain.entity.ExamPaperScore; import com.ycl.jxkg.domain.entity.User; import com.ycl.jxkg.domain.vo.PaperFixQuestionVO; import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperMarkNavbarVO; import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperScoreVO; import com.ycl.jxkg.domain.vo.admin.paper.ExamPaperAnswerPageRequestVO; import com.ycl.jxkg.domain.vo.admin.paper.UserAnswerPageRequestVO; import com.ycl.jxkg.domain.vo.student.exampaper.ExamPaperAnswerExportVO; import com.ycl.jxkg.domain.vo.student.exampaper.ExamPaperAnswerPageResponseVO; import com.ycl.jxkg.domain.vo.student.exampaper.UserAnswerPageResponseVO; import com.ycl.jxkg.service.ExamPaperScoreService; import com.ycl.jxkg.service.UserService; import com.ycl.jxkg.utils.ExcelUtils; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.springframework.beans.BeanUtils; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Objects; /** * @author gonghl */ @RequiredArgsConstructor @RestController("AdminExamPaperAnswerController") @RequestMapping(value = "/api/admin/examPaperAnswer") public class ExamPaperScoreController extends BaseApiController { private final ExamPaperScoreService examPaperScoreService; private final UserService userService; @PostMapping("/pageExamPaper") public Result> pageExamPaper(@RequestBody ExamPaperAnswerPageRequestVO model) { return Result.ok(examPaperScoreService.pageExamPaper(model)); } @RequestMapping(value = "/page", method = RequestMethod.POST) public Result> pageJudgeList(@RequestBody ExamPaperAnswerPageRequestVO model) { return Result.ok(examPaperScoreService.adminPage(model)); } @PostMapping("/pageUser") public Result> pageUser(@RequestBody UserAnswerPageRequestVO model) { return Result.ok(examPaperScoreService.pageUser(model)); } @RequestMapping(value = "/exportExcel", method = RequestMethod.POST) @SneakyThrows public void exportExcel(ExamPaperAnswerPageRequestVO model, HttpServletResponse response) { List list = examPaperScoreService.list(model); ExcelUtils.exportExcelToTarget(response, "", "成绩列表", list, ExamPaperAnswerExportVO.class); } @PostMapping("/read/{id}") public Result read(@PathVariable Integer id) { ExamPaperScore examPaperScore = examPaperScoreService.getById(id); ExamPaperScoreVO examPaperScoreVO = new ExamPaperScoreVO(); BeanUtils.copyProperties(examPaperScore, examPaperScoreVO); User user = userService.getById(examPaperScore.getUserId()); examPaperScoreVO.setUserName(Objects.nonNull(user) ? user.getRealName() : "用户已注销"); examPaperScoreVO.setNavbar(JSON.parseArray(examPaperScore.getNavbar(), ExamPaperMarkNavbarVO.class)); examPaperScoreVO.setTitleItems(JSON.parseArray(examPaperScore.getPaperContent(), PaperFixQuestionVO.class)); return Result.ok(examPaperScoreVO); } @PostMapping("/queryMaxAndMinScore/{id}") public Result queryMaxAndMinScore(@PathVariable Integer id) { return examPaperScoreService.queryMaxAndMinScore(id); } }