deason vor 6 Jahren
Ursprung
Commit
46fff4ad87

+ 25 - 8
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/PrintingProjectServiceImpl.java

@@ -11,7 +11,6 @@ import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.core.print.common.jpa.OrderBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
-import cn.com.qmth.examcloud.core.print.common.jpa.SqlWrapper;
 import cn.com.qmth.examcloud.core.print.common.utils.Check;
 import cn.com.qmth.examcloud.core.print.entity.PrintingProject;
 import cn.com.qmth.examcloud.core.print.repository.PrintingProjectRepository;
@@ -23,10 +22,13 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.domain.Specification;
+import org.springframework.jdbc.core.BatchPreparedStatementSetter;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.util.List;
 
 import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
@@ -142,13 +144,28 @@ public class PrintingProjectServiceImpl implements PrintingProjectService {
 
     @Override
     public void dataInit() {
-        SqlWrapper wrapper = new SqlWrapper()
-                .select("em.id as examId,em.name as examName,em.root_org_id as orgId,org.name as orgName")
-                .from("ec_e_exam").as("em")
-                .innerJoin("ec_b_org").as("org").on("org.id", "em.root_org_id")
-                .where().eq("em.exam_type", "TRADITION");
-        List<PrintingProject> list = jdbcTemplate.query(wrapper.build(), new BeanPropertyRowMapper(PrintingProject.class));
-        printingProjectRepository.save(list);
+        //查询数据记录
+        String selectSql = "SELECT em.id as examId,em.name as examName,em.root_org_id as orgId,org.name as orgName FROM ec_e_exam em "
+                + "INNER JOIN ec_b_org org ON org.id = em.root_org_id WHERE em.exam_type = 'TRADITION' ORDER BY em.id ASC";
+        List<PrintingProject> list = jdbcTemplate.query(selectSql, new BeanPropertyRowMapper(PrintingProject.class));
+
+        //批量保存数据
+        String insertSql = "INSERT INTO ec_prt_project(exam_id,exam_name,org_id,org_name,creation_time,update_time) VALUES (?,?,?,?,NOW(),NOW())";
+        jdbcTemplate.batchUpdate(insertSql, new BatchPreparedStatementSetter() {
+            @Override
+            public void setValues(PreparedStatement ps, int i) throws SQLException {
+                PrintingProject row = list.get(i);
+                ps.setLong(1, row.getExamId());
+                ps.setString(2, row.getExamName());
+                ps.setLong(3, row.getOrgId());
+                ps.setString(4, row.getOrgName());
+            }
+
+            @Override
+            public int getBatchSize() {
+                return list.size();
+            }
+        });
     }
 
 }