Explorar el Código

FixExamStudentId

deason hace 4 años
padre
commit
fa675bae28

+ 118 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/fixExamStudentId/FixExamStudentId.java

@@ -0,0 +1,118 @@
+package cn.com.qmth.dp.examcloud.oe.modules.fixExamStudentId;
+
+import cn.com.qmth.dp.examcloud.oe.modules.fixExamStudentId.vo.ExamStudentVO;
+import org.apache.commons.collections.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+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.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * 修复考务考生表某些考生被不合理删除错误(可重复执行)
+ */
+@Component
+public class FixExamStudentId {
+
+    private final static Logger log = LoggerFactory.getLogger(FixExamStudentId.class);
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    public void start() {
+        final Long examId = 2843L;
+        final Long courseId = 11231L;
+
+        // 查询网考端考生表记录
+        StringBuilder querySql = new StringBuilder()
+                .append("select id,exam_id,course_id,student_id,exam_student_id from ec_oe_exam_student ")
+                .append("where id > %s and exam_id = %s and course_id = %s ")
+                .append("order by id asc limit 0,10");
+
+        int total = 0, err = 0;
+        Long nextMinId = 0L;
+        while (true) {
+            System.out.println();
+            log.info("query nextMinId:" + nextMinId + ", total " + total + ", err " + err);
+
+            List<ExamStudentVO> list = jdbcTemplate.query(
+                    String.format(querySql.toString(), nextMinId, examId, courseId),
+                    new BeanPropertyRowMapper(ExamStudentVO.class));
+
+            if (CollectionUtils.isEmpty(list)) {
+                break;
+            }
+
+            nextMinId = list.get(list.size() - 1).getId();
+            total += list.size();
+
+            // this.fix(list, err);
+        }
+
+        log.info("task end...");
+    }
+
+    private void fix(List<ExamStudentVO> examStudentList, int err) {
+        for (ExamStudentVO vo : examStudentList) {
+            // 查询考务端考生表记录
+            Long realExamStudentId = this.queryExamStudentFromExamWork(vo.getExamId(), vo.getCourseId(), vo.getStudentId());
+            if (realExamStudentId == null) {
+                log.warn("curExamStudentId = " + vo.getExamStudentId() + " realExamStudentId is not exist");
+                continue;
+            }
+
+            if (!vo.getExamStudentId().equals(realExamStudentId)) {
+                err++;
+
+                int a = this.update_ec_oes_exam_record_data(vo.getExamStudentId(), realExamStudentId);
+                int b = this.update_ec_oe_exam_record_data(vo.getExamStudentId(), realExamStudentId);
+                int c = this.update_ec_oe_exam_student_final_score(vo.getExamStudentId(), realExamStudentId);
+                int d = this.update_ec_oe_exam_record_4_marking(vo.getExamStudentId(), realExamStudentId);
+                int e = this.delete_ec_oe_exam_student(vo.getId());
+
+                String msg = String.format("curExamStudentId = %s realExamStudentId = %s fix--> %s - %s - %s - %s - %s",
+                        vo.getExamStudentId(), realExamStudentId, a, b, c, d, e);
+                log.info(msg);
+            }
+        }
+    }
+
+    private Long queryExamStudentFromExamWork(Long examId, Long courseId, Long studentId) {
+        String querySql = String.format("select id from ec_e_exam_student where exam_id = %s and course_id = %s and student_id = %s ", examId, courseId, studentId);
+        try {
+            return jdbcTemplate.queryForObject(querySql, Long.class);
+        } catch (EmptyResultDataAccessException e) {
+            return null;
+        }
+    }
+
+    private int update_ec_oes_exam_record_data(Long curExamStudentId, Long realExamStudentId) {
+        String sql = String.format("update ec_oes_exam_record_data set exam_student_id = %s where exam_student_id = %s", realExamStudentId, curExamStudentId);
+        return jdbcTemplate.update(sql);
+    }
+
+    private int update_ec_oe_exam_record_data(Long curExamStudentId, Long realExamStudentId) {
+        String sql = String.format("update ec_oe_exam_record_data set exam_student_id = %s where exam_student_id = %s", realExamStudentId, curExamStudentId);
+        return jdbcTemplate.update(sql);
+    }
+
+    private int update_ec_oe_exam_student_final_score(Long curExamStudentId, Long realExamStudentId) {
+        String sql = String.format("update ec_oe_exam_student_final_score set exam_student_id = %s where exam_student_id = %s", realExamStudentId, curExamStudentId);
+        return jdbcTemplate.update(sql);
+    }
+
+    private int update_ec_oe_exam_record_4_marking(Long curExamStudentId, Long realExamStudentId) {
+        String sql = String.format("update ec_oe_exam_record_4_marking set exam_student_id = %s where exam_student_id = %s", realExamStudentId, curExamStudentId);
+        return jdbcTemplate.update(sql);
+    }
+
+    private int delete_ec_oe_exam_student(Long id) {
+        String sql = String.format("delete from ec_oe_exam_student where id = %s", id);
+        return jdbcTemplate.update(sql);
+    }
+
+}

+ 79 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/fixExamStudentId/vo/ExamStudentVO.java

@@ -0,0 +1,79 @@
+package cn.com.qmth.dp.examcloud.oe.modules.fixExamStudentId.vo;
+
+import java.io.Serializable;
+
+public class ExamStudentVO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private Long id;
+
+    private Long examId;//考试ID
+
+    private Long courseId;//课程ID
+
+    private Long studentId;//学生ID
+
+    private String identityNumber;//身份证号
+
+    private String studentCode;//学号
+
+    private Long examStudentId;//考生ID
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    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 String getIdentityNumber() {
+        return identityNumber;
+    }
+
+    public void setIdentityNumber(String identityNumber) {
+        this.identityNumber = identityNumber;
+    }
+
+    public String getStudentCode() {
+        return studentCode;
+    }
+
+    public void setStudentCode(String studentCode) {
+        this.studentCode = studentCode;
+    }
+
+    public Long getExamStudentId() {
+        return examStudentId;
+    }
+
+    public void setExamStudentId(Long examStudentId) {
+        this.examStudentId = examStudentId;
+    }
+
+}

+ 8 - 1
src/test/java/cn/com/qmth/dp/examcloud/oe/test/ExportTest.java

@@ -2,6 +2,7 @@ package cn.com.qmth.dp.examcloud.oe.test;
 
 import cn.com.qmth.dp.examcloud.oe.Tianji2App;
 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;
 import cn.com.qmth.dp.examcloud.oe.modules.get_student_one_question_answer.GetStduentOneAnswerService;
 import org.junit.Test;
@@ -23,6 +24,9 @@ public class ExportTest {
     @Autowired
     private GetStduentAnswerDetailService studentAnswerDetailService;
 
+    @Autowired
+    private FixExamStudentId fixExamStudentId;
+
     @Test
     public void exportTest() throws Exception {
 
@@ -36,6 +40,9 @@ public class ExportTest {
         // 导出 - 考生得分明细
         // studentAnswerDetailService.start(1606L, "410901031");
 
+        // 修复考务考生表某些考生被不合理删除错误
+        // fixExamStudentId.start();
+
     }
 
-}
+}