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