deason 3 سال پیش
والد
کامیت
0e0fc51cfd

+ 2 - 7
src/main/java/cn/com/qmth/dp/examcloud/oe/Task.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.dp.examcloud.oe;
 
+import cn.com.qmth.dp.examcloud.oe.modules.exam_record_data.ExamRecordDataTool;
 import cn.com.qmth.dp.examcloud.oe.modules.export_exam_student_score.ExportExamStudentScore;
 import cn.com.qmth.dp.examcloud.oe.modules.fixExamStudentId.FixExamStudentId;
 import cn.com.qmth.dp.examcloud.oe.modules.get_student_answer_detail.GetStduentAnswerDetailService;
@@ -49,20 +50,14 @@ public class Task {
         try {
 
             // SpringContextHolder.getBean(ImportPaperDzkdService.class).start();
-
             // SpringContextHolder.getBean(FixCorrectAnswerAndResetScoreService.class).start();
-
             // SpringContextHolder.getBean(ExportExamStudentScore.class).start();
-
             // SpringContextHolder.getBean(GetStduentOneAnswerService.class).start(1213L, 1, "01");
-
             // SpringContextHolder.getBean(GetStduentAnswerDetailService.class).start(1627L, "000004");
-
             // SpringContextHolder.getBean(InitUserDataRule.class).start();
-
             // SpringContextHolder.getBean(FixExamStudentId.class).start(2843L, null);
-
             // SpringContextHolder.getBean(MarkingItemChangeService.class).start();
+            // SpringContextHolder.getBean(ExamRecordDataTool.class).start();
 
         } catch (Exception e) {
             log.error("unexpected", e);

+ 105 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/exam_record_data/ExamRecordDataTool.java

@@ -0,0 +1,105 @@
+package cn.com.qmth.dp.examcloud.oe.modules.exam_record_data;
+
+import cn.com.qmth.examcloud.commons.util.JsonMapper;
+import cn.com.qmth.examcloud.support.examing.ExamRecordData;
+import cn.com.qmth.examcloud.web.redis.RedisClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class ExamRecordDataTool {
+
+    private final static Logger log = LoggerFactory.getLogger(ExamRecordDataTool.class);
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+
+    @Autowired
+    private RedisClient redisClient;
+
+    private JsonMapper jsonMapper = new JsonMapper();
+
+    public void start() {
+        StringBuilder querySql = new StringBuilder()
+                .append(" select t.id,t.root_org_id,t.exam_id,t.course_id,")
+                .append(" t.student_id,t.exam_student_id,t.exam_type,t.creation_time")
+                .append(" from ec_oes_exam_record_data t")
+                .append(" where 1=1")
+                .append(" and t.creation_time >= '2022-05-08 00:00:00'")
+                .append(" and t.creation_time <= '2022-05-08 18:00:00'")
+                .append(" and t.sync_status = 'UNSYNC'");
+        // .append(" limit 3");
+
+        List<ExamRecordDataVO> allList = jdbcTemplate.query(querySql.toString(), new BeanPropertyRowMapper(ExamRecordDataVO.class));
+        System.out.println("total is " + allList.size());
+
+        List<ExamRecordDataVO> errList = new ArrayList<>();
+        for (int i = 0; i < allList.size(); i++) {
+            ExamRecordDataVO vo = allList.get(i);
+
+            String examRecordDataKey = String.format("OE_ERD:%s", vo.getId());
+            String studentPaperKey = String.format("OE_PAPER:%s", vo.getId());
+
+            boolean hasError = false;
+            ExamRecordData data = redisClient.get(examRecordDataKey, ExamRecordData.class);
+            if (data == null) {
+                System.out.println("缓存不存在! key = " + examRecordDataKey);
+                hasError = true;
+            } else {
+                if (!redisTemplate.hasKey(studentPaperKey)) {
+                    System.out.println("缓存不存在! key = " + studentPaperKey);
+                    hasError = true;
+                }
+
+                int x = 0;
+                for (int n = 1; n <= data.getQuestionCount(); n++) {
+                    String studentAnswerKey = String.format("OE_ANSWER:%s_%s", vo.getId(), n);
+                    if (!redisTemplate.hasKey(studentAnswerKey)) {
+                        // System.out.println("缓存不存在! key = " + studentAnswerKey);
+                        hasError = true;
+                        x++;
+                    }
+                }
+                System.out.println(String.format("%s-->考试记录缓存:%s, 总题数:%s, 缺作答缓存数:%s", i + 1, examRecordDataKey, data.getQuestionCount(), x));
+            }
+
+            if (hasError) {
+                errList.add(vo);
+                System.out.println();
+            }
+        }
+
+        Map<Long, List<ExamRecordDataVO>> maps = new HashMap<>();
+        for (ExamRecordDataVO data : errList) {
+            List<ExamRecordDataVO> list = maps.get(data.getRootOrgId());
+            if (list == null) {
+                list = new ArrayList<>();
+                maps.put(data.getRootOrgId(), list);
+            }
+            list.add(data);
+        }
+
+        for (Map.Entry<Long, List<ExamRecordDataVO>> entry : maps.entrySet()) {
+            System.out.println(String.format("\nrootOrgId = %s, errSize = %s", entry.getKey(), entry.getValue().size()));
+            for (ExamRecordDataVO data : entry.getValue()) {
+                System.out.println(jsonMapper.toJson(data));
+            }
+        }
+
+        System.out.println("\ntotalError is " + errList.size());
+    }
+
+}

+ 100 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/exam_record_data/ExamRecordDataVO.java

@@ -0,0 +1,100 @@
+package cn.com.qmth.dp.examcloud.oe.modules.exam_record_data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+public class ExamRecordDataVO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private Long id;
+
+    private Long rootOrgId;
+
+    private Long examId;
+
+    private Long courseId;
+
+    private Long studentId;
+
+    private Long examStudentId;
+
+    private String examType;
+
+    private String examRecordStatus;
+
+    private Date creationTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getRootOrgId() {
+        return rootOrgId;
+    }
+
+    public void setRootOrgId(Long rootOrgId) {
+        this.rootOrgId = rootOrgId;
+    }
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public Long getCourseId() {
+        return courseId;
+    }
+
+    public void setCourseId(Long courseId) {
+        this.courseId = courseId;
+    }
+
+    public Long getStudentId() {
+        return studentId;
+    }
+
+    public void setStudentId(Long studentId) {
+        this.studentId = studentId;
+    }
+
+    public Long getExamStudentId() {
+        return examStudentId;
+    }
+
+    public void setExamStudentId(Long examStudentId) {
+        this.examStudentId = examStudentId;
+    }
+
+    public String getExamType() {
+        return examType;
+    }
+
+    public void setExamType(String examType) {
+        this.examType = examType;
+    }
+
+    public String getExamRecordStatus() {
+        return examRecordStatus;
+    }
+
+    public void setExamRecordStatus(String examRecordStatus) {
+        this.examRecordStatus = examRecordStatus;
+    }
+
+    public Date getCreationTime() {
+        return creationTime;
+    }
+
+    public void setCreationTime(Date creationTime) {
+        this.creationTime = creationTime;
+    }
+
+}