|
@@ -8,14 +8,24 @@ import org.apache.poi.ss.usermodel.Sheet;
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
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.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.core.basic.api.StudentCloudService;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.InsertOrUpdateStudentReq;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.InsertOrUpdateStudentResp;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentTempRepo;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentTempRepo;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentTempEntity;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentTempEntity;
|
|
import cn.com.qmth.examcloud.core.examwork.service.ExamStudentImportService;
|
|
import cn.com.qmth.examcloud.core.examwork.service.ExamStudentImportService;
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.ExamStudentCloudService;
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.bean.ExamStudentBean;
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.SaveExamStudentReq;
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.response.SaveExamStudentResp;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 类注释
|
|
* 类注释
|
|
@@ -27,14 +37,22 @@ import cn.com.qmth.examcloud.core.examwork.service.ExamStudentImportService;
|
|
@Service
|
|
@Service
|
|
public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
|
|
|
|
|
|
+ protected ExamCloudLog log = ExamCloudLogFactory.getLog(this.getClass());
|
|
|
|
+
|
|
private static final String[] EXCEL_HEADER = new String[]{"姓名", "学号", "身份证号", "学习中心代码",
|
|
private static final String[] EXCEL_HEADER = new String[]{"姓名", "学号", "身份证号", "学习中心代码",
|
|
"学习中心名称", "课程代码", "课程名称", "试卷类型", "专业", "考点", "信息采集人", "学生电话", "年级"};
|
|
"学习中心名称", "课程代码", "课程名称", "试卷类型", "专业", "考点", "信息采集人", "学生电话", "年级"};
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- ExamStudentTempRepo ExamStudentTempRepo;
|
|
|
|
|
|
+ ExamStudentTempRepo examStudentTempRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ StudentCloudService studentCloudService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ExamStudentCloudService examStudentCloudService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void importExamStudent(File file, String fileName) {
|
|
|
|
|
|
+ public void importExamStudent(File file, String fileName, Long rootOrgId, Long examId) {
|
|
Workbook workBook = ExcelParser.getWorkBook(file, fileName);
|
|
Workbook workBook = ExcelParser.getWorkBook(file, fileName);
|
|
|
|
|
|
Sheet sheet = workBook.getSheetAt(0);
|
|
Sheet sheet = workBook.getSheetAt(0);
|
|
@@ -43,16 +61,19 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
ExcelParser.close(workBook);
|
|
ExcelParser.close(workBook);
|
|
|
|
|
|
List<ExamStudentTempEntity> list = Lists.newArrayList();
|
|
List<ExamStudentTempEntity> list = Lists.newArrayList();
|
|
- long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
|
+ long batchId = System.currentTimeMillis();
|
|
|
|
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
String[] line = lineList.get(i);
|
|
String[] line = lineList.get(i);
|
|
if (0 == i) {
|
|
if (0 == i) {
|
|
checkExcelHeader(line);
|
|
checkExcelHeader(line);
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
|
|
ExamStudentTempEntity es = new ExamStudentTempEntity();
|
|
ExamStudentTempEntity es = new ExamStudentTempEntity();
|
|
- es.setBatchId(currentTimeMillis);
|
|
|
|
|
|
+ es.setRootOrgId(rootOrgId);
|
|
|
|
+ es.setExamId(examId);
|
|
|
|
+ es.setBatchId(batchId);
|
|
es.setName(trimAndNullIfBlank(line[0]));
|
|
es.setName(trimAndNullIfBlank(line[0]));
|
|
es.setStudentCode(trimAndNullIfBlank(line[1]));
|
|
es.setStudentCode(trimAndNullIfBlank(line[1]));
|
|
es.setIdentityNumber(trimAndNullIfBlank(line[2]));
|
|
es.setIdentityNumber(trimAndNullIfBlank(line[2]));
|
|
@@ -68,10 +89,66 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
|
|
es.setGrade(trimAndNullIfBlank(line[12]));
|
|
es.setGrade(trimAndNullIfBlank(line[12]));
|
|
|
|
|
|
list.add(es);
|
|
list.add(es);
|
|
|
|
+ if (0 == i % 100) {
|
|
|
|
+ examStudentTempRepo.save(list);
|
|
|
|
+
|
|
|
|
+ list = Lists.newArrayList();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- ExamStudentTempRepo.save(list);
|
|
|
|
|
|
+ examStudentTempRepo.save(list);
|
|
|
|
+
|
|
|
|
+ examStudentTempRepo.processExamStudentTemp(batchId);
|
|
|
|
+
|
|
|
|
+ saveExamStudents(batchId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void saveExamStudents(Long batchId) {
|
|
|
|
+ List<ExamStudentTempEntity> list = examStudentTempRepo.findRight(batchId);
|
|
|
|
+
|
|
|
|
+ for (ExamStudentTempEntity examStudent : list) {
|
|
|
|
+
|
|
|
|
+ saveExamStudent(examStudent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ @Transactional
|
|
|
|
+ private void saveExamStudent(ExamStudentTempEntity examStudent) {
|
|
|
|
+ InsertOrUpdateStudentReq saveStudentReq = new InsertOrUpdateStudentReq();
|
|
|
|
+ saveStudentReq.setIdentityNumber(examStudent.getIdentityNumber());
|
|
|
|
+ saveStudentReq.setName(examStudent.getName());
|
|
|
|
+ saveStudentReq.setPhoneNumber(examStudent.getPhone());
|
|
|
|
+ saveStudentReq.setOrgCode(examStudent.getOrgCode());
|
|
|
|
+ saveStudentReq.setOrgId(examStudent.getOrgId());
|
|
|
|
+ saveStudentReq.setOrgName(examStudent.getOrgName());
|
|
|
|
+ saveStudentReq.setRootOrgId(examStudent.getRootOrgId());
|
|
|
|
+ saveStudentReq.setStudentCode(examStudent.getStudentCode());
|
|
|
|
+
|
|
|
|
+ InsertOrUpdateStudentResp insertOrUpdateStudentResp = studentCloudService
|
|
|
|
+ .insertOrUpdateStudent(saveStudentReq);
|
|
|
|
+
|
|
|
|
+ Long studentId = insertOrUpdateStudentResp.getStudentId();
|
|
|
|
+
|
|
|
|
+ SaveExamStudentReq saveExamStudentReq = new SaveExamStudentReq();
|
|
|
|
+ saveExamStudentReq.setCourseCode(examStudent.getCourseCode());
|
|
|
|
+ saveExamStudentReq.setCourseLevel(examStudent.getCourseLevel());
|
|
|
|
+ saveExamStudentReq.setCourseName(examStudent.getCourseName());
|
|
|
|
+ saveExamStudentReq.setExamId(examStudent.getExamId());
|
|
|
|
+ saveExamStudentReq.setIdentityNumber(examStudent.getIdentityNumber());
|
|
|
|
+ saveExamStudentReq.setPaperType(examStudent.getPaperType());
|
|
|
|
+ saveExamStudentReq.setRootOrgId(examStudent.getRootOrgId());
|
|
|
|
+ saveExamStudentReq.setStudentCode(examStudent.getStudentCode());
|
|
|
|
+ saveExamStudentReq.setStudentName(examStudent.getName());
|
|
|
|
+ saveExamStudentReq.setStudentId(studentId);
|
|
|
|
+ saveExamStudentReq.setInfoCollector(examStudent.getInfoCollector());
|
|
|
|
+ saveExamStudentReq.setGrade(examStudent.getGrade());
|
|
|
|
+ saveExamStudentReq.setExamSite(examStudent.getExamSite());
|
|
|
|
+ saveExamStudentReq.setSpecialtyName(examStudent.getSpecialtyName());
|
|
|
|
+
|
|
|
|
+ SaveExamStudentResp saveExamStudentResp = examStudentCloudService
|
|
|
|
+ .saveExamStudent(saveExamStudentReq);
|
|
|
|
+ ExamStudentBean examStudentBean = saveExamStudentResp.getExamStudentBean();
|
|
|
|
+ log.debug("examStudentId=" + examStudentBean.getId());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|