|
@@ -2,22 +2,13 @@ package com.qmth.themis.business.templete.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
-import com.google.gson.Gson;
|
|
|
|
-import com.qmth.themis.business.constant.SpringContextHolder;
|
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.dto.ExamStudentImportDto;
|
|
import com.qmth.themis.business.dto.ExamStudentImportDto;
|
|
-import com.qmth.themis.business.entity.TBExamInvigilateUser;
|
|
|
|
-import com.qmth.themis.business.entity.TEExamActivity;
|
|
|
|
-import com.qmth.themis.business.entity.TEExamStudent;
|
|
|
|
-import com.qmth.themis.business.entity.TEStudent;
|
|
|
|
import com.qmth.themis.business.enums.ExamModeEnum;
|
|
import com.qmth.themis.business.enums.ExamModeEnum;
|
|
-import com.qmth.themis.business.service.TBExamInvigilateUserService;
|
|
|
|
-import com.qmth.themis.business.service.TEExamStudentService;
|
|
|
|
-import com.qmth.themis.business.service.TEStudentService;
|
|
|
|
import com.qmth.themis.business.templete.TaskImportCommon;
|
|
import com.qmth.themis.business.templete.TaskImportCommon;
|
|
import com.qmth.themis.business.templete.TaskImportTemplete;
|
|
import com.qmth.themis.business.templete.TaskImportTemplete;
|
|
|
|
+import com.qmth.themis.business.templete.service.TempleteLogicService;
|
|
import com.qmth.themis.business.util.ExcelCallback;
|
|
import com.qmth.themis.business.util.ExcelCallback;
|
|
import com.qmth.themis.business.util.ExcelError;
|
|
import com.qmth.themis.business.util.ExcelError;
|
|
import com.qmth.themis.business.util.ExcelUtil;
|
|
import com.qmth.themis.business.util.ExcelUtil;
|
|
@@ -27,14 +18,14 @@ import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 考生导入任务
|
|
* @Description: 考生导入任务
|
|
@@ -43,9 +34,13 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
* @Author: wangliang
|
|
* @Author: wangliang
|
|
* @Date: 2020/7/15
|
|
* @Date: 2020/7/15
|
|
*/
|
|
*/
|
|
|
|
+@Service
|
|
public class TaskExamStudentImportTemplete implements TaskImportTemplete {
|
|
public class TaskExamStudentImportTemplete implements TaskImportTemplete {
|
|
private final static Logger log = LoggerFactory.getLogger(TaskExamStudentImportTemplete.class);
|
|
private final static Logger log = LoggerFactory.getLogger(TaskExamStudentImportTemplete.class);
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ TempleteLogicService templeteLogicService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 考生导入模版
|
|
* 考生导入模版
|
|
*
|
|
*
|
|
@@ -55,15 +50,13 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
|
|
* @throws InterruptedException
|
|
* @throws InterruptedException
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- @Transactional
|
|
|
|
public Result importTask(Map<String, Object> map) throws IOException {
|
|
public Result importTask(Map<String, Object> map) throws IOException {
|
|
TaskImportCommon taskImportCommon = new TaskImportCommon(map);
|
|
TaskImportCommon taskImportCommon = new TaskImportCommon(map);
|
|
taskImportCommon.init();
|
|
taskImportCommon.init();
|
|
File file = taskImportCommon.getUploadFile();
|
|
File file = taskImportCommon.getUploadFile();
|
|
- List<String> txtList = new ArrayList();
|
|
|
|
|
|
+ taskImportCommon.setTxtList(new ArrayList());
|
|
String timeFormat = taskImportCommon.getTimeFormat();
|
|
String timeFormat = taskImportCommon.getTimeFormat();
|
|
- txtList.add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导入的考生数据");
|
|
|
|
- List<String> finalTxtList = txtList;
|
|
|
|
|
|
+ taskImportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导入的考生数据");
|
|
List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(new FileInputStream(file), Lists.newArrayList(ExamStudentImportDto.class), new ExcelCallback() {
|
|
List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(new FileInputStream(file), Lists.newArrayList(ExamStudentImportDto.class), new ExcelCallback() {
|
|
@Override
|
|
@Override
|
|
public List<LinkedMultiValueMap<Integer, Object>> callback(List<LinkedMultiValueMap<Integer, Object>> finalList, List<LinkedMultiValueMap<Integer, String>> finalColumnNameList) throws IllegalAccessException, IOException {
|
|
public List<LinkedMultiValueMap<Integer, Object>> callback(List<LinkedMultiValueMap<Integer, Object>> finalList, List<LinkedMultiValueMap<Integer, String>> finalColumnNameList) throws IllegalAccessException, IOException {
|
|
@@ -78,15 +71,15 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
|
|
excelErrorList.addAll(excelErrorTemp);
|
|
excelErrorList.addAll(excelErrorTemp);
|
|
}
|
|
}
|
|
//校验考试模式,如果是集中统一,则需填写考试场次
|
|
//校验考试模式,如果是集中统一,则需填写考试场次
|
|
- if (taskImportCommon.getMode().intValue() == ExamModeEnum.together.ordinal() && Objects.isNull(examStudentImportDto.getExamActivityCode())) {
|
|
|
|
|
|
+ if (Objects.equals(taskImportCommon.getMode(), ExamModeEnum.together.name()) && Objects.isNull(examStudentImportDto.getExamActivityCode())) {
|
|
excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[考场]为空"));
|
|
excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[考场]为空"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (excelErrorList.size() > 0) {
|
|
if (excelErrorList.size() > 0) {
|
|
- finalTxtList.add(DateUtil.format(new Date(), timeFormat) + "->数据校验异常:" + JSONObject.toJSONString(excelErrorList));
|
|
|
|
|
|
+ taskImportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->数据校验异常:" + JSONObject.toJSONString(excelErrorList));
|
|
taskImportCommon.setException(true);
|
|
taskImportCommon.setException(true);
|
|
- taskImportCommon.writeImportResultTxt(finalTxtList.toString());
|
|
|
|
|
|
+ taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString());
|
|
throw new BusinessException(JSONObject.toJSONString(excelErrorList));
|
|
throw new BusinessException(JSONObject.toJSONString(excelErrorList));
|
|
}
|
|
}
|
|
return finalList;
|
|
return finalList;
|
|
@@ -96,118 +89,18 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
|
|
if (Objects.nonNull(finalList) && finalList.size() > 0) {
|
|
if (Objects.nonNull(finalList) && finalList.size() > 0) {
|
|
log.info("开始导入考生数据");
|
|
log.info("开始导入考生数据");
|
|
long start = System.currentTimeMillis();
|
|
long start = System.currentTimeMillis();
|
|
-
|
|
|
|
- TEExamStudentService teExamStudentService = SpringContextHolder.getBean(TEExamStudentService.class);
|
|
|
|
- TEStudentService teStudentService = SpringContextHolder.getBean(TEStudentService.class);
|
|
|
|
-// TBUserRoleService tbUserRoleService = SpringContextHolder.getBean(TBUserRoleService.class);
|
|
|
|
- TBExamInvigilateUserService tbExamInvigilateUserService = SpringContextHolder.getBean(TBExamInvigilateUserService.class);
|
|
|
|
-
|
|
|
|
- List<TEExamStudent> teExamStudentList = new ArrayList<>();
|
|
|
|
- List<TEStudent> teStudentList = new ArrayList<>();
|
|
|
|
-// List<TBUserRole> tbUserRoleList = new ArrayList<>();
|
|
|
|
- List<TBExamInvigilateUser> tbExamInvigilateUserList = new ArrayList<>();
|
|
|
|
- int y = 0, min = 0;
|
|
|
|
try {
|
|
try {
|
|
- Gson gson = new Gson();
|
|
|
|
- Set<String> roomCodeAndNameSet = new HashSet<>();
|
|
|
|
- Map<String, TEExamActivity> teExamActivityMap = (Map<String, TEExamActivity>) map.get("teExamActivityMap");
|
|
|
|
- //保存用户
|
|
|
|
- for (int i = 0; i < finalList.size(); i++) {
|
|
|
|
- LinkedMultiValueMap<Integer, Object> finalMap = finalList.get(i);
|
|
|
|
- List<Object> examStudentImportDtoList = finalMap.get(i);
|
|
|
|
- min = 0;
|
|
|
|
- y = 0;
|
|
|
|
- int max = SystemConstant.MAX_IMPORT_SIZE, size = examStudentImportDtoList.size();
|
|
|
|
- if (max >= size) {
|
|
|
|
- max = size;
|
|
|
|
- }
|
|
|
|
- while (max <= size) {
|
|
|
|
- List subList = examStudentImportDtoList.subList(min, max);
|
|
|
|
- for (; y < subList.size(); y++) {
|
|
|
|
- ExamStudentImportDto examStudentImportDto = (ExamStudentImportDto) subList.get(y);
|
|
|
|
- Map m = (Map) teExamActivityMap.get(examStudentImportDto.getExamActivityCode());
|
|
|
|
- m = SystemConstant.timeTransform(m);
|
|
|
|
- TEExamActivity teExamActivity = gson.fromJson(gson.toJson(m), TEExamActivity.class);
|
|
|
|
- //先根据证件号+科目代码查询考生是否存在,存在则更新,不存在则插入
|
|
|
|
- QueryWrapper<TEExamStudent> teExamStudentQueryWrapper = new QueryWrapper<>();
|
|
|
|
- teExamStudentQueryWrapper.lambda().eq(TEExamStudent::getIdentity, examStudentImportDto.getIdentity()).eq(TEExamStudent::getCourseCode, examStudentImportDto.getCourseCode());
|
|
|
|
- TEExamStudent teExamStudent = teExamStudentService.getOne(teExamStudentQueryWrapper);
|
|
|
|
- //如果为空则插入考生数据,插入考生前先插入学生档案数据
|
|
|
|
- if (Objects.isNull(teExamStudent)) {
|
|
|
|
- QueryWrapper<TEStudent> teStudentQueryWrapper = new QueryWrapper<>();
|
|
|
|
- teStudentQueryWrapper.lambda().eq(TEStudent::getIdentity, examStudentImportDto.getIdentity()).eq(TEStudent::getOrgId, taskImportCommon.getOrgId());
|
|
|
|
- TEStudent teStudent = teStudentService.getOne(teStudentQueryWrapper);
|
|
|
|
- if (Objects.isNull(teStudent)) {//如果学生数据为空则插入学生数据
|
|
|
|
- //先插入学生档案数据
|
|
|
|
- teStudent = new TEStudent(taskImportCommon.getOrgId(), examStudentImportDto.getIdentity(), examStudentImportDto.getName(), taskImportCommon.getCreateId());
|
|
|
|
- teStudentService.save(teStudent);
|
|
|
|
- teStudentList.add(teStudent);
|
|
|
|
-
|
|
|
|
-// //插入用户角色关系
|
|
|
|
-// TBUserRole tbUserRole = new TBUserRole(teStudent.getId(), RoleEnum.STUDENT.name());
|
|
|
|
-// tbUserRoleService.save(tbUserRole);
|
|
|
|
-// tbUserRoleList.add(tbUserRole);
|
|
|
|
- }
|
|
|
|
- teExamStudent = gson.fromJson(gson.toJson(examStudentImportDto), TEExamStudent.class);
|
|
|
|
- teExamStudent.setExamId(taskImportCommon.getExamId());
|
|
|
|
- teExamStudent.setExamActivityId(teExamActivity.getId());
|
|
|
|
- teExamStudent.setStudentId(teStudent.getId());
|
|
|
|
- teExamStudent.setCreateId(taskImportCommon.getCreateId());
|
|
|
|
- } else {
|
|
|
|
- teExamStudent.setUpdateId(taskImportCommon.getCreateId());
|
|
|
|
- teExamStudent.setName(examStudentImportDto.getName());
|
|
|
|
- teExamStudent.setCourseName(examStudentImportDto.getCourseName());
|
|
|
|
- teExamStudent.setGrade(examStudentImportDto.getGrade());
|
|
|
|
- teExamStudent.setClassNo(examStudentImportDto.getClassNo());
|
|
|
|
- teExamStudent.setRoomCode(examStudentImportDto.getRoomCode());
|
|
|
|
- teExamStudent.setRoomName(examStudentImportDto.getRoomName());
|
|
|
|
- teExamStudent.setExamActivityId(teExamActivity.getId());
|
|
|
|
- }
|
|
|
|
- teExamStudentService.saveOrUpdate(teExamStudent);
|
|
|
|
- roomCodeAndNameSet.add(teExamStudent.getRoomCode() + ":" + teExamStudent.getRoomName());
|
|
|
|
- teExamStudentList.add(teExamStudent);
|
|
|
|
- }
|
|
|
|
- txtList = taskImportCommon.progress(max, min, size, txtList);
|
|
|
|
- if (max == size) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- min = max;
|
|
|
|
- max += SystemConstant.MAX_IMPORT_SIZE;
|
|
|
|
- if (max >= size) {
|
|
|
|
- max = size;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //考场创建
|
|
|
|
- if (Objects.nonNull(roomCodeAndNameSet) && roomCodeAndNameSet.size() > 0) {
|
|
|
|
- Map<String, String> tbExamInvigilateUserMap = (Map<String, String>) map.get("tbExamInvigilateUserMap");
|
|
|
|
- AtomicInteger count = new AtomicInteger(0);
|
|
|
|
- roomCodeAndNameSet.forEach(s -> {
|
|
|
|
- if (Objects.isNull(tbExamInvigilateUserMap) || (Objects.nonNull(tbExamInvigilateUserMap) && Objects.isNull(tbExamInvigilateUserMap.get(s)))) {
|
|
|
|
- String[] strs = s.split(":");
|
|
|
|
- TBExamInvigilateUser tbExamInvigilateUser = new TBExamInvigilateUser(taskImportCommon.getOrgId(), strs[0], strs[1]);
|
|
|
|
- tbExamInvigilateUserService.save(tbExamInvigilateUser);
|
|
|
|
- tbExamInvigilateUserList.add(tbExamInvigilateUser);
|
|
|
|
- count.getAndIncrement();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if (count.get() > 0) {
|
|
|
|
- txtList.add(DateUtil.format(new Date(), timeFormat) + "->创建了" + count + "条考场数据");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ map = templeteLogicService.execImportExamStudentLogic(finalList, map);
|
|
long end = System.currentTimeMillis();
|
|
long end = System.currentTimeMillis();
|
|
log.info("导入考生数据结束,============耗时============:{}秒", (end - start) / 1000);
|
|
log.info("导入考生数据结束,============耗时============:{}秒", (end - start) / 1000);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- txtList = taskImportCommon.exception(min, y, e, txtList);
|
|
|
|
- if (e instanceof BusinessException) {
|
|
|
|
- throw new BusinessException(e.getMessage());
|
|
|
|
- } else {
|
|
|
|
- throw new RuntimeException(e);
|
|
|
|
- }
|
|
|
|
|
|
+ int min = Objects.isNull(map.get("min")) ? 0 : Integer.parseInt(String.valueOf(map.get("min")));
|
|
|
|
+ int y = Objects.isNull(map.get("y")) ? 0 : Integer.parseInt(String.valueOf(map.get("y")));
|
|
|
|
+ taskImportCommon.exception(min, y, e, taskImportCommon.getTxtList());
|
|
} finally {
|
|
} finally {
|
|
//这里写入txt文件
|
|
//这里写入txt文件
|
|
- taskImportCommon.writeImportResultTxt(txtList.toString());
|
|
|
|
|
|
+ taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|