From b661bcf7e065092c876e052bad0bfaecb9dc0c17 Mon Sep 17 00:00:00 2001
From: luohairen <3399054449@qq.com>
Date: 星期二, 12 十一月 2024 21:21:06 +0800
Subject: [PATCH] 优化错题查询
---
src/main/java/com/ycl/jxkg/controller/student/ExamPaperAnswerController.java | 146 +++++++++++++++++++++++++-----------------------
1 files changed, 77 insertions(+), 69 deletions(-)
diff --git a/src/main/java/com/ycl/jxkg/controller/student/ExamPaperAnswerController.java b/src/main/java/com/ycl/jxkg/controller/student/ExamPaperAnswerController.java
index f9e0cae..4e35021 100644
--- a/src/main/java/com/ycl/jxkg/controller/student/ExamPaperAnswerController.java
+++ b/src/main/java/com/ycl/jxkg/controller/student/ExamPaperAnswerController.java
@@ -1,43 +1,40 @@
package com.ycl.jxkg.controller.student;
+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.*;
-import com.ycl.jxkg.domain.entity.ExamPaperAnswer;
-import com.ycl.jxkg.domain.entity.Subject;
+import com.ycl.jxkg.domain.ExamPaperAnswerInfo;
+import com.ycl.jxkg.domain.entity.ExamPaperScore;
import com.ycl.jxkg.domain.entity.User;
-import com.ycl.jxkg.domain.entity.UserEventLog;
-import com.ycl.jxkg.domain.vo.ExamSubmitVO;
-import com.ycl.jxkg.enums.ExamPaperAnswerStatusEnum;
-import com.ycl.jxkg.event.CalculateExamPaperAnswerCompleteEvent;
-import com.ycl.jxkg.event.UserEvent;
-import com.ycl.jxkg.service.ExamPaperAnswerService;
-import com.ycl.jxkg.service.ExamPaperService;
-import com.ycl.jxkg.service.SubjectService;
-import com.ycl.jxkg.utils.DateTimeUtil;
-import com.ycl.jxkg.utils.ExamUtil;
-import com.ycl.jxkg.utils.PageInfoHelper;
-import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperEditRequestVO;
-import com.ycl.jxkg.domain.vo.student.exam.ExamPaperReadVO;
+import com.ycl.jxkg.domain.vo.DoQuestionVO;
+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.student.exam.ExamPaperSubmitVO;
import com.ycl.jxkg.domain.vo.student.exampaper.ExamPaperAnswerPageResponseVO;
import com.ycl.jxkg.domain.vo.student.exampaper.ExamPaperAnswerPageVO;
-import com.github.pagehelper.PageInfo;
+import com.ycl.jxkg.service.ExamPaperScoreService;
+import com.ycl.jxkg.service.ExamPaperService;
+import com.ycl.jxkg.service.SubjectService;
+import com.ycl.jxkg.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
-import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
@RequiredArgsConstructor
@RestController("StudentExamPaperAnswerController")
@RequestMapping(value = "/api/student/exampaper/answer")
public class ExamPaperAnswerController extends BaseApiController {
- private final ExamPaperAnswerService examPaperAnswerService;
+ private final ExamPaperScoreService examPaperScoreService;
+ private final UserService userService;
private final ExamPaperService examPaperService;
private final SubjectService subjectService;
private final ApplicationEventPublisher eventPublisher;
@@ -46,19 +43,7 @@
@RequestMapping(value = "/pageList", method = RequestMethod.POST)
public Result<PageInfo<ExamPaperAnswerPageResponseVO>> pageList(@RequestBody @Valid ExamPaperAnswerPageVO model) {
model.setCreateUser(getCurrentUser().getId());
- PageInfo<ExamPaperAnswer> pageInfo = examPaperAnswerService.studentPage(model);
- PageInfo<ExamPaperAnswerPageResponseVO> page = PageInfoHelper.copyMap(pageInfo, e -> {
- ExamPaperAnswerPageResponseVO vo = new ExamPaperAnswerPageResponseVO();
- BeanUtils.copyProperties(e, vo);
- Subject subject = subjectService.getById(vo.getSubjectId());
- vo.setDoTime(ExamUtil.secondToVM(e.getDoTime()));
- vo.setSystemScore(ExamUtil.scoreToVM(e.getSystemScore()));
- vo.setUserScore(ExamUtil.scoreToVM(e.getUserScore()));
- vo.setPaperScore(ExamUtil.scoreToVM(e.getPaperScore()));
- vo.setSubjectName(subject.getName());
- vo.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime()));
- return vo;
- });
+ PageInfo<ExamPaperAnswerPageResponseVO> page = examPaperScoreService.studentPage(model);
return Result.ok(page);
}
@@ -66,54 +51,77 @@
@RequestMapping(value = "/answerSubmit", method = RequestMethod.POST)
public Result answerSubmit(@RequestBody @Valid ExamPaperSubmitVO examPaperSubmitVO) {
User user = getCurrentUser();
- ExamPaperAnswerInfo examPaperAnswerInfo = examPaperAnswerService.calculateExamPaperAnswer(examPaperSubmitVO, user);
+ ExamPaperAnswerInfo examPaperAnswerInfo = examPaperScoreService.calculateExamPaperAnswer(examPaperSubmitVO, user);
if (null == examPaperAnswerInfo) {
return Result.fail(2, "璇曞嵎涓嶈兘閲嶅鍋�");
}
- ExamPaperAnswer examPaperAnswer = examPaperAnswerInfo.getExamPaperAnswer();
- Integer userScore = examPaperAnswer.getUserScore();
- String scoreVm = ExamUtil.scoreToVM(userScore);
- UserEventLog userEventLog = new UserEventLog(user.getId(), user.getUserName(), user.getRealName(), new Date());
- String content = user.getUserName() + " 鎻愪氦璇曞嵎锛�" + examPaperAnswerInfo.getExamPaper().getName()
- + " 寰楀垎锛�" + scoreVm
- + " 鑰楁椂锛�" + ExamUtil.secondToVM(examPaperAnswer.getDoTime());
- userEventLog.setContent(content);
- eventPublisher.publishEvent(new CalculateExamPaperAnswerCompleteEvent(examPaperAnswerInfo));
- eventPublisher.publishEvent(new UserEvent(userEventLog));
- return Result.ok(scoreVm);
+// ExamPaperScore examPaperScore = examPaperAnswerInfo.getExamPaperScore();
+// Integer userScore = examPaperScore.getUserScore();
+// String scoreVm = ExamUtil.scoreToVM(userScore);
+// UserEventLog userEventLog = new UserEventLog(user.getId(), user.getUserName(), user.getRealName(), new Date());
+// String content = user.getUserName() + " 鎻愪氦璇曞嵎锛�" + examPaperAnswerInfo.getExamPaper().getName()
+// + " 寰楀垎锛�" + scoreVm
+// + " 鑰楁椂锛�" + ExamUtil.secondToVM(examPaperScore.getDoTime());
+// userEventLog.setContent(content);
+// eventPublisher.publishEvent(new CalculateExamPaperAnswerCompleteEvent(examPaperAnswerInfo));
+// eventPublisher.publishEvent(new UserEvent(userEventLog));
+// return Result.ok(scoreVm);
+ return Result.ok();
}
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public Result edit(@RequestBody @Valid ExamPaperSubmitVO examPaperSubmitVO) {
- boolean notJudge = examPaperSubmitVO.getAnswerItems().stream().anyMatch(i -> i.getDoRight() == null && i.getScore() == null);
- if (notJudge) {
- return Result.fail(2, "鏈夋湭鎵规敼棰樼洰");
- }
-
- ExamPaperAnswer examPaperAnswer = examPaperAnswerService.getById(examPaperSubmitVO.getId());
- ExamPaperAnswerStatusEnum examPaperAnswerStatusEnum = ExamPaperAnswerStatusEnum.fromCode(examPaperAnswer.getStatus());
- if (examPaperAnswerStatusEnum == ExamPaperAnswerStatusEnum.Complete) {
- return Result.fail(3, "璇曞嵎宸插畬鎴�");
- }
- String score = examPaperAnswerService.judge(examPaperSubmitVO);
- User user = getCurrentUser();
- UserEventLog userEventLog = new UserEventLog(user.getId(), user.getUserName(), user.getRealName(), new Date());
- String content = user.getUserName() + " 鎵规敼璇曞嵎锛�" + examPaperAnswer.getPaperName() + " 寰楀垎锛�" + score;
- userEventLog.setContent(content);
- eventPublisher.publishEvent(new UserEvent(userEventLog));
+// boolean notJudge = examPaperSubmitVO.getAnswerItems().stream().anyMatch(i -> i.getDoRight() == null && i.getScore() == null);
+// if (notJudge) {
+// return Result.fail(2, "鏈夋湭鎵规敼棰樼洰");
+// }
+//
+// ExamPaperScore examPaperScore = examPaperScoreService.getById(examPaperSubmitVO.getId());
+// ExamPaperAnswerStatusEnum examPaperAnswerStatusEnum = ExamPaperAnswerStatusEnum.fromCode(examPaperScore.getStatus());
+// if (examPaperAnswerStatusEnum == ExamPaperAnswerStatusEnum.Complete) {
+// return Result.fail(3, "璇曞嵎宸插畬鎴�");
+// }
+ String score = examPaperScoreService.judge(examPaperSubmitVO);
+// User user = getCurrentUser();
+// UserEventLog userEventLog = new UserEventLog(user.getId(), user.getUserName(), user.getRealName(), new Date());
+// String content = user.getUserName() + " 鎵规敼璇曞嵎锛�" + examPaperScore.get() + " 寰楀垎锛�" + score;
+// userEventLog.setContent(content);
+// eventPublisher.publishEvent(new UserEvent(userEventLog));
return Result.ok(score);
}
@RequestMapping(value = "/read/{id}", method = RequestMethod.POST)
- public Result<ExamPaperReadVO> read(@PathVariable Integer id) {
- ExamPaperAnswer examPaperAnswer = examPaperAnswerService.getById(id);
- ExamPaperReadVO vm = new ExamPaperReadVO();
- ExamPaperEditRequestVO paper = examPaperService.examPaperToVM(examPaperAnswer.getExamPaperId());
- ExamPaperSubmitVO answer = examPaperAnswerService.examPaperAnswerToVM(examPaperAnswer.getId());
- vm.setPaper(paper);
- vm.setAnswer(answer);
- return Result.ok(vm);
+ public Result<ExamPaperScoreVO> 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);
}
+ @RequestMapping(value = "/checkWrong", method = RequestMethod.POST)
+ public Result<ExamPaperScoreVO> checkWrong(@RequestBody @Valid DoQuestionVO model) {
+ ExamPaperScore examPaperScore = examPaperScoreService.getById(model.getId());
+ 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));
+
+ List<PaperFixQuestionVO> titleItems = new ArrayList<>();
+ List<DoQuestionVO> list = new ArrayList<>();
+ PaperFixQuestionVO paperFixQuestionVO = new PaperFixQuestionVO();
+ paperFixQuestionVO.setQuestionType(model.getQuestionType());
+ list.add(model);
+ paperFixQuestionVO.setQuestionList(list);
+ titleItems.add(paperFixQuestionVO);
+ examPaperScoreVO.setTitleItems(titleItems);
+ return Result.ok(examPaperScoreVO);
+ }
+
}
--
Gitblit v1.8.0