|
@@ -1,6 +1,7 @@
|
|
|
package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Collections;
|
|
@@ -18,10 +19,12 @@ import javax.persistence.PersistenceUnit;
|
|
|
import javax.persistence.Query;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -32,6 +35,8 @@ import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.base.helpers.poi.ExcelParser;
|
|
|
import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLog;
|
|
|
import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLogFactory;
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.DateUtil;
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.DateUtil.DatePatterns;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.request.InsertOrUpdateStudentReq;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.response.InsertOrUpdateStudentResp;
|
|
@@ -68,6 +73,9 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
|
@PersistenceUnit
|
|
|
private EntityManagerFactory entityManagerFactory;
|
|
|
|
|
|
+ @Value("${$tempDir}")
|
|
|
+ private String $tempDir;
|
|
|
+
|
|
|
private static ExecutorService executorService = Executors.newFixedThreadPool(50);
|
|
|
|
|
|
@Override
|
|
@@ -140,7 +148,12 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
|
|
|
|
result.setFailNum(failRecords.size());
|
|
|
|
|
|
- ExamStudentImportThread thread = new ExamStudentImportThread(failRecords, batchId);
|
|
|
+ String resultFileName = new StringBuilder().append(rootOrgId).append("_").append(examId)
|
|
|
+ .append("_").append(DateUtil.getNow(DatePatterns.YYYYMMDDHHMM)).append(".txt")
|
|
|
+ .toString();
|
|
|
+
|
|
|
+ ExamStudentImportThread thread = new ExamStudentImportThread(failRecords, batchId,
|
|
|
+ resultFileName);
|
|
|
executorService.execute(thread);
|
|
|
|
|
|
return result;
|
|
@@ -154,19 +167,34 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
|
* @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) {
|
|
|
+ private String fileName;
|
|
|
+
|
|
|
+ public ExamStudentImportThread(List<Map<String, Object>> failRecords, Long batchId,
|
|
|
+ String fileName) {
|
|
|
super();
|
|
|
this.failRecords = failRecords;
|
|
|
this.batchId = batchId;
|
|
|
+ this.fileName = fileName;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
saveExamStudents(failRecords, batchId);
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (Map<String, Object> cur : failRecords) {
|
|
|
+ sb.append("line:").append(cur.get("lineNum")).append(cur.get("msg")).append("\n");
|
|
|
+ }
|
|
|
+ File file = new File($tempDir + File.separator + fileName);
|
|
|
+ try {
|
|
|
+ FileUtils.writeStringToFile(file, sb.toString(), "UTF-8");
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("fail to create file.", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -302,12 +330,12 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
|
} catch (StatusException e) {
|
|
|
Map<String, Object> map = Maps.newHashMap();
|
|
|
map.put("lineNum", examStudent.getLineNum());
|
|
|
- map.put("msg", e.getDesc());
|
|
|
+ map.put("msg", " " + e.getDesc());
|
|
|
failRecords.add(map);
|
|
|
} catch (Exception e) {
|
|
|
Map<String, Object> map = Maps.newHashMap();
|
|
|
map.put("lineNum", examStudent.getLineNum());
|
|
|
- map.put("msg", e.getMessage());
|
|
|
+ map.put("msg", " " + e.getMessage());
|
|
|
failRecords.add(map);
|
|
|
}
|
|
|
}
|