|
@@ -1,10 +1,14 @@
|
|
package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
import javax.persistence.CacheRetrieveMode;
|
|
import javax.persistence.CacheRetrieveMode;
|
|
import javax.persistence.EntityManager;
|
|
import javax.persistence.EntityManager;
|
|
@@ -64,6 +68,8 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
@PersistenceUnit
|
|
@PersistenceUnit
|
|
private EntityManagerFactory entityManagerFactory;
|
|
private EntityManagerFactory entityManagerFactory;
|
|
|
|
|
|
|
|
+ private static ExecutorService executorService = Executors.newFixedThreadPool(50);
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public ExamStudentImportResult importExamStudent(File file, String fileName, Long rootOrgId,
|
|
public ExamStudentImportResult importExamStudent(File file, String fileName, Long rootOrgId,
|
|
Long examId) {
|
|
Long examId) {
|
|
@@ -82,7 +88,8 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
long batchId = System.currentTimeMillis();
|
|
long batchId = System.currentTimeMillis();
|
|
|
|
|
|
ExamStudentImportResult result = new ExamStudentImportResult();
|
|
ExamStudentImportResult result = new ExamStudentImportResult();
|
|
- List<Map<String, Object>> failRecords = Lists.newArrayList();
|
|
|
|
|
|
+ List<Map<String, Object>> failRecords = Collections
|
|
|
|
+ .synchronizedList(new ArrayList<Map<String, Object>>());
|
|
result.setFailRecords(failRecords);
|
|
result.setFailRecords(failRecords);
|
|
|
|
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
@@ -129,14 +136,41 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
|
|
|
|
findError(failRecords, batchId);
|
|
findError(failRecords, batchId);
|
|
|
|
|
|
- saveExamStudents(failRecords, batchId);
|
|
|
|
-
|
|
|
|
delete(batchId);
|
|
delete(batchId);
|
|
|
|
|
|
result.setFailNum(failRecords.size());
|
|
result.setFailNum(failRecords.size());
|
|
|
|
+
|
|
|
|
+ ExamStudentImportThread thread = new ExamStudentImportThread(failRecords, batchId);
|
|
|
|
+ executorService.execute(thread);
|
|
|
|
+
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 类注释
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @date 2018年7月26日
|
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
|
+ */
|
|
|
|
+ private class ExamStudentImportThread implements Runnable {
|
|
|
|
+ private List<Map<String, Object>> failRecords;
|
|
|
|
+
|
|
|
|
+ private Long batchId;
|
|
|
|
+
|
|
|
|
+ public ExamStudentImportThread(List<Map<String, Object>> failRecords, Long batchId) {
|
|
|
|
+ super();
|
|
|
|
+ this.failRecords = failRecords;
|
|
|
|
+ this.batchId = batchId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ saveExamStudents(failRecords, batchId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
private void findError(List<Map<String, Object>> failRecords, long batchId) {
|
|
private void findError(List<Map<String, Object>> failRecords, long batchId) {
|
|
EntityManager em = entityManagerFactory.createEntityManager();
|
|
EntityManager em = entityManagerFactory.createEntityManager();
|
|
Query query = em.createQuery("select s from ExamStudentTempEntity s where "
|
|
Query query = em.createQuery("select s from ExamStudentTempEntity s where "
|