|
@@ -0,0 +1,344 @@
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.update_correct_answer;
|
|
|
+
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.export_exam_student_score.vo.ExamStudentVO;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.export_exam_student_score.vo.ScoreVO;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.update_correct_answer.entity.ExamRecordDataEntity;
|
|
|
+import cn.com.qmth.examcloud.commons.util.PropertiesUtil;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.dao.EmptyResultDataAccessException;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 重新计算分数
|
|
|
+ * @Author lideyin
|
|
|
+ * @Date 2020/4/25 12:52
|
|
|
+ * @Version 1.0
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ResetScoreService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ private static final Long MARKING_TYPE_KEY = 24L;// 阅卷方式KEY
|
|
|
+
|
|
|
+ @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]);
|
|
|
+ Long courseId = Long.valueOf(strExamIdAndCourseCode.split(",")[1]);
|
|
|
+
|
|
|
+ run(examId, courseId);
|
|
|
+
|
|
|
+ Thread.sleep(10);
|
|
|
+ //19,"03013750"
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("999.all is over.....");
|
|
|
+
|
|
|
+ } 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, Long courseId) {
|
|
|
+ //考试下所有考试记录
|
|
|
+ List<ExamRecordDataEntity> allExamRecordDataList = queryExamRecordDataList(examId, courseId);
|
|
|
+
|
|
|
+ //取正式有效的考试记录数据
|
|
|
+ List<ExamRecordDataEntity> effectiveExamRecordDataList =
|
|
|
+ allExamRecordDataList.stream()
|
|
|
+ .filter(p -> !p.getIllegality() && (!p.getWarn() || (p.getWarn() && p.getAudit())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //当前考试课程下的所有的课程id
|
|
|
+ List<ExamStudentVO> examStudentList = queryExamStudents(examId, courseId);
|
|
|
+
|
|
|
+ // 获取考试的阅卷方式
|
|
|
+ String markingType = this.queryExamMarkingType(examId, MARKING_TYPE_KEY);
|
|
|
+ double objectiveScore = 0;
|
|
|
+ double subjectiveScore = 0;
|
|
|
+ double objectiveAccuracy = 0;
|
|
|
+ double successPercent = 0;
|
|
|
+ double totalScore = 0;
|
|
|
+
|
|
|
+ int esTotalNum = examStudentList.size();
|
|
|
+ int esIndex = 0;
|
|
|
+ for (ExamStudentVO esVo : examStudentList) {
|
|
|
+ esIndex++;
|
|
|
+
|
|
|
+ Long esId = esVo.getExamStudentId();
|
|
|
+ System.out.println(String.format("[examId_stuId_total]:%s_%s_total---start---共%s个考生,当前正在执行第%s条...",
|
|
|
+ examId, esId,esTotalNum, esIndex));
|
|
|
+ //如果当前考生的考试成绩已存在则直接跳过
|
|
|
+ if (existsFinalScore(esId)) {
|
|
|
+ System.out.println(String.format("[examId_stuId_total]:%s_%s_total---exist---共%s个考生,当前正在执行第%s条...",
|
|
|
+ examId, esId,esTotalNum, esIndex));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //当前考生的所有考试记录
|
|
|
+ List<ExamRecordDataEntity> curEstRecordList = effectiveExamRecordDataList.stream().filter(p -> p.getExamStudentId().equals(esId)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (curEstRecordList == null || curEstRecordList.isEmpty()) {
|
|
|
+ System.out.println(String.format("[examId_stuId_total]:%s_%s_total---warn---共%s个考生,当前正在执行第%s条...",
|
|
|
+ examId, esId,esTotalNum, esIndex));
|
|
|
+ continue;//缺考考生数据不处理
|
|
|
+ }
|
|
|
+
|
|
|
+ //最终有效的分数
|
|
|
+ ScoreVO effectiveScore;
|
|
|
+ if (curEstRecordList.size() == 1) {
|
|
|
+ // 只有一条考试记录情况
|
|
|
+ Long okExamRecordDataId = curEstRecordList.get(0).getId();
|
|
|
+
|
|
|
+ // 获取考试记录对应的成绩
|
|
|
+ effectiveScore = this.queryExamScore(okExamRecordDataId);
|
|
|
+
|
|
|
+ } else{
|
|
|
+ // 多条考试记录情况
|
|
|
+ List<ScoreVO> scores = new ArrayList<>();
|
|
|
+ for (ExamRecordDataEntity examRecordData : effectiveExamRecordDataList) {
|
|
|
+ Long examRecordDataId = examRecordData.getId();
|
|
|
+ // 分别获取考试记录对应的成绩
|
|
|
+ ScoreVO score = this.queryExamScore(examRecordDataId);
|
|
|
+ scores.add(score);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (markingType.equals("ALL") || markingType.equals("OBJECT_SCORE_MAX")) {
|
|
|
+ // 全部评阅规则 或 客观分最高规则:取总分最高
|
|
|
+ effectiveScore = scores.stream()
|
|
|
+ .sorted((obj1, obj2) -> obj2.getTotalScore().compareTo(obj1.getTotalScore()))
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ .get(0);
|
|
|
+ } else {
|
|
|
+ // 否则:取最后一次的成绩
|
|
|
+ effectiveScore = scores.stream()
|
|
|
+ .sorted((obj1, obj2) -> obj2.getId().compareTo(obj1.getId()))
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ .get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ objectiveScore = effectiveScore.getObjectiveScore();
|
|
|
+ subjectiveScore = effectiveScore.getSubjectiveScore();
|
|
|
+ objectiveAccuracy = effectiveScore.getObjectiveAccuracy();
|
|
|
+ successPercent = effectiveScore.getSuccPercent();
|
|
|
+ totalScore = effectiveScore.getTotalScore();
|
|
|
+
|
|
|
+ //再次判断数据是否已存在
|
|
|
+ if (!existsFinalScore(esId)) {
|
|
|
+ insertFinalScore(effectiveScore.getExamRecordDataId(), esId, objectiveScore, objectiveAccuracy, subjectiveScore, successPercent, totalScore);
|
|
|
+
|
|
|
+ System.out.println(String.format("[examId_stuId_total]:%s_%s_total---success---共%s个考生,当前正在执行第%s条...",
|
|
|
+ examId, esId,esTotalNum, esIndex));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入最终分数
|
|
|
+ * @param examRecordDataId
|
|
|
+ * @param esId
|
|
|
+ * @param objectiveScore
|
|
|
+ * @param objectiveAccuracy
|
|
|
+ * @param subjectiveScore
|
|
|
+ * @param successPercent
|
|
|
+ * @param totalScore
|
|
|
+ */
|
|
|
+ private void insertFinalScore(Long examRecordDataId, Long esId, double objectiveScore, double objectiveAccuracy,
|
|
|
+ double subjectiveScore, double successPercent, double totalScore) {
|
|
|
+ String strSql = String.format("INSERT INTO `ec_oe_exam_student_final_score` " +
|
|
|
+ "( `creation_time`, `update_time`, `exam_record_data_id`, `exam_student_id`, " +
|
|
|
+ "`objective_accuracy`, `objective_score`, `subjective_score`, `succ_percent`, `total_score` ) " +
|
|
|
+ "VALUES " +
|
|
|
+ " ( NOW(), NOW(), %d, %d, " +
|
|
|
+ "%s, %s, %s, %s, %s ) ", examRecordDataId, esId, objectiveAccuracy, objectiveScore, subjectiveScore, successPercent, totalScore);
|
|
|
+
|
|
|
+ jdbcTemplate.execute(strSql);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否存在最终分数
|
|
|
+ * @param estId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean existsFinalScore(Long estId) {
|
|
|
+ String strSql = String.format("select 1 from ec_oe_exam_student_final_score where exam_student_id=%d ", estId);
|
|
|
+
|
|
|
+ List<Map<String, Object>> mapList = jdbcTemplate.queryForList(strSql);
|
|
|
+
|
|
|
+ return !(mapList == null || mapList.isEmpty());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询考试记录
|
|
|
+ * @param examId
|
|
|
+ * @param courseId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ExamRecordDataEntity> queryExamRecordDataList(Long examId, Long courseId) {
|
|
|
+ String strSql = String.format("SELECT " +
|
|
|
+ "t1.`id`, " +
|
|
|
+ "t1.`exam_student_id`, " +
|
|
|
+ "t1.`course_id`, " +
|
|
|
+ "t1.`is_illegality`, " +
|
|
|
+ "t1.`is_warn`, " +
|
|
|
+ "t1.`is_audit`, " +
|
|
|
+ "t1.exam_record_questions_id " +
|
|
|
+ "FROM " +
|
|
|
+ "ec_oe_exam_record_data t1 " +
|
|
|
+ "WHERE " +
|
|
|
+ "t1.exam_id = %d " +
|
|
|
+ "AND t1.`course_id` =%d ", examId, courseId);
|
|
|
+
|
|
|
+ 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("course_id") != null) {
|
|
|
+ entity.setCourseId(Long.valueOf(map.get("course_id").toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (map.get("is_illegality") != null) {
|
|
|
+ entity.setIllegality(Boolean.valueOf(map.get("is_illegality").toString()));
|
|
|
+ } else {
|
|
|
+ entity.setIllegality(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (map.get("is_warn") != null) {
|
|
|
+ entity.setWarn(Boolean.valueOf(map.get("is_warn").toString()));
|
|
|
+ } else {
|
|
|
+ entity.setWarn(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (map.get("is_audit") != null) {
|
|
|
+ entity.setAudit(Boolean.valueOf(map.get("is_audit").toString()));
|
|
|
+ } else {
|
|
|
+ entity.setAudit(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ resultList.add(entity);
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询考试下所有考生
|
|
|
+ * @param examId
|
|
|
+ * @param courseId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ExamStudentVO> queryExamStudents(Long examId, Long courseId) {
|
|
|
+ final String columns = "exam_student_id,student_code,student_name,identity_number,org_id,course_id,course_code,course_level,grade,specialty_name,finished";
|
|
|
+ final String querySql = String.format("select %s from ec_oe_exam_student where exam_id = %s and course_id = %s and enable = 1", columns, examId, courseId);
|
|
|
+ return jdbcTemplate.query(querySql, new BeanPropertyRowMapper(ExamStudentVO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询考试的阅卷类型
|
|
|
+ * @param examId
|
|
|
+ * @param markingTypeKey
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String queryExamMarkingType(Long examId, Long markingTypeKey) {
|
|
|
+ final String querySql = String.format("select value from ec_e_exam_prop where exam_id = %s and key_id = %s", examId, markingTypeKey);
|
|
|
+ try {
|
|
|
+ String result = jdbcTemplate.queryForObject(querySql, String.class);
|
|
|
+ return org.apache.commons.lang3.StringUtils.isNoneBlank(result) ? result.trim() : "ALL";
|
|
|
+ } catch (EmptyResultDataAccessException e) {
|
|
|
+ return "ALL";// 默认值
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询考试分数
|
|
|
+ * @param examRecordDataId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ScoreVO queryExamScore(Long examRecordDataId) {
|
|
|
+ final String querySql = String.format("select id,objective_score,subjective_score,total_score,objective_accuracy,succ_percent,total_score from ec_oe_exam_score where exam_record_data_id = %s", examRecordDataId);
|
|
|
+ List<ScoreVO> result = jdbcTemplate.query(querySql, new BeanPropertyRowMapper(ScoreVO.class));
|
|
|
+
|
|
|
+ ScoreVO score;
|
|
|
+ if (CollectionUtils.isNotEmpty(result)) {
|
|
|
+ score = result.get(0);
|
|
|
+ } else {
|
|
|
+ score = new ScoreVO();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 默认值
|
|
|
+ score.setExamRecordDataId(examRecordDataId);
|
|
|
+ score.setObjectiveScore(score.getObjectiveScore() != null ? score.getObjectiveScore() : 0d);
|
|
|
+ score.setSubjectiveScore(score.getSubjectiveScore() != null ? score.getSubjectiveScore() : 0d);
|
|
|
+ score.setTotalScore(score.getTotalScore() != null ? score.getTotalScore() : 0d);
|
|
|
+ score.setObjectiveAccuracy(score.getObjectiveAccuracy() != null ? score.getObjectiveAccuracy() : 0d);
|
|
|
+ score.setSuccPercent(score.getSuccPercent() != null ? score.getSuccPercent() : 0d);
|
|
|
+
|
|
|
+ return score;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|