|
@@ -2,20 +2,22 @@ package com.qmth.themis.business.templete.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import com.google.gson.Gson;
|
|
|
-import com.qmth.themis.business.config.EnvConfig;
|
|
|
import com.qmth.themis.business.constant.SpringContextHolder;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
import com.qmth.themis.business.dto.ExamStudentDtoImport;
|
|
|
-import com.qmth.themis.business.entity.*;
|
|
|
-import com.qmth.themis.business.enums.ExamModeEnum;
|
|
|
-import com.qmth.themis.business.enums.RoleEnum;
|
|
|
-import com.qmth.themis.business.enums.TaskTypeExecEnum;
|
|
|
-import com.qmth.themis.business.service.*;
|
|
|
+import com.qmth.themis.business.entity.TBExamInvigilateUser;
|
|
|
+import com.qmth.themis.business.entity.TBUser;
|
|
|
+import com.qmth.themis.business.entity.TBUserRole;
|
|
|
+import com.qmth.themis.business.service.TBExamInvigilateUserService;
|
|
|
+import com.qmth.themis.business.service.TBUserRoleService;
|
|
|
+import com.qmth.themis.business.service.TBUserService;
|
|
|
+import com.qmth.themis.business.templete.TaskImportCommon;
|
|
|
import com.qmth.themis.business.templete.TaskImportTemplete;
|
|
|
-import com.qmth.themis.business.util.*;
|
|
|
+import com.qmth.themis.business.util.ExcelCallback;
|
|
|
+import com.qmth.themis.business.util.ExcelError;
|
|
|
+import com.qmth.themis.business.util.ExcelUtil;
|
|
|
+import com.qmth.themis.business.util.JacksonUtil;
|
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
|
import com.qmth.themis.common.util.Result;
|
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
@@ -26,15 +28,12 @@ import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
-import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- * @Description: 考生导入任务
|
|
|
+ * @Description: 考场导入任务
|
|
|
* @Param:
|
|
|
* @return:
|
|
|
* @Author: wangliang
|
|
@@ -44,7 +43,7 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
|
|
|
private final static Logger log = LoggerFactory.getLogger(TaskRoomCodeImportTemplete.class);
|
|
|
|
|
|
/**
|
|
|
- * 考生导入模版
|
|
|
+ * 考场导入模版
|
|
|
*
|
|
|
* @param map
|
|
|
* @return
|
|
@@ -54,19 +53,9 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Result importTask(Map<String, Object> map) throws IOException {
|
|
|
- Integer mode = Integer.parseInt(String.valueOf(map.get("mode")));
|
|
|
- Long orgId = Long.parseLong(String.valueOf(map.get("orgId")));
|
|
|
- Long createId = Long.parseLong(String.valueOf(map.get("createId")));
|
|
|
- Long examId = Long.parseLong(String.valueOf(map.get("examId")));
|
|
|
- JSONObject remarkJs = JSONObject.parseObject(String.valueOf(map.get("remark")));
|
|
|
- String type = String.valueOf(remarkJs.get("type"));
|
|
|
- String path = String.valueOf(remarkJs.get("path"));
|
|
|
- Integer uploadType = Integer.parseInt(String.valueOf(remarkJs.get("uploadType")));
|
|
|
- OssUtil ossUtil = SpringContextHolder.getBean(OssUtil.class);
|
|
|
- EnvConfig envConfig = SpringContextHolder.getBean(EnvConfig.class);
|
|
|
- Map<String, Object> ossEnv = envConfig.getOssEnv(uploadType);
|
|
|
- TBTaskHistoryService tbTaskHistoryService = SpringContextHolder.getBean(TBTaskHistoryService.class);
|
|
|
- File file = getUploadFile(path, type, ossEnv, ossUtil);
|
|
|
+ TaskImportCommon taskImportCommon = new TaskImportCommon(map);
|
|
|
+ taskImportCommon.init();
|
|
|
+ File file = taskImportCommon.getUploadFile();
|
|
|
List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(new FileInputStream(file), Lists.newArrayList(ExamStudentDtoImport.class), new ExcelCallback() {
|
|
|
@Override
|
|
|
public List<LinkedMultiValueMap<Integer, Object>> callback(List<LinkedMultiValueMap<Integer, Object>> finalList, List<LinkedMultiValueMap<Integer, String>> finalColumnNameList) throws IllegalAccessException {
|
|
@@ -80,10 +69,6 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
|
|
|
if (excelErrorTemp.size() > 0) {
|
|
|
excelErrorList.addAll(excelErrorTemp);
|
|
|
}
|
|
|
- //校验考试模式,如果是集中统一,则需填写考试场次
|
|
|
- if (mode.intValue() == ExamModeEnum.together.ordinal() && Objects.isNull(examStudentDtoImport.getExamActivityCode())) {
|
|
|
- excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行考场为空"));
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
if (excelErrorList.size() > 0) {
|
|
@@ -92,143 +77,60 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
|
|
|
return finalList;
|
|
|
}
|
|
|
});
|
|
|
- boolean exception = false;
|
|
|
-// String timeFormat = "yyyy-MM-dd HH:mm:ss:sss";
|
|
|
- String timeFormat = "yyyy-MM-dd HH:mm:ss";
|
|
|
//保存数据到数据库
|
|
|
if (Objects.nonNull(finalList) && finalList.size() > 0) {
|
|
|
- log.info("开始导入考生数据");
|
|
|
+ log.info("开始导入考场数据");
|
|
|
long start = System.currentTimeMillis();
|
|
|
- TEExamStudentService teExamStudentService = SpringContextHolder.getBean(TEExamStudentService.class);
|
|
|
- TEStudentService teStudentService = SpringContextHolder.getBean(TEStudentService.class);
|
|
|
+
|
|
|
+ TBUserService tbUserService = SpringContextHolder.getBean(TBUserService.class);
|
|
|
TBUserRoleService tbUserRoleService = SpringContextHolder.getBean(TBUserRoleService.class);
|
|
|
TBExamInvigilateUserService tbExamInvigilateUserService = SpringContextHolder.getBean(TBExamInvigilateUserService.class);
|
|
|
- List<TEExamStudent> teExamStudentList = new ArrayList<>();
|
|
|
- List<TEStudent> teStudentList = new ArrayList<>();
|
|
|
+ String timeFormat = taskImportCommon.getTimeFormat();
|
|
|
+
|
|
|
+ List<TBUser> tbUserList = new ArrayList<>();
|
|
|
List<TBUserRole> tbUserRoleList = new ArrayList<>();
|
|
|
List<TBExamInvigilateUser> tbExamInvigilateUserList = new ArrayList<>();
|
|
|
- List txtList = new ArrayList();
|
|
|
- TBTaskHistory tbTaskHistory = null;
|
|
|
- txtList.add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导入的考生数据");
|
|
|
+ List<String> txtList = new ArrayList();
|
|
|
+ txtList.add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导入的考场数据");
|
|
|
int y = 0, min = 0;
|
|
|
try {
|
|
|
- Gson gson = new Gson();
|
|
|
- Set<String> roomCodeAndNameSet = new HashSet<>();
|
|
|
- Map<String, TEExamActivity> teExamActivityMap = (Map<String, TEExamActivity>) map.get("teExamActivityMap");
|
|
|
- Map tbTaskHistoryMap = (Map) map.get("tbTaskHistory");
|
|
|
- tbTaskHistoryMap = SystemConstant.timeTransform(tbTaskHistoryMap);
|
|
|
- tbTaskHistory = gson.fromJson(gson.toJson(tbTaskHistoryMap), TBTaskHistory.class);
|
|
|
+// Gson gson = new Gson();
|
|
|
//保存用户
|
|
|
for (int i = 0; i < finalList.size(); i++) {
|
|
|
LinkedMultiValueMap<Integer, Object> finalMap = finalList.get(i);
|
|
|
List<Object> examStudentDtoImportList = finalMap.get(i);
|
|
|
min = 0;
|
|
|
- int max = 500, size = examStudentDtoImportList.size();
|
|
|
+ int max = SystemConstant.MAX_IMPORT_SIZE, size = examStudentDtoImportList.size();
|
|
|
if (max >= size) {
|
|
|
max = size;
|
|
|
}
|
|
|
while (max <= size) {
|
|
|
List subList = examStudentDtoImportList.subList(min, max);
|
|
|
for (y = 0; y < subList.size(); y++) {
|
|
|
- ExamStudentDtoImport examStudentDtoImport = (ExamStudentDtoImport) subList.get(y);
|
|
|
- Map m = (Map) teExamActivityMap.get(examStudentDtoImport.getExamActivityCode());
|
|
|
- m = SystemConstant.timeTransform(m);
|
|
|
- TEExamActivity teExamActivity = gson.fromJson(gson.toJson(m), TEExamActivity.class);
|
|
|
- //先根据证件号+科目代码查询考生是否存在,存在则更新,不存在则插入
|
|
|
- QueryWrapper<TEExamStudent> teExamStudentQueryWrapper = new QueryWrapper<>();
|
|
|
- teExamStudentQueryWrapper.lambda().eq(TEExamStudent::getIdentity, examStudentDtoImport.getIdentity()).eq(TEExamStudent::getCourseCode, examStudentDtoImport.getCourseCode());
|
|
|
- TEExamStudent teExamStudent = teExamStudentService.getOne(teExamStudentQueryWrapper);
|
|
|
- //如果为空则插入考生数据,插入考生前先插入学生档案数据
|
|
|
- if (Objects.isNull(teExamStudent)) {
|
|
|
- //先插入学生档案数据
|
|
|
- TEStudent teStudent = new TEStudent(orgId, examStudentDtoImport.getIdentity(), examStudentDtoImport.getName(), createId);
|
|
|
- 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(examStudentDtoImport), TEExamStudent.class);
|
|
|
- teExamStudent.setExamId(examId);
|
|
|
- teExamStudent.setExamActivityId(teExamActivity.getId());
|
|
|
- teExamStudent.setStudentId(teStudent.getId());
|
|
|
- teExamStudent.setCreateId(createId);
|
|
|
- } else {
|
|
|
- teExamStudent.setUpdateId(createId);
|
|
|
- teExamStudent.setName(examStudentDtoImport.getName());
|
|
|
- teExamStudent.setCourseName(examStudentDtoImport.getCourseName());
|
|
|
- teExamStudent.setGrade(examStudentDtoImport.getGrade());
|
|
|
- teExamStudent.setClassNo(examStudentDtoImport.getClassNo());
|
|
|
- teExamStudent.setRoomCode(examStudentDtoImport.getRoomCode());
|
|
|
- teExamStudent.setRoomName(examStudentDtoImport.getRoomName());
|
|
|
- teExamStudent.setExamActivityId(teExamActivity.getId());
|
|
|
- }
|
|
|
- teExamStudentService.saveOrUpdate(teExamStudent);
|
|
|
- roomCodeAndNameSet.add(teExamStudent.getRoomCode() + ":" + teExamStudent.getRoomName());
|
|
|
- teExamStudentList.add(teExamStudent);
|
|
|
}
|
|
|
- BigDecimal bigDecimal = new BigDecimal(100);
|
|
|
- BigDecimal progress = new BigDecimal(Double.valueOf(new BigDecimal(max).divide(new BigDecimal(size), 2, BigDecimal.ROUND_HALF_UP).multiply(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
- log.info("progress:{}", progress);
|
|
|
- if (progress.intValue() == 100) {
|
|
|
- tbTaskHistory.setStatus(TaskTypeExecEnum.finish.ordinal());
|
|
|
- tbTaskHistory.setSummary("共处理了" + size + "条数据");
|
|
|
- tbTaskHistory.setFinishTime(new Date());
|
|
|
- txtList.add(DateUtil.format(new Date(), timeFormat) + "->考生数据处理完毕," + tbTaskHistory.getSummary());
|
|
|
- } else {
|
|
|
- tbTaskHistory.setStatus(TaskTypeExecEnum.running.ordinal());
|
|
|
- tbTaskHistory.setSummary("正在处理第" + min + "条至" + max + "条数据");
|
|
|
- txtList.add(DateUtil.format(new Date(), timeFormat) + "->考生数据处理中," + tbTaskHistory.getSummary());
|
|
|
- }
|
|
|
- tbTaskHistory.setProgress(progress.doubleValue());
|
|
|
- tbTaskHistoryService.updateById(tbTaskHistory);
|
|
|
+ txtList = taskImportCommon.progress(max, min, size, txtList);
|
|
|
if (max == size) {
|
|
|
break;
|
|
|
}
|
|
|
min = max;
|
|
|
- max += 500;
|
|
|
+ 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(orgId, createId, strs[0], strs[1]);
|
|
|
- tbExamInvigilateUserService.save(tbExamInvigilateUser);
|
|
|
- tbExamInvigilateUserList.add(tbExamInvigilateUser);
|
|
|
- count.getAndIncrement();
|
|
|
- }
|
|
|
- });
|
|
|
- if (count.get() > 0) {
|
|
|
- txtList.add(DateUtil.format(new Date(), timeFormat) + "->创建了" + count + "条考场数据");
|
|
|
- }
|
|
|
- }
|
|
|
long end = System.currentTimeMillis();
|
|
|
- log.info("导入考生数据结束,============耗时============:{}秒", (end - start) / 1000);
|
|
|
+ log.info("导入考场数据结束,============耗时============:{}秒", (end - start) / 1000);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- exception = true;
|
|
|
- String exceptionStr = "考生数据处理到第" + (min + y + 1) + "条时发生异常:" + e.getMessage();
|
|
|
- txtList.add(DateUtil.format(new Date(), timeFormat) + "->" + exceptionStr);
|
|
|
- tbTaskHistory.setSummary(exceptionStr);
|
|
|
- tbTaskHistoryService.updateById(tbTaskHistory);
|
|
|
- if (Objects.nonNull(teStudentList) && teStudentList.size() > 0) {
|
|
|
- teStudentService.removeByIds(teStudentList.stream().map(s -> s.getId()).collect(Collectors.toList()));
|
|
|
+ txtList = taskImportCommon.exception(min, y, e, txtList);
|
|
|
+ if (Objects.nonNull(tbUserList) && tbUserList.size() > 0) {
|
|
|
+ tbUserService.removeByIds(tbUserList.stream().map(s -> s.getId()).collect(Collectors.toList()));
|
|
|
}
|
|
|
if (Objects.nonNull(tbUserRoleList) && tbUserRoleList.size() > 0) {
|
|
|
tbUserRoleService.removeByIds(tbUserRoleList.stream().map(s -> s.getId()).collect(Collectors.toList()));
|
|
|
}
|
|
|
- if (Objects.nonNull(teExamStudentList) && teExamStudentList.size() > 0) {
|
|
|
- teExamStudentService.removeByIds(teExamStudentList.stream().map(s -> s.getId()).collect(Collectors.toList()));
|
|
|
- }
|
|
|
if (Objects.nonNull(tbExamInvigilateUserList) && tbExamInvigilateUserList.size() > 0) {
|
|
|
tbExamInvigilateUserService.removeByIds(tbExamInvigilateUserList.stream().map(s -> s.getId()).collect(Collectors.toList()));
|
|
|
}
|
|
@@ -239,80 +141,9 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
} finally {
|
|
|
//这里写入txt文件
|
|
|
- writeImportResultTxt(exception, ossUtil, tbTaskHistoryService, tbTaskHistory, txtList.toString(), path, type, ossEnv);
|
|
|
+ taskImportCommon.writeImportResultTxt(txtList.toString());
|
|
|
}
|
|
|
}
|
|
|
return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取上传的文件
|
|
|
- *
|
|
|
- * @param path
|
|
|
- * @param type
|
|
|
- * @param ossEnv
|
|
|
- * @param ossUtil
|
|
|
- * @return
|
|
|
- */
|
|
|
- File getUploadFile(String path, String type, Map<String, Object> ossEnv, OssUtil ossUtil) {
|
|
|
- StringJoiner localPath = new StringJoiner("").add(
|
|
|
- System.getProperty(SystemConstant.USER_DIR)).add(File.separator).add(path);
|
|
|
- File file = null;
|
|
|
- if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.LOCAL)) {
|
|
|
- file = new File(localPath.toString());
|
|
|
- } else {
|
|
|
- try {
|
|
|
- file = ossUtil.ossDownload(ossEnv, localPath.toString(), localPath.toString());
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- return file;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 写入txt文件
|
|
|
- *
|
|
|
- * @param exception
|
|
|
- * @param ossUtil
|
|
|
- * @param tbTaskHistoryService
|
|
|
- * @param tbTaskHistory
|
|
|
- * @param txtStr
|
|
|
- * @param path
|
|
|
- * @param type
|
|
|
- * @param ossEnv
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- void writeImportResultTxt(boolean exception, OssUtil ossUtil, TBTaskHistoryService tbTaskHistoryService, TBTaskHistory tbTaskHistory, String txtStr, String path, String type, Map<String, Object> ossEnv) throws IOException {
|
|
|
- FileWriter fileWriter = null;
|
|
|
- try {
|
|
|
- path = path.substring(0, path.lastIndexOf(File.separator) + 1);
|
|
|
- File file = new File(path + tbTaskHistory.getId() + ".txt");
|
|
|
- if (!file.exists()) {
|
|
|
- file.createNewFile();
|
|
|
- }
|
|
|
- fileWriter = new FileWriter(file);
|
|
|
- fileWriter.write(txtStr);
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("path", file.getPath());
|
|
|
- json.put("type", type);
|
|
|
- if (exception) {
|
|
|
- tbTaskHistory.setErrorFilePath(json.toJSONString());
|
|
|
- } else {
|
|
|
- tbTaskHistory.setResultFilePath(json.toJSONString());
|
|
|
- }
|
|
|
- if (Objects.equals(type, SystemConstant.OSS)) {
|
|
|
- ossUtil.ossUpload(ossEnv, file.getPath(), txtStr);
|
|
|
- file.delete();
|
|
|
- }
|
|
|
- tbTaskHistoryService.updateById(tbTaskHistory);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- if (Objects.nonNull(fileWriter)) {
|
|
|
- fileWriter.flush();
|
|
|
- fileWriter.close();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|