|
@@ -0,0 +1,329 @@
|
|
|
|
+package cn.com.qmth.examcloud.dengbao.service;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.dengbao.model.*;
|
|
|
|
+import cn.com.qmth.examcloud.dengbao.utils.AESEncryptor;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+
|
|
|
|
+import java.sql.PreparedStatement;
|
|
|
|
+import java.sql.SQLException;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class InitDataService {
|
|
|
|
+
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(InitDataService.class);
|
|
|
|
+
|
|
|
|
+ private static final int MAX_PAGE_SIZE = 10000;
|
|
|
|
+
|
|
|
|
+ private AESEncryptor aes = new AESEncryptor();
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
+
|
|
|
|
+ @Async
|
|
|
|
+ public void init_EC_B_Student(String secretKey, boolean needEncrypt) {
|
|
|
|
+ StringBuilder querySql = new StringBuilder()
|
|
|
|
+ .append("select id,identity_number,name,phone_number,security_phone from ec_b_student ")
|
|
|
|
+ .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
|
|
|
|
+
|
|
|
|
+ int total = 0;
|
|
|
|
+ Long startId = 0L;
|
|
|
|
+ while (true) {
|
|
|
|
+ List<EC_B_Student> list = jdbcTemplate.query(
|
|
|
|
+ querySql.toString().replace("?1", startId.toString()),
|
|
|
|
+ new BeanPropertyRowMapper(EC_B_Student.class)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ total += list.size();
|
|
|
|
+ startId = list.get(list.size() - 1).getId();
|
|
|
|
+ log.info("[ec_b_student] lastId:{} curTotal:{}", startId, total);
|
|
|
|
+
|
|
|
|
+ for (EC_B_Student obj : list) {
|
|
|
|
+ if (needEncrypt) {
|
|
|
|
+ obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ obj.setName(aes.encrypt(secretKey, obj.getName()));
|
|
|
|
+ obj.setPhoneNumber(aes.encrypt(secretKey, obj.getPhoneNumber()));
|
|
|
|
+ obj.setSecurityPhone(aes.encrypt(secretKey, obj.getSecurityPhone()));
|
|
|
|
+ } else {
|
|
|
|
+ obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ obj.setName(aes.decrypt(secretKey, obj.getName()));
|
|
|
|
+ obj.setPhoneNumber(aes.decrypt(secretKey, obj.getPhoneNumber()));
|
|
|
|
+ obj.setSecurityPhone(aes.decrypt(secretKey, obj.getSecurityPhone()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.update_EC_B_Student(list);
|
|
|
|
+ list.clear();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void update_EC_B_Student(List<EC_B_Student> list) {
|
|
|
|
+ StringBuilder sql = new StringBuilder()
|
|
|
|
+ .append("update ec_b_student ")
|
|
|
|
+ .append("set identity_number = ?,name = ?,phone_number = ?,security_phone = ? ")
|
|
|
|
+ .append("where id = ? ");
|
|
|
|
+
|
|
|
|
+ jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
|
|
|
|
+ @Override
|
|
|
|
+ public void setValues(PreparedStatement ps, int n) throws SQLException {
|
|
|
|
+ EC_B_Student row = list.get(n);
|
|
|
|
+ ps.setString(1, row.getIdentityNumber());
|
|
|
|
+ ps.setString(2, row.getName());
|
|
|
|
+ ps.setString(3, row.getPhoneNumber());
|
|
|
|
+ ps.setString(4, row.getSecurityPhone());
|
|
|
|
+ ps.setLong(5, row.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int getBatchSize() {
|
|
|
|
+ return list.size();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Async
|
|
|
|
+ public void init_EC_B_StudentCode(String secretKey, boolean needEncrypt) {
|
|
|
|
+ StringBuilder querySql = new StringBuilder()
|
|
|
|
+ .append("select id,identity_number from ec_b_student_code ")
|
|
|
|
+ .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
|
|
|
|
+
|
|
|
|
+ int total = 0;
|
|
|
|
+ Long startId = 0L;
|
|
|
|
+ while (true) {
|
|
|
|
+ List<EC_B_StudentCode> list = jdbcTemplate.query(
|
|
|
|
+ querySql.toString().replace("?1", startId.toString()),
|
|
|
|
+ new BeanPropertyRowMapper(EC_B_StudentCode.class)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ total += list.size();
|
|
|
|
+ startId = list.get(list.size() - 1).getId();
|
|
|
|
+ log.info("[ec_b_student_code] lastId:{} curTotal:{}", startId, total);
|
|
|
|
+
|
|
|
|
+ for (EC_B_StudentCode obj : list) {
|
|
|
|
+ if (needEncrypt) {
|
|
|
|
+ obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ } else {
|
|
|
|
+ obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.update_EC_B_StudentCode(list);
|
|
|
|
+ list.clear();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void update_EC_B_StudentCode(List<EC_B_StudentCode> list) {
|
|
|
|
+ StringBuilder sql = new StringBuilder()
|
|
|
|
+ .append("update ec_b_student_code ")
|
|
|
|
+ .append("set identity_number = ? ")
|
|
|
|
+ .append("where id = ? ");
|
|
|
|
+
|
|
|
|
+ jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
|
|
|
|
+ @Override
|
|
|
|
+ public void setValues(PreparedStatement ps, int n) throws SQLException {
|
|
|
|
+ EC_B_StudentCode row = list.get(n);
|
|
|
|
+ ps.setString(1, row.getIdentityNumber());
|
|
|
|
+ ps.setLong(2, row.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int getBatchSize() {
|
|
|
|
+ return list.size();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Async
|
|
|
|
+ public void init_EC_E_ExamStudent(String secretKey, boolean needEncrypt) {
|
|
|
|
+ StringBuilder querySql = new StringBuilder()
|
|
|
|
+ .append("select id,identity_number,name from ec_e_exam_student ")
|
|
|
|
+ .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
|
|
|
|
+
|
|
|
|
+ int total = 0;
|
|
|
|
+ Long startId = 0L;
|
|
|
|
+ while (true) {
|
|
|
|
+ List<EC_E_ExamStudent> list = jdbcTemplate.query(
|
|
|
|
+ querySql.toString().replace("?1", startId.toString()),
|
|
|
|
+ new BeanPropertyRowMapper(EC_E_ExamStudent.class)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ total += list.size();
|
|
|
|
+ startId = list.get(list.size() - 1).getId();
|
|
|
|
+ log.info("[ec_e_exam_student] lastId:{} curTotal:{}", startId, total);
|
|
|
|
+
|
|
|
|
+ for (EC_E_ExamStudent obj : list) {
|
|
|
|
+ if (needEncrypt) {
|
|
|
|
+ obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ obj.setName(aes.encrypt(secretKey, obj.getName()));
|
|
|
|
+ } else {
|
|
|
|
+ obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ obj.setName(aes.decrypt(secretKey, obj.getName()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.update_EC_E_ExamStudent(list);
|
|
|
|
+ list.clear();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void update_EC_E_ExamStudent(List<EC_E_ExamStudent> list) {
|
|
|
|
+ StringBuilder sql = new StringBuilder()
|
|
|
|
+ .append("update ec_e_exam_student ")
|
|
|
|
+ .append("set identity_number = ?,name = ? ")
|
|
|
|
+ .append("where id = ? ");
|
|
|
|
+
|
|
|
|
+ jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
|
|
|
|
+ @Override
|
|
|
|
+ public void setValues(PreparedStatement ps, int n) throws SQLException {
|
|
|
|
+ EC_E_ExamStudent row = list.get(n);
|
|
|
|
+ ps.setString(1, row.getIdentityNumber());
|
|
|
|
+ ps.setString(2, row.getName());
|
|
|
|
+ ps.setLong(3, row.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int getBatchSize() {
|
|
|
|
+ return list.size();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Async
|
|
|
|
+ public void init_EC_OE_ExamStudent(String secretKey, boolean needEncrypt) {
|
|
|
|
+ StringBuilder querySql = new StringBuilder()
|
|
|
|
+ .append("select id,identity_number,student_name from ec_oe_exam_student ")
|
|
|
|
+ .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
|
|
|
|
+
|
|
|
|
+ int total = 0;
|
|
|
|
+ Long startId = 0L;
|
|
|
|
+ while (true) {
|
|
|
|
+ List<EC_OE_ExamStudent> list = jdbcTemplate.query(
|
|
|
|
+ querySql.toString().replace("?1", startId.toString()),
|
|
|
|
+ new BeanPropertyRowMapper(EC_OE_ExamStudent.class)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ total += list.size();
|
|
|
|
+ startId = list.get(list.size() - 1).getId();
|
|
|
|
+ log.info("[ec_oe_exam_student] lastId:{} curTotal:{}", startId, total);
|
|
|
|
+
|
|
|
|
+ for (EC_OE_ExamStudent obj : list) {
|
|
|
|
+ if (needEncrypt) {
|
|
|
|
+ obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ obj.setStudentName(aes.encrypt(secretKey, obj.getStudentName()));
|
|
|
|
+ } else {
|
|
|
|
+ obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ obj.setStudentName(aes.decrypt(secretKey, obj.getStudentName()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.update_EC_OE_ExamStudent(list);
|
|
|
|
+ list.clear();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void update_EC_OE_ExamStudent(List<EC_OE_ExamStudent> list) {
|
|
|
|
+ StringBuilder sql = new StringBuilder()
|
|
|
|
+ .append("update ec_oe_exam_student ")
|
|
|
|
+ .append("set identity_number = ?,student_name = ? ")
|
|
|
|
+ .append("where id = ? ");
|
|
|
|
+
|
|
|
|
+ jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
|
|
|
|
+ @Override
|
|
|
|
+ public void setValues(PreparedStatement ps, int n) throws SQLException {
|
|
|
|
+ EC_OE_ExamStudent row = list.get(n);
|
|
|
|
+ ps.setString(1, row.getIdentityNumber());
|
|
|
|
+ ps.setString(2, row.getStudentName());
|
|
|
|
+ ps.setLong(3, row.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int getBatchSize() {
|
|
|
|
+ return list.size();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Async
|
|
|
|
+ public void init_EC_OE_ExamRecordData(String secretKey, boolean needEncrypt) {
|
|
|
|
+ StringBuilder querySql = new StringBuilder()
|
|
|
|
+ .append("select id,identity_number,student_name from ec_oe_exam_record_data ")
|
|
|
|
+ .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
|
|
|
|
+
|
|
|
|
+ int total = 0;
|
|
|
|
+ Long startId = 0L;
|
|
|
|
+ while (true) {
|
|
|
|
+ List<EC_OE_ExamRecordData> list = jdbcTemplate.query(
|
|
|
|
+ querySql.toString().replace("?1", startId.toString()),
|
|
|
|
+ new BeanPropertyRowMapper(EC_OE_ExamRecordData.class)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ total += list.size();
|
|
|
|
+ startId = list.get(list.size() - 1).getId();
|
|
|
|
+ log.info("[ec_oe_exam_record_data] lastId:{} curTotal:{}", startId, total);
|
|
|
|
+
|
|
|
|
+ for (EC_OE_ExamRecordData obj : list) {
|
|
|
|
+ if (needEncrypt) {
|
|
|
|
+ obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ obj.setStudentName(aes.encrypt(secretKey, obj.getStudentName()));
|
|
|
|
+ } else {
|
|
|
|
+ obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
|
|
|
|
+ obj.setStudentName(aes.decrypt(secretKey, obj.getStudentName()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.update_EC_OE_ExamRecordData(list);
|
|
|
|
+ list.clear();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void update_EC_OE_ExamRecordData(List<EC_OE_ExamRecordData> list) {
|
|
|
|
+ StringBuilder sql = new StringBuilder()
|
|
|
|
+ .append("update ec_oe_exam_record_data ")
|
|
|
|
+ .append("set identity_number = ?,student_name = ? ")
|
|
|
|
+ .append("where id = ? ");
|
|
|
|
+
|
|
|
|
+ jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
|
|
|
|
+ @Override
|
|
|
|
+ public void setValues(PreparedStatement ps, int n) throws SQLException {
|
|
|
|
+ EC_OE_ExamRecordData row = list.get(n);
|
|
|
|
+ ps.setString(1, row.getIdentityNumber());
|
|
|
|
+ ps.setString(2, row.getStudentName());
|
|
|
|
+ ps.setLong(3, row.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int getBatchSize() {
|
|
|
|
+ return list.size();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|