|
@@ -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());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|