|
@@ -0,0 +1,658 @@
|
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.update_question_score;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.update_correct_answer.entity.*;
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.update_correct_answer.util.OKHttpUtil;
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.update_correct_answer.util.QmthUtil;
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.update_question_score.entity.*;
|
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.HttpMethod;
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.PropertiesUtil;
|
|
|
|
+import com.mongodb.client.result.UpdateResult;
|
|
|
|
+import com.mysql.cj.util.StringUtils;
|
|
|
|
+import okhttp3.Response;
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Update;
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Description 更新小题分数(涉及到分数重新计算,待阅卷表的数据重新更新)
|
|
|
|
+ * @Author lideyin
|
|
|
|
+ * @Date 2020/5/25 14:51
|
|
|
|
+ * @Version 1.0
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class UpdateQuestionScoreService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ JdbcTemplate jdbcTemplate;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
|
+
|
|
|
|
+ //试卷结构本地缓存
|
|
|
|
+ private final Map<String, DefaultPaperBean> paperCacheMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ //小题标准答案本地缓存
|
|
|
|
+ private final Map<String, List<String>> rightAnswerCacheMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ //部分平面化的试卷结构缓存
|
|
|
|
+ private final Map<String, Map<String, Object>> partialFacetPaperCacheMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ //没有标答的小题id
|
|
|
|
+ private Set<String> noAnswerQuestionIdSet = new HashSet<>();
|
|
|
|
+
|
|
|
|
+ @Async
|
|
|
|
+ public void start() {
|
|
|
|
+
|
|
|
|
+ String absolutePath = PropertiesUtil.getString("fixAnswer.data.path");
|
|
|
|
+// ClassPathResource classPathResource = new ClassPathResource("temp1.txt");
|
|
|
|
+ FileInputStream fis = null;
|
|
|
|
+ InputStreamReader isr = null;
|
|
|
|
+ BufferedReader br = null;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ fis = new FileInputStream(new File(absolutePath));
|
|
|
|
+ isr = new InputStreamReader(fis);
|
|
|
|
+ br = new BufferedReader(isr);
|
|
|
|
+ String strExamIdAndCourseCode = "";
|
|
|
|
+ while ((strExamIdAndCourseCode = br.readLine()) != null) {
|
|
|
|
+ Long examId = Long.valueOf(strExamIdAndCourseCode.split(",")[0]);
|
|
|
|
+ String courseCode = strExamIdAndCourseCode.split(",")[1];
|
|
|
|
+ System.out.println(String.format("examId:%s,courseCode:%s", examId, courseCode));
|
|
|
|
+ run(examId, courseCode);
|
|
|
|
+ Thread.sleep(10);
|
|
|
|
+ //19,"03013750"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ if (br != null) {
|
|
|
|
+ try {
|
|
|
|
+ br.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isr != null) {
|
|
|
|
+ try {
|
|
|
|
+ isr.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (fis != null) {
|
|
|
|
+ try {
|
|
|
|
+ fis.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void run(long examId, String courseCode) {
|
|
|
|
+ List<ExamRecordDataEntity> examRecordDataList = queryExamRecordDataList(examId, courseCode);
|
|
|
|
+
|
|
|
|
+ if (examRecordDataList.isEmpty()) {
|
|
|
|
+ throw new StatusException("100001", "找不到对应的考试记录");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //首先更新mongo中的作答记录
|
|
|
|
+ modifyMongoQuestionScore(examRecordDataList, examId, courseCode);
|
|
|
|
+
|
|
|
|
+ //重新计算分数并保存
|
|
|
|
+ modifyDbScore(examRecordDataList);
|
|
|
|
+
|
|
|
|
+ //如果存在,则打印错误数据
|
|
|
|
+ printErrorDataIfExist();
|
|
|
|
+
|
|
|
|
+ System.out.println("999.all is over.....");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void printErrorDataIfExist() {
|
|
|
|
+ if (noAnswerQuestionIdSet.size() > 0) {
|
|
|
|
+ for (String quesId : noAnswerQuestionIdSet)
|
|
|
|
+ System.out.println(String.format("找不到quesId=%s的标答数据", quesId));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void modifyDbScore(List<ExamRecordDataEntity> examRecordDataList) {
|
|
|
|
+ Set<Long> examStudentIdSet = new HashSet<>();
|
|
|
|
+ int effectiveNum = 0;//有效数量
|
|
|
|
+ //按考试记录更新分数表
|
|
|
|
+ for (ExamRecordDataEntity record : examRecordDataList) {
|
|
|
|
+ Query query = new Query();
|
|
|
|
+ query.addCriteria(Criteria.where("_id").is(record.getExamRecordQuestionsId()));
|
|
|
|
+ ExamRecordQuestionsEntity erq = mongoTemplate.findOne(query, ExamRecordQuestionsEntity.class, "examRecordQuestions");
|
|
|
|
+ if (erq == null) continue;
|
|
|
|
+
|
|
|
|
+ List<ExamQuestionEntity> objectiveQuesList = erq.getExamQuestionEntities().stream()
|
|
|
|
+ .filter(p -> isObjectiveQues(p.getQuestionType())).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ double objectiveScore = calcTotalObjectiveScore(objectiveQuesList);
|
|
|
|
+ double objectiveAccuracy = calcTotalObjectiveAccuracy(objectiveQuesList);
|
|
|
|
+
|
|
|
|
+ updateExamScore(objectiveScore, objectiveAccuracy, record.getId());
|
|
|
|
+ updateExamRecord4Marking(objectiveScore, record.getId());
|
|
|
|
+ System.out.println(String.format("2.更新第%d条分数成功---examRecordDataId=%s", ++effectiveNum, record.getId()));
|
|
|
|
+ examStudentIdSet.add(record.getExamStudentId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// int esNum = 0;
|
|
|
|
+// //按考生id,删除考生最终分数表(此表如果不存在数据,获取时,系统会重新计算)
|
|
|
|
+// for (Long estId : examStudentIdSet) {
|
|
|
|
+// deleteFinalScore(estId);
|
|
|
|
+// System.out.println(String.format("3.删除第%d条最终分数成功---examStudentId=%s", ++esNum, estId));
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void deleteFinalScore(Long estId) {
|
|
|
|
+ String strSql = String.format("delete from ec_oe_exam_student_final_score where exam_student_id=%d ", estId);
|
|
|
|
+
|
|
|
|
+ jdbcTemplate.execute(strSql);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 计算客观题总分
|
|
|
|
+ *
|
|
|
|
+ * @param objectiveQuesList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private double calcTotalObjectiveScore(List<ExamQuestionEntity> objectiveQuesList) {
|
|
|
|
+ double totalObjectiveScore = 0d;//客观题总分
|
|
|
|
+
|
|
|
|
+ for (ExamQuestionEntity eq : objectiveQuesList) {
|
|
|
|
+ if (!StringUtils.isNullOrEmpty(eq.getStudentAnswer())
|
|
|
|
+ && !StringUtils.isNullOrEmpty(eq.getCorrectAnswer())
|
|
|
|
+ && eq.getStudentAnswer().equals(eq.getCorrectAnswer())) {
|
|
|
|
+ totalObjectiveScore += eq.getQuestionScore();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return totalObjectiveScore;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 计算客观题正确率
|
|
|
|
+ *
|
|
|
|
+ * @param objectiveQuesList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private double calcTotalObjectiveAccuracy(List<ExamQuestionEntity> objectiveQuesList) {
|
|
|
|
+ double correctNum = 0d;
|
|
|
|
+ double totalNum = 0d;
|
|
|
|
+ for (ExamQuestionEntity eq : objectiveQuesList) {
|
|
|
|
+ if (!StringUtils.isNullOrEmpty(eq.getStudentAnswer())
|
|
|
|
+ && !StringUtils.isNullOrEmpty(eq.getCorrectAnswer())
|
|
|
|
+ && eq.getStudentAnswer().equals(eq.getCorrectAnswer())) {
|
|
|
|
+ correctNum += 1;
|
|
|
|
+ }
|
|
|
|
+ totalNum += 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (totalNum == 0) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Double.valueOf(new DecimalFormat("#.00").format(correctNum * 100D / totalNum));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新作答记录中的小题分数
|
|
|
|
+ *
|
|
|
|
+ * @param examRecordDataList
|
|
|
|
+ */
|
|
|
|
+ private void modifyMongoQuestionScore(List<ExamRecordDataEntity> examRecordDataList, long examId, String courseCode) {
|
|
|
|
+ int rubbishNum = 0;
|
|
|
|
+ int effectiveNum = 0;//有效数量
|
|
|
|
+ int rubbishNum2 = 0;
|
|
|
|
+ int effectiveNum2 = 0;//有效数量
|
|
|
|
+ for (ExamRecordDataEntity record : examRecordDataList) {
|
|
|
|
+ //更新作答记录中的小题分数
|
|
|
|
+ try {
|
|
|
|
+ String examRecordQuestionsId = record.getExamRecordQuestionsId();
|
|
|
|
+ Query query = new Query();
|
|
|
|
+ query.addCriteria(Criteria.where("_id").is(examRecordQuestionsId));
|
|
|
|
+ //作答记录
|
|
|
|
+ ExamRecordQuestionsEntity erq = mongoTemplate.findOne(query, ExamRecordQuestionsEntity.class, "examRecordQuestions");
|
|
|
|
+
|
|
|
|
+ if (erq == null) {
|
|
|
|
+ System.out.println(String.format("1.作答记录发现%d条垃圾数据:examRecordDataId=%s", ++rubbishNum, record.getId()));
|
|
|
|
+ continue;//垃圾数据
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<ExamQuestionEntity> examQuestionList = erq.getExamQuestionEntities();
|
|
|
|
+
|
|
|
|
+ for (ExamQuestionEntity ques : examQuestionList) {
|
|
|
|
+ String quesId = ques.getQuestionId();
|
|
|
|
+
|
|
|
|
+ //最小维度的小题单元集合
|
|
|
|
+ List<ExamQuestionEntity> questionUnitList = examQuestionList.stream()
|
|
|
|
+ .filter(p -> p.getQuestionId().equals(quesId))
|
|
|
|
+ .sorted((o1, o2) -> o1.getOrder().intValue() - o2.getOrder().intValue())
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ //根据题目id获取标答集合
|
|
|
|
+ List<String> rightAnswerList = getRightAnswerList(quesId);
|
|
|
|
+ if (rightAnswerList == null) {
|
|
|
|
+ noAnswerQuestionIdSet.add(quesId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //根据题目id获取小题分集合
|
|
|
|
+ List<Double> questionScoreList =
|
|
|
|
+ getQuestionScoreList(quesId, examId, courseCode, record.getPaperType(), record.getBasePaperId());
|
|
|
|
+
|
|
|
|
+ //循环保存所有小题单元
|
|
|
|
+ for (int i = 0; i < questionUnitList.size(); i++) {
|
|
|
|
+ Double questionScore = questionScoreList.get(i);
|
|
|
|
+ //更新小题分数
|
|
|
|
+ updateQuestionScore(examRecordQuestionsId, ques.getOrder(), questionScore);
|
|
|
|
+
|
|
|
|
+ //如果为客观题重新算分并保存
|
|
|
|
+ if (isObjectiveQues(ques.getQuestionType())) {
|
|
|
|
+ String rightAnswer = rightAnswerList.get(i);
|
|
|
|
+ if (!StringUtils.isNullOrEmpty(rightAnswer)) {
|
|
|
|
+ ExamQuestionEntity curQues = questionUnitList.get(i);
|
|
|
|
+
|
|
|
|
+ String curCorrectAnswer = curQues.getCorrectAnswer();
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNullOrEmpty(curCorrectAnswer)
|
|
|
|
+ || (!StringUtils.isNullOrEmpty(curCorrectAnswer) && !curCorrectAnswer.equals(rightAnswer))) {
|
|
|
|
+ updatePartialQuestionAnswer(examRecordQuestionsId, curQues.getOrder(),
|
|
|
|
+ rightAnswer, calcStudentUnitScore(rightAnswer, curQues.getStudentAnswer(), questionScore));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println(String.format("1.更新第%d条作答记录成功---examRecordDataId=%s", ++effectiveNum, record.getId()));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ System.out.println(String.format("1.更新第%d条作答记录失败---examRecordDataId=%s", ++effectiveNum, record.getId()));
|
|
|
|
+ throw new StatusException("100002", e.getMessage(), e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //更新试卷结构中的小题分数
|
|
|
|
+ try {
|
|
|
|
+ String paperStructId = record.getPaperStructId();
|
|
|
|
+ Query query = new Query();
|
|
|
|
+ query.addCriteria(Criteria.where("_id").is(paperStructId));
|
|
|
|
+ //试卷结构
|
|
|
|
+ ExamRecordPaperStructBean paperStructBean = mongoTemplate.findOne(query, ExamRecordPaperStructBean.class, "examRecordPaperStruct");
|
|
|
|
+
|
|
|
|
+ if (paperStructBean == null) {
|
|
|
|
+ System.out.println(String.format("1.2.试卷结构发现%d条垃圾数据:examRecordDataId=%s", ++rubbishNum2, record.getId()));
|
|
|
|
+ continue;//垃圾数据
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //题库中的原始试卷结构
|
|
|
|
+ DefaultPaperBean originalPaper = getPaper(examId, courseCode, record.getPaperType(), record.getBasePaperId());
|
|
|
|
+
|
|
|
|
+ DefaultPaperBean defaultPaper = paperStructBean.getDefaultPaper();
|
|
|
|
+
|
|
|
|
+ //题组
|
|
|
|
+ List<DefaultQuestionGroupBean> questionGroupList = defaultPaper.getQuestionGroupList();
|
|
|
|
+ for (DefaultQuestionGroupBean group : questionGroupList) {
|
|
|
|
+ //题包装器
|
|
|
|
+ List<DefaultQuestionStructureWrapperBean> questionWrapperList = group.getQuestionWrapperList();
|
|
|
|
+ for (DefaultQuestionStructureWrapperBean qw : questionWrapperList) {
|
|
|
|
+ Map<String, Object> partialFacetPaper =
|
|
|
|
+ getPartialFacetPaper(qw.getQuestionId(), examId, courseCode, record.getPaperType(), record.getBasePaperId());
|
|
|
|
+ if (null != partialFacetPaper) {
|
|
|
|
+ if (null != partialFacetPaper.get("groupScore")) {
|
|
|
|
+ group.setGroupScore(Double.valueOf(partialFacetPaper.get("groupScore").toString()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null != partialFacetPaper.get("questionWrapperScore")) {
|
|
|
|
+ qw.setQuestionScore(Double.valueOf(partialFacetPaper.get("questionWrapperScore").toString()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null != partialFacetPaper.get("questionUnitList")) {
|
|
|
|
+ List<DefaultQuestionUnitWrapperBean> questionUnitList =
|
|
|
|
+ (List<DefaultQuestionUnitWrapperBean>) partialFacetPaper.get("questionUnitList");
|
|
|
|
+
|
|
|
|
+ List<DefaultQuestionUnitWrapperBean> questionUnitWrapperList = qw.getQuestionUnitWrapperList();
|
|
|
|
+ for (int i = 0; i < questionUnitWrapperList.size(); i++) {
|
|
|
|
+ questionUnitWrapperList.get(i).setQuestionScore(questionUnitList.get(i).getQuestionScore());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //更新修改后的试卷结构
|
|
|
|
+ mongoTemplate.save(paperStructBean, "examRecordPaperStruct");
|
|
|
|
+ System.out.println(String.format("1.2.更新第%d条试卷结构数据成功---examRecordDataId=%s,paperStructId=%s",
|
|
|
|
+ ++effectiveNum, record.getId(), record.getPaperStructId()));
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ System.out.println(String.format("1.2.更新第%d条试卷结构数据失败---examRecordDataId=%s,paperStructId=%s",
|
|
|
|
+ ++effectiveNum, record.getId(), record.getPaperStructId()));
|
|
|
|
+ throw new StatusException("100003", e.getMessage(), e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取当前考试id下的所有小题分集合
|
|
|
|
+ *
|
|
|
|
+ * @param questionId
|
|
|
|
+ * @param examId
|
|
|
|
+ * @param courseCode
|
|
|
|
+ * @param paperType
|
|
|
|
+ * @param basePaperId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<Double> getQuestionScoreList(String questionId, Long examId, String courseCode,
|
|
|
|
+ String paperType, String basePaperId) {
|
|
|
|
+
|
|
|
|
+ Map<String, Object> partialFacetPaper = getPartialFacetPaper(questionId, examId, courseCode, paperType, basePaperId);
|
|
|
|
+ if (null == partialFacetPaper) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<DefaultQuestionUnitWrapperBean> questionUnitList = (List<DefaultQuestionUnitWrapperBean>) partialFacetPaper.get("questionUnitList");
|
|
|
|
+
|
|
|
|
+ return questionUnitList.stream()
|
|
|
|
+ .map(DefaultQuestionUnitWrapperBean::getQuestionScore).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取部分平面化的试卷信息
|
|
|
|
+ *
|
|
|
|
+ * @param questionId
|
|
|
|
+ * @param examId
|
|
|
|
+ * @param courseCode
|
|
|
|
+ * @param paperType
|
|
|
|
+ * @param basePaperId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Map<String, Object> getPartialFacetPaper(String questionId, Long examId, String courseCode,
|
|
|
|
+ String paperType, String basePaperId) {
|
|
|
|
+ String cacheKey = String.format("questionScore_%s", questionId);
|
|
|
|
+ if (partialFacetPaperCacheMap.containsKey(cacheKey)) {
|
|
|
|
+ return partialFacetPaperCacheMap.get(cacheKey);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DefaultPaperBean defaultPaper = getPaper(examId, courseCode, paperType, basePaperId);
|
|
|
|
+ if (null == defaultPaper) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ List<DefaultQuestionGroupBean> questionGroupList = defaultPaper.getQuestionGroupList();
|
|
|
|
+ for (DefaultQuestionGroupBean group : questionGroupList) {
|
|
|
|
+ List<DefaultQuestionStructureWrapperBean> questionWrapperList = group.getQuestionWrapperList();
|
|
|
|
+ for (DefaultQuestionStructureWrapperBean qw : questionWrapperList) {
|
|
|
|
+ if (qw.getQuestionId().equals(questionId)) {
|
|
|
|
+ Map<String, Object> curQuestionMap = new HashMap<>();
|
|
|
|
+ //当前试题id对应的题组分数
|
|
|
|
+ curQuestionMap.put("groupScore", group.getGroupScore());
|
|
|
|
+ //当前试题id对应的题包装器分数
|
|
|
|
+ curQuestionMap.put("questionWrapperScore", qw.getQuestionScore());
|
|
|
|
+ //当前试题id对应的题单元集合
|
|
|
|
+ curQuestionMap.put("questionUnitList", qw.getQuestionUnitWrapperList());
|
|
|
|
+
|
|
|
|
+ partialFacetPaperCacheMap.put(cacheKey, curQuestionMap);
|
|
|
|
+ return curQuestionMap;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private DefaultPaperBean getPaper(Long examId, String courseCode,
|
|
|
|
+ String paperType, String basePaperId) {
|
|
|
|
+ String cacheKey = String.format("paper_%s_%s_%s_%s", examId, courseCode, paperType, basePaperId);
|
|
|
|
+ if (paperCacheMap.containsKey(cacheKey)) {
|
|
|
|
+ return paperCacheMap.get(cacheKey);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ OuterGetPaperStructReq reqBody = new OuterGetPaperStructReq();
|
|
|
|
+ reqBody.setBasePaperId(basePaperId);
|
|
|
|
+ reqBody.setCourseCode(courseCode);
|
|
|
|
+ reqBody.setExamId(examId);
|
|
|
|
+ reqBody.setPaperType(paperType);
|
|
|
|
+
|
|
|
|
+ String url = QmthUtil.buildUrl("/api/exchange/outer/question/getPaperStruct");
|
|
|
|
+ Response resp = null;
|
|
|
|
+ try {
|
|
|
|
+ resp = OKHttpUtil.call(HttpMethod.POST, url, QmthUtil.getSecurityHeaders(),
|
|
|
|
+ JsonUtil.toJson(reqBody));
|
|
|
|
+ if (resp.code() == 200) {
|
|
|
|
+ String resultJson = resp.body().string();
|
|
|
|
+ OuterGetPaperStructResp outerGetQuestionAnswerResp = JsonUtil.fromJson(resultJson, OuterGetPaperStructResp.class);
|
|
|
|
+
|
|
|
|
+ DefaultPaperBean defaultPaper = outerGetQuestionAnswerResp.getDefaultPaper();
|
|
|
|
+ paperCacheMap.putIfAbsent(cacheKey, defaultPaper);
|
|
|
|
+
|
|
|
|
+ return defaultPaper;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new StatusException("102002", e.getMessage(), e);
|
|
|
|
+ } finally {
|
|
|
|
+ IOUtils.closeQuietly(resp);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 计算学生的小题得分
|
|
|
|
+ *
|
|
|
|
+ * @param rightAnswer
|
|
|
|
+ * @param studentAnswer
|
|
|
|
+ * @param questionScore
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Double calcStudentUnitScore(String rightAnswer, String studentAnswer, Double questionScore) {
|
|
|
|
+ Double studentUnitScore = 0D;
|
|
|
|
+ if (!StringUtils.isNullOrEmpty(rightAnswer)
|
|
|
|
+ && !(StringUtils.isNullOrEmpty(studentAnswer))
|
|
|
|
+ && rightAnswer.equals(studentAnswer)) {
|
|
|
|
+ studentUnitScore = questionScore;
|
|
|
|
+ }
|
|
|
|
+ return studentUnitScore;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取题目正确答案
|
|
|
|
+ *
|
|
|
|
+ * @param quesId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<String> getRightAnswerList(String quesId) {
|
|
|
|
+// if (1 == 1) {
|
|
|
|
+// List<String> list = new ArrayList<>();
|
|
|
|
+// list.add("2");
|
|
|
|
+// list.add("2");
|
|
|
|
+// list.add("2");
|
|
|
|
+// list.add("2");
|
|
|
|
+// list.add("2");
|
|
|
|
+// list.add("2");
|
|
|
|
+// return list;
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ if (rightAnswerCacheMap.containsKey(quesId)) {
|
|
|
|
+ return rightAnswerCacheMap.get(quesId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ OuterGetQuestionAnswerReq reqBody = new OuterGetQuestionAnswerReq();
|
|
|
|
+ reqBody.setQuestionId(quesId);
|
|
|
|
+
|
|
|
|
+ String url = QmthUtil.buildUrl("/api/exchange/outer/question/getQuestionAnswer");
|
|
|
|
+ Response resp = null;
|
|
|
|
+ try {
|
|
|
|
+ resp = OKHttpUtil.call(HttpMethod.POST, url, QmthUtil.getSecurityHeaders(),
|
|
|
|
+ JsonUtil.toJson(reqBody));
|
|
|
|
+ if (resp.code() == 200) {
|
|
|
|
+ String resultJson = resp.body().string();
|
|
|
|
+ OuterGetQuestionAnswerResp outerGetQuestionAnswerResp = JsonUtil.fromJson(resultJson, OuterGetQuestionAnswerResp.class);
|
|
|
|
+
|
|
|
|
+ rightAnswerCacheMap.putIfAbsent(quesId, outerGetQuestionAnswerResp.getAnswerList());
|
|
|
|
+ return outerGetQuestionAnswerResp.getAnswerList();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new StatusException("102002", e.getMessage(), e);
|
|
|
|
+ } finally {
|
|
|
|
+ IOUtils.closeQuietly(resp);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 是否为客观题
|
|
|
|
+ *
|
|
|
|
+ * @param questionType
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private boolean isObjectiveQues(String questionType) {
|
|
|
|
+ return "SINGLE_CHOICE".equals(questionType)
|
|
|
|
+ || "MULTIPLE_CHOICE".equals(questionType)
|
|
|
|
+ || "TRUE_OR_FALSE".equals(questionType);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<ExamRecordDataEntity> queryExamRecordDataList(Long examId, String courseCode) {
|
|
|
|
+ String strSql = String.format("SELECT " +
|
|
|
|
+ "t1.`id`, " +
|
|
|
|
+ "t1.`exam_student_id`, " +
|
|
|
|
+ "t1.`paper_struct_id`, " +
|
|
|
|
+ "t1.`paper_type`, " +
|
|
|
|
+ "t1.`base_paper_id`, " +
|
|
|
|
+ "t1.exam_record_questions_id " +
|
|
|
|
+ "FROM " +
|
|
|
|
+ "ec_oe_exam_record_data t1 " +
|
|
|
|
+ "INNER JOIN ec_b_course t2 ON t1.course_id = t2.id " +
|
|
|
|
+ "WHERE " +
|
|
|
|
+ "t1.exam_id = %d " +
|
|
|
|
+ "AND t2.`code` ='%s' ", examId, courseCode);
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> mapList = jdbcTemplate.queryForList(strSql);
|
|
|
|
+ List<ExamRecordDataEntity> resultList = new ArrayList<>();
|
|
|
|
+ for (Map<String, Object> map : mapList) {
|
|
|
|
+ ExamRecordDataEntity entity = new ExamRecordDataEntity();
|
|
|
|
+ if (map.get("id") != null) {
|
|
|
|
+ entity.setId(Long.valueOf(map.get("id").toString()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (map.get("exam_student_id") != null) {
|
|
|
|
+ entity.setExamStudentId(Long.valueOf(map.get("exam_student_id").toString()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (map.get("exam_record_questions_id") != null) {
|
|
|
|
+ entity.setExamRecordQuestionsId(map.get("exam_record_questions_id").toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (map.get("paper_struct_id") != null) {
|
|
|
|
+ entity.setPaperStructId(map.get("paper_struct_id").toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (map.get("paper_type") != null) {
|
|
|
|
+ entity.setPaperType(map.get("paper_type").toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (map.get("base_paper_id") != null) {
|
|
|
|
+ entity.setBasePaperId(map.get("base_paper_id").toString());
|
|
|
|
+ }
|
|
|
|
+ resultList.add(entity);
|
|
|
|
+ }
|
|
|
|
+ return resultList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void updateExamScore(double objectiveScore, double objectiveAccuracy,
|
|
|
|
+ Long examRecordDataId) {
|
|
|
|
+ String strSql = String.format("UPDATE ec_oe_exam_score " +
|
|
|
|
+ "SET objective_score = %s, " +
|
|
|
|
+ "objective_accuracy = %s, " +
|
|
|
|
+ "total_score = objective_score+ IFNULL(subjective_score,0) " +
|
|
|
|
+ "WHERE " +
|
|
|
|
+ "exam_record_data_id = %d ", objectiveScore, objectiveAccuracy, examRecordDataId);
|
|
|
|
+
|
|
|
|
+ jdbcTemplate.execute(strSql);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void updateExamRecord4Marking(double objectiveScore, Long examRecordDataId) {
|
|
|
|
+ String strSql = String.format("UPDATE ec_oe_exam_record_4_marking " +
|
|
|
|
+ "SET objective_score = %s " +
|
|
|
|
+ "WHERE " +
|
|
|
|
+ " exam_record_data_id = %s ", objectiveScore, examRecordDataId);
|
|
|
|
+
|
|
|
|
+ jdbcTemplate.execute(strSql);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新小题分数
|
|
|
|
+ *
|
|
|
|
+ * @param examRecordQuestionsId
|
|
|
|
+ * @param order
|
|
|
|
+ * @param newQuestionScore
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public long updateQuestionScore(String examRecordQuestionsId, Integer order, Double newQuestionScore) {
|
|
|
|
+ // 查询相应的题目
|
|
|
|
+ Query query = Query.query(Criteria.where("_id").is(examRecordQuestionsId)
|
|
|
|
+ .and("examQuestionEntities.order").is(order));
|
|
|
|
+ Update update = new Update();
|
|
|
|
+ update.set("examQuestionEntities.$.questionScore", newQuestionScore);
|
|
|
|
+
|
|
|
|
+ UpdateResult upResult = mongoTemplate.updateFirst(query, update, "examRecordQuestions");
|
|
|
|
+ long res =upResult.getMatchedCount();
|
|
|
|
+
|
|
|
|
+ System.out.println(String.format("更新作答记录中小题分数成功effectNum=%s,id=%s,order=%s,newQuestionScore=%s",
|
|
|
|
+ res,examRecordQuestionsId, order, newQuestionScore));
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新学生作答的部分数据
|
|
|
|
+ *
|
|
|
|
+ * @param examRecordQuestionsId
|
|
|
|
+ * @param order
|
|
|
|
+ * @param newAnswer
|
|
|
|
+ * @param studentScore
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public long updatePartialQuestionAnswer(String examRecordQuestionsId, Integer order, String newAnswer, Double studentScore) {
|
|
|
|
+ // 查询相应的题目
|
|
|
|
+ Query query = Query.query(Criteria.where("_id").is(examRecordQuestionsId)
|
|
|
|
+ .and("examQuestionEntities.order").is(order));
|
|
|
|
+ Update update = new Update();
|
|
|
|
+ update.set("examQuestionEntities.$.correctAnswer", newAnswer);
|
|
|
|
+ update.set("examQuestionEntities.$.studentScore", studentScore);
|
|
|
|
+
|
|
|
|
+ UpdateResult upResult = mongoTemplate.updateFirst(query, update, "examRecordQuestions");
|
|
|
|
+ long res =upResult.getMatchedCount();
|
|
|
|
+
|
|
|
|
+ System.out.println(String.format("更新作答记录中学生分数成功effectNum=%s,id=%s,order=%s,studentScore=%s,correctAnswer=%s",
|
|
|
|
+ res,examRecordQuestionsId, order, studentScore,newAnswer));
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|