From 47cd9ecc0eff38ffe6b3b794b2bf197e958f4403 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期三, 14 五月 2025 15:50:57 +0800
Subject: [PATCH] bug:学员有状态不能修改问题
---
src/main/java/com/mindskip/xzs/service/impl/ExamPaperAnswerServiceImpl.java | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 158 insertions(+), 12 deletions(-)
diff --git a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperAnswerServiceImpl.java b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperAnswerServiceImpl.java
index 57637ed..cb7c8be 100644
--- a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperAnswerServiceImpl.java
+++ b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperAnswerServiceImpl.java
@@ -1,14 +1,19 @@
package com.mindskip.xzs.service.impl;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.domain.*;
+import com.mindskip.xzs.domain.enums.AnswerInvalidEnum;
import com.mindskip.xzs.domain.enums.ExamPaperAnswerStatusEnum;
import com.mindskip.xzs.domain.enums.ExamPaperTypeEnum;
import com.mindskip.xzs.domain.enums.QuestionTypeEnum;
import com.mindskip.xzs.domain.exam.ExamPaperTitleItemObject;
-import com.mindskip.xzs.domain.other.KeyValue;
import com.mindskip.xzs.domain.other.ExamPaperAnswerUpdate;
+import com.mindskip.xzs.domain.other.KeyValue;
import com.mindskip.xzs.domain.task.TaskItemAnswerObject;
-import com.mindskip.xzs.repository.*;
+import com.mindskip.xzs.domain.vo.ExamPaperDataExportVO;
+import com.mindskip.xzs.domain.vo.ExamPaperDataVO;
+import com.mindskip.xzs.domain.vo.ExamPaperStatisticVO;
import com.mindskip.xzs.repository.ExamPaperAnswerMapper;
import com.mindskip.xzs.repository.ExamPaperMapper;
import com.mindskip.xzs.repository.QuestionMapper;
@@ -19,19 +24,17 @@
import com.mindskip.xzs.utility.DateTimeUtil;
import com.mindskip.xzs.utility.ExamUtil;
import com.mindskip.xzs.utility.JsonUtil;
+import com.mindskip.xzs.viewmodel.admin.paper.ExamPaperGradePageRequestVM;
+import com.mindskip.xzs.viewmodel.admin.paper.ExamPaperGradeQuery;
import com.mindskip.xzs.viewmodel.student.exam.ExamPaperSubmitItemVM;
import com.mindskip.xzs.viewmodel.student.exam.ExamPaperSubmitVM;
import com.mindskip.xzs.viewmodel.student.exampaper.ExamPaperAnswerPageVM;
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
-import com.mindskip.xzs.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
import java.util.stream.Collectors;
@Service
@@ -162,8 +165,8 @@
}
@Override
- public Integer selectAllCount() {
- return examPaperAnswerMapper.selectAllCount();
+ public Integer selectAllCount(List<Integer> deptIds) {
+ return examPaperAnswerMapper.selectAllCount(deptIds);
}
@Override
@@ -220,13 +223,17 @@
QuestionTypeEnum questionTypeEnum = QuestionTypeEnum.fromCode(examPaperQuestionCustomerAnswer.getQuestionType());
switch (questionTypeEnum) {
case SingleChoice:
+ examPaperQuestionCustomerAnswer.setAnswer(customerQuestionAnswer.getContent());
+ examPaperQuestionCustomerAnswer.setDoRight(question.getCorrect().equals(customerQuestionAnswer.getContent()));
+ examPaperQuestionCustomerAnswer.setCustomerScore(examPaperQuestionCustomerAnswer.getDoRight() ? question.getScore() : 0);
+ break;
case TrueFalse:
examPaperQuestionCustomerAnswer.setAnswer(customerQuestionAnswer.getContent());
examPaperQuestionCustomerAnswer.setDoRight(question.getCorrect().equals(customerQuestionAnswer.getContent()));
examPaperQuestionCustomerAnswer.setCustomerScore(examPaperQuestionCustomerAnswer.getDoRight() ? question.getScore() : 0);
break;
case MultipleChoice:
- String customerAnswer = ExamUtil.contentToString(customerQuestionAnswer.getContentArray());
+ String customerAnswer = customerQuestionAnswer.getContent() ==null ? ExamUtil.contentToString(customerQuestionAnswer.getContentArray()) : customerQuestionAnswer.getContent();
examPaperQuestionCustomerAnswer.setAnswer(customerAnswer);
examPaperQuestionCustomerAnswer.setDoRight(customerAnswer.equals(question.getCorrect()));
examPaperQuestionCustomerAnswer.setCustomerScore(examPaperQuestionCustomerAnswer.getDoRight() ? question.getScore() : 0);
@@ -272,7 +279,7 @@
@Override
public PageInfo<ExamPaperAnswer> adminPage(com.mindskip.xzs.viewmodel.admin.paper.ExamPaperAnswerPageRequestVM requestVM) {
- return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "user_score desc").doSelectPageInfo(() ->
+ return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "create_time desc").doSelectPageInfo(() ->
examPaperAnswerMapper.adminPage(requestVM));
}
@@ -280,4 +287,143 @@
public ExamPaperAnswer getById(Integer id) {
return examPaperAnswerMapper.getById(id);
}
+
+ @Override
+ public List<ExamPaperAnswer> selectByPaperName(String paperName) {
+ return examPaperAnswerMapper.selectByPaperName(paperName);
+ }
+
+ @Override
+ public List<ExamPaperAnswer> getByExamPaperIdAndUserId(List<ExamTemplatesUserCount> examTemplatesUserCount) {
+ return examPaperAnswerMapper.getByExamPaperIdAndUserId(examTemplatesUserCount);
+ }
+
+ @Override
+ public PageInfo<ExamPaperAnswer> adminPageByGrade(ExamPaperGradePageRequestVM grade) {
+ return PageHelper.startPage(grade.getPageIndex(), grade.getPageSize(), "id desc").doSelectPageInfo(() ->
+ examPaperAnswerMapper.adminPageByGrade(grade));
+ }
+
+ @Override
+ public List<ExamPaperAnswer> getByScorePaperIdAndUserId(List<ScoreTemplatesUserCount> scoreTemplatesUserCounts) {
+ return examPaperAnswerMapper.getByScorePaperIdAndUserId(scoreTemplatesUserCounts);
+ }
+
+ @Override
+ public PageInfo<ExamPaperAnswer> getByCreatUser(ExamPaperGradeQuery query) {
+ query.setFullTime();
+ return PageHelper.startPage(query.getPageIndex(), query.getPageSize(), "id desc").doSelectPageInfo(() ->
+ examPaperAnswerMapper.getByCreatUser(query));
+ }
+
+ @Override
+ public Map<String, Object> statistic(ExamPaperStatisticVO examPaperStatisticVO) {
+ // 鑾峰彇鍘熷鏁版嵁
+ Map<String, Object> histogram;
+ ExamPaperDataExportVO examPaperDataExportVO;
+ if (Objects.equals(examPaperStatisticVO.getExamPaperType(), 7)) {
+ histogram = examPaperAnswerMapper.histogramByTemplate(examPaperStatisticVO);
+ examPaperDataExportVO = examPaperAnswerMapper.totalByTemplate(new ExamPaperDataVO().setId(examPaperStatisticVO.getExamPaperId()).setDeptIds(examPaperStatisticVO.getDepartmentId()));
+ } else {
+ histogram = examPaperAnswerMapper.histogram(examPaperStatisticVO);
+ examPaperDataExportVO = examPaperAnswerMapper.totalByPaper(new ExamPaperDataVO().setId(examPaperStatisticVO.getExamPaperId()).setDeptIds(examPaperStatisticVO.getDepartmentId()));
+ }
+
+ // 涓嶅瓨鍦ㄦ椂濉厖0
+ if (Objects.isNull(examPaperDataExportVO)) {
+ examPaperDataExportVO = new ExamPaperDataExportVO()
+ .setExamTotal(examPaperAnswerMapper.getExamTotal(examPaperStatisticVO))
+ .setFactPeopleTotal(0)
+ .setAverageScore(BigDecimal.ZERO)
+ .setReferencePercentage(BigDecimal.ZERO);
+ }
+
+ Map<String, Object> pieChart = examPaperAnswerMapper.pieChart(examPaperStatisticVO);
+ // 鍒濆鍖栫粨鏋滃鍣�
+ HashMap<String, Object> map = new HashMap<>();
+ List<Map<String, Object>> score = new ArrayList<>();
+ List<Map<String, Object>> age = new ArrayList<>();
+ List<Map<String, Object>> examPeopleNum = new ArrayList<>();
+ // 澶勭悊鎴愮哗涓庡勾榫勫垎甯�
+ histogram.forEach((k, v) -> {
+ Map<String, Object> hashMap = new HashMap<>();
+ hashMap.put(k, v);
+ if (k.contains("score")) {
+ score.add(hashMap);
+ }
+ if (k.contains("age")) {
+ age.add(hashMap);
+ }
+ });
+ // 澶勭悊鍙傝�冧汉鏁帮紙鍑哄腑涓庣己甯級
+ pieChart.forEach((k, v) -> {
+ Map<String, Object> hashMap = new HashMap<>();
+ hashMap.put(k, v);
+ if ("totalAttended".equals(k)) {
+ examPeopleNum.add(hashMap);
+ }
+ if ("totalAbsent".equals(k)) {
+ examPeopleNum.add(hashMap);
+ }
+ });
+ map.put("score", score);
+ map.put("age", age);
+ map.put("examPeopleNum", examPeopleNum);
+ map.put("total", examPaperDataExportVO);
+ return map;
+ }
+
+ @Override
+ public Map<String, Object> data(ExamPaperDataVO examPaperDataVO) {
+ Map<String, Object> map = new HashMap<>();
+ // 闅忔満璇曞嵎
+ if (Objects.equals(examPaperDataVO.getType(), 7)) {
+ map.put("data", examPaperAnswerMapper.dataByTemplate(examPaperDataVO));
+ map.put("total", examPaperAnswerMapper.totalByTemplate(examPaperDataVO));
+ } else {
+ map.put("data", examPaperAnswerMapper.dataByPaper(examPaperDataVO));
+ map.put("total", examPaperAnswerMapper.totalByPaper(examPaperDataVO));
+ }
+ return map;
+ }
+
+ @Override
+ public List<ExamPaperDataExportVO> dataExport(ExamPaperDataVO examPaperDataVO) {
+ // 闅忔満璇曞嵎
+ if (Objects.equals(examPaperDataVO.getType(), 7)) {
+ List<ExamPaperDataExportVO > dataByTemplate = examPaperAnswerMapper.dataByTemplate(examPaperDataVO);
+ ExamPaperDataExportVO totalByTemplate = examPaperAnswerMapper.totalByTemplate(examPaperDataVO);
+ dataByTemplate.add(0, totalByTemplate.setName("鎵�鏈夐儴闂�"));
+ return dataByTemplate;
+ } else {
+ List<ExamPaperDataExportVO > dataByPaper = examPaperAnswerMapper.dataByPaper(examPaperDataVO);
+ ExamPaperDataExportVO totalByPaper = examPaperAnswerMapper.totalByPaper(examPaperDataVO);
+ dataByPaper.add(0, totalByPaper.setName("鎵�鏈夐儴闂�"));
+ return dataByPaper;
+ }
+ }
+
+ @Override
+ public void maxGrade(ExamPaperAnswer examPaperAnswer, Integer templateId) {
+ // 鑾峰彇鏌愪竴鍦鸿�冭瘯鏇剧粡鐨勬渶楂樻垚缁�
+ ExamPaperAnswer maxGrade;
+ if (Objects.equals(examPaperAnswer.getPaperType(), 7)) {
+ maxGrade = examPaperAnswerMapper.getTemplateOtherExamAnswer(examPaperAnswer, templateId);
+ } else {
+ maxGrade = examPaperAnswerMapper.getPaperOtherExamAnswer(examPaperAnswer);
+ }
+ if (Objects.isNull(maxGrade)) {
+ return;
+ }
+ // 鏈鑰冭瘯鍒嗘暟涓嶅涔嬪墠锛屾湰娆℃棤鏁�
+ if (maxGrade.getUserScore() > examPaperAnswer.getUserScore()) {
+ // 涔嬪墠鐨勬垚缁╂湁鏁�
+ maxGrade.setInvalid(AnswerInvalidEnum.VALID);
+ examPaperAnswerMapper.updateByPrimaryKeySelective(maxGrade);
+ // 鏈鐨勪笉鏄渶楂樺垎锛屾棤鏁�
+ examPaperAnswer.setInvalid(AnswerInvalidEnum.INVALID);
+ examPaperAnswerMapper.updateByPrimaryKeySelective(examPaperAnswer);
+ }
+ }
+
}
--
Gitblit v1.8.0