wangliang 4 vuotta sitten
vanhempi
commit
0b9473527c

+ 2 - 2
themis-backend/src/main/java/com/qmth/themis/backend/api/TEStudentController.java

@@ -80,8 +80,8 @@ public class TEStudentController {
     @RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
     @Transactional
-    public Result updatePwd(@ApiJsonObject(name = "studentUpdatePwd", value = {
-            @ApiJsonProperty(key = "id", type = "long", example = "1", description = "学生ID"),
+    public Result studentUpdatePwd(@ApiJsonObject(name = "studentUpdatePwd", value = {
+            @ApiJsonProperty(key = "id", type = "long", example = "1", description = "用户ID"),
             @ApiJsonProperty(key = "password", description = "新密码")
     }) @ApiParam(value = "学生信息", required = true) @RequestBody Map<String, Object> mapParameter) {
         if (Objects.isNull(mapParameter.get("id")) || Objects.equals(mapParameter.get("id"), "")) {

+ 19 - 10
themis-business/src/main/java/com/qmth/themis/business/templete/TaskExportCommon.java

@@ -40,6 +40,7 @@ public class TaskExportCommon {
     private boolean exception = false;
     private TBAttachmentService tbAttachmentService = null;
     private String type = null;
+    private List<String> txtList = null;
 
     public TaskExportCommon() {
 
@@ -68,21 +69,21 @@ public class TaskExportCommon {
         this.tbTaskHistoryService = SpringContextHolder.getBean(TBTaskHistoryService.class);
         this.tbAttachmentService = SpringContextHolder.getBean(TBAttachmentService.class);
         this.timeFormat = "yyyy-MM-dd HH:mm:ss";
+        map.put("tbTaskHistory", tbTaskHistory);
+        map.put("timeFormat", timeFormat);
     }
 
     /**
-     * 创建excel
+     * 创建文件
      *
+     * @param path
      * @return
+     * @throws IOException
      */
-    public File createExcel() throws IOException {
+    public File createExcel(String path) throws IOException {
         LocalDateTime nowTime = LocalDateTime.now();
         StringJoiner stringJoiner = new StringJoiner("");
-        String uploadType = String.valueOf(this.ossEnv.get(SystemConstant.UPLOAD_TYPE));
-        stringJoiner.add(uploadType).add(File.separator).add(String.valueOf(nowTime.getYear()))
-                .add(File.separator).add(String.valueOf(nowTime.getMonthValue()))
-                .add(File.separator).add(String.valueOf(nowTime.getDayOfMonth()));
-        File file = new File(stringJoiner.add(File.separator).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
+        File file = new File(stringJoiner.add(path).add(File.separator).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
                 .add(SystemConstant.EXCEL_PREFIX).toString());
         if (!file.exists()) {
             file.getParentFile().mkdirs();
@@ -129,8 +130,7 @@ public class TaskExportCommon {
     public void writeExportResultTxt(String path, String txtStr) throws IOException {
         FileWriter fileWriter = null;
         try {
-            path = path.substring(0, path.lastIndexOf(File.separator) + 1);
-            File file = new File(path + String.valueOf(UUID.randomUUID()).replaceAll("-", "") + SystemConstant.TXT_PREFIX);
+            File file = new File(path + File.separator + String.valueOf(UUID.randomUUID()).replaceAll("-", "") + SystemConstant.TXT_PREFIX);
             if (!file.exists()) {
                 file.getParentFile().mkdirs();
                 file.createNewFile();
@@ -198,7 +198,7 @@ public class TaskExportCommon {
      */
     public List<String> exception(int min, int y, Exception e, List<String> txtList) {
         this.exception = true;
-        String exceptionStr = "数据导出到第" + (min + y + 1) + "条时发生异常:" + e.getMessage();
+        String exceptionStr = "数据导出到第" + (y == 0 ? y + 1 : y) + "条时发生异常:" + e.getMessage();
         txtList.add(DateUtil.format(new Date(), this.timeFormat) + "->" + exceptionStr);
         this.tbTaskHistory.setSummary(exceptionStr);
         this.tbTaskHistoryService.updateById(this.tbTaskHistory);
@@ -248,4 +248,13 @@ public class TaskExportCommon {
     public TBAttachmentService getTbAttachmentService() {
         return tbAttachmentService;
     }
+
+    public List<String> getTxtList() {
+        return txtList;
+    }
+
+    public void setTxtList(List<String> txtList) {
+        this.txtList = txtList;
+        map.put("txtList", txtList);
+    }
 }

+ 16 - 33
themis-business/src/main/java/com/qmth/themis/business/templete/TaskImportCommon.java

@@ -7,14 +7,12 @@ import com.qmth.themis.business.config.SystemConfig;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.TBTaskHistory;
-import com.qmth.themis.business.enums.TaskStatusEnum;
 import com.qmth.themis.business.service.TBTaskHistoryService;
 import com.qmth.themis.business.util.OssUtil;
 
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.math.BigDecimal;
 import java.util.*;
 
 /**
@@ -25,7 +23,7 @@ import java.util.*;
  * @Date: 2020/7/19
  */
 public class TaskImportCommon {
-    private Integer mode = null;
+    private String mode = null;
     private Map<String, Object> map = null;
     private Long orgId = null;
     private Long createId = null;
@@ -39,6 +37,7 @@ public class TaskImportCommon {
     private TBTaskHistory tbTaskHistory = null;
     private String timeFormat = null;
     private boolean exception = false;
+    private List<String> txtList = null;
 
     public TaskImportCommon() {
 
@@ -55,7 +54,7 @@ public class TaskImportCommon {
         SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
         Gson gson = new Gson();
         if (Objects.nonNull(this.map.get("mode"))) {
-            this.mode = Integer.parseInt(String.valueOf(this.map.get("mode")));
+            this.mode = String.valueOf(this.map.get("mode"));
         }
         if (Objects.nonNull(this.map.get("orgId"))) {
             this.orgId = Long.parseLong(String.valueOf(this.map.get("orgId")));
@@ -75,6 +74,8 @@ public class TaskImportCommon {
         this.tbTaskHistory = gson.fromJson(gson.toJson(tbTaskHistoryMap), TBTaskHistory.class);
         this.tbTaskHistoryService = SpringContextHolder.getBean(TBTaskHistoryService.class);
         this.timeFormat = "yyyy-MM-dd HH:mm:ss";
+        map.put("tbTaskHistory", tbTaskHistory);
+        map.put("timeFormat", timeFormat);
     }
 
     /**
@@ -138,33 +139,6 @@ public class TaskImportCommon {
         }
     }
 
-    /**
-     * 换算进度
-     *
-     * @param max
-     * @param min
-     * @param size
-     * @param txtList
-     * @return
-     */
-    public List<String> progress(int max, int min, int size, List<String> txtList) {
-        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);
-        if (progress.intValue() == 100) {
-            this.tbTaskHistory.setStatus(TaskStatusEnum.finish);
-            this.tbTaskHistory.setSummary("共处理了" + size + "条数据");
-            this.tbTaskHistory.setFinishTime(new Date());
-            txtList.add(DateUtil.format(new Date(), this.timeFormat) + "->数据处理完毕," + this.tbTaskHistory.getSummary());
-        } else {
-            this.tbTaskHistory.setStatus(TaskStatusEnum.running);
-            this.tbTaskHistory.setSummary("正在处理第" + min + "条至" + max + "条数据");
-            txtList.add(DateUtil.format(new Date(), this.timeFormat) + "->数据处理中," + this.tbTaskHistory.getSummary());
-        }
-        this.tbTaskHistory.setProgress(progress.doubleValue());
-        this.tbTaskHistoryService.updateById(this.tbTaskHistory);
-        return txtList;
-    }
-
     /**
      * 异常处理
      *
@@ -176,13 +150,22 @@ public class TaskImportCommon {
      */
     public List<String> exception(int min, int y, Exception e, List<String> txtList) {
         this.exception = true;
-        String exceptionStr = "数据处理到第" + (min + y + 1) + "条时发生异常:" + e.getMessage();
+        String exceptionStr = "数据处理到第" + (y == 0 ? y + 1 : y) + "条时发生异常:" + e.getMessage();
         txtList.add(DateUtil.format(new Date(), this.timeFormat) + "->" + exceptionStr);
         this.tbTaskHistory.setSummary(exceptionStr);
         this.tbTaskHistoryService.updateById(this.tbTaskHistory);
         return txtList;
     }
 
+    public List<String> getTxtList() {
+        return txtList;
+    }
+
+    public void setTxtList(List<String> txtList) {
+        this.txtList = txtList;
+        map.put("txtList", txtList);
+    }
+
     public void setException(boolean exception) {
         this.exception = exception;
     }
@@ -195,7 +178,7 @@ public class TaskImportCommon {
         return timeFormat;
     }
 
-    public Integer getMode() {
+    public String getMode() {
         return mode;
     }
 

+ 17 - 124
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentImportTemplete.java

@@ -2,22 +2,13 @@ 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.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 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.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.TaskImportTemplete;
+import com.qmth.themis.business.templete.service.TempleteLogicService;
 import com.qmth.themis.business.util.ExcelCallback;
 import com.qmth.themis.business.util.ExcelError;
 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 org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.transaction.annotation.Transactional;
+import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
 
+import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * @Description: 考生导入任务
@@ -43,9 +34,13 @@ import java.util.concurrent.atomic.AtomicInteger;
  * @Author: wangliang
  * @Date: 2020/7/15
  */
+@Service
 public class TaskExamStudentImportTemplete implements TaskImportTemplete {
     private final static Logger log = LoggerFactory.getLogger(TaskExamStudentImportTemplete.class);
 
+    @Resource
+    TempleteLogicService templeteLogicService;
+
     /**
      * 考生导入模版
      *
@@ -55,15 +50,13 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
      * @throws InterruptedException
      */
     @Override
-    @Transactional
     public Result importTask(Map<String, Object> map) throws IOException {
         TaskImportCommon taskImportCommon = new TaskImportCommon(map);
         taskImportCommon.init();
         File file = taskImportCommon.getUploadFile();
-        List<String> txtList = new ArrayList();
+        taskImportCommon.setTxtList(new ArrayList());
         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() {
             @Override
             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);
                         }
                         //校验考试模式,如果是集中统一,则需填写考试场次
-                        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) + "行[考场]为空"));
                         }
                     }
                 }
                 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.writeImportResultTxt(finalTxtList.toString());
+                    taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString());
                     throw new BusinessException(JSONObject.toJSONString(excelErrorList));
                 }
                 return finalList;
@@ -96,118 +89,18 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
         if (Objects.nonNull(finalList) && finalList.size() > 0) {
             log.info("开始导入考生数据");
             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 {
-                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();
                 log.info("导入考生数据结束,============耗时============:{}秒", (end - start) / 1000);
             } catch (Exception e) {
                 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 {
                 //这里写入txt文件
-                taskImportCommon.writeImportResultTxt(txtList.toString());
+                taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString());
             }
         }
         return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));

+ 31 - 17
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskRoomCodeExportTemplete.java

@@ -2,26 +2,27 @@ package com.qmth.themis.business.templete.impl;
 
 import cn.hutool.core.date.DateUtil;
 import com.qmth.themis.business.annotation.ExcelNote;
-import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.RoomCodeExportDto;
 import com.qmth.themis.business.service.TBExamInvigilateUserService;
 import com.qmth.themis.business.templete.TaskExportCommon;
 import com.qmth.themis.business.templete.TaskExportTemplete;
+import com.qmth.themis.business.templete.service.TempleteLogicService;
 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;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.transaction.annotation.Transactional;
+import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Field;
+import java.time.LocalDateTime;
 import java.util.*;
 
 /**
@@ -31,9 +32,16 @@ import java.util.*;
  * @Author: wangliang
  * @Date: 2020/7/20
  */
+@Service
 public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
     private final static Logger log = LoggerFactory.getLogger(TaskRoomCodeExportTemplete.class);
 
+    @Resource
+    TempleteLogicService templeteLogicService;
+
+    @Resource
+    TBExamInvigilateUserService tbExamInvigilateUserService;
+
     /**
      * 考场导出模版
      *
@@ -41,23 +49,31 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
      * @return
      */
     @Override
-    @Transactional
     public Result exportTask(Map<String, Object> map) throws IOException {
         log.info("开始导出考场数据");
         long start = System.currentTimeMillis();
         TaskExportCommon taskExportCommon = new TaskExportCommon(map);
         taskExportCommon.init();
         String timeFormat = taskExportCommon.getTimeFormat();
-        List<String> txtList = new ArrayList();
+        taskExportCommon.setTxtList(new ArrayList());
         FileOutputStream fos = null;
         SXSSFWorkbook wb = null;
-        File file = null;
+        File mkdir = null;
         int y = 0, min = 0;
         try {
-            txtList.add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导出的考场数据");
-            TBExamInvigilateUserService tbExamInvigilateUserService = SpringContextHolder.getBean(TBExamInvigilateUserService.class);
+            taskExportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导出的考场数据");
             List<RoomCodeExportDto> roomCodeExportDtoList = tbExamInvigilateUserService.examInvigilateUserExport();
 
+            LocalDateTime nowTime = LocalDateTime.now();
+            StringJoiner stringJoiner = new StringJoiner("");
+            String uploadType = String.valueOf(taskExportCommon.getOssEnv().get(SystemConstant.UPLOAD_TYPE));
+            stringJoiner.add(uploadType).add(File.separator).add(String.valueOf(nowTime.getYear()))
+                    .add(File.separator).add(String.valueOf(nowTime.getMonthValue()))
+                    .add(File.separator).add(String.valueOf(nowTime.getDayOfMonth()));
+            mkdir = new File(stringJoiner.toString());
+            if (!mkdir.exists()) {
+                mkdir.mkdirs();
+            }
             //创建excel
             wb = new SXSSFWorkbook();
             Sheet sheet = wb.createSheet("考场导出");
@@ -93,7 +109,10 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
                         cellIndex++;
                     }
                 }
-                txtList = taskExportCommon.progress(max, min, size, txtList);
+                map.put("max", max);
+                map.put("min", min);
+                map.put("size", size);
+                map = templeteLogicService.execExportRoomCodeLogic(map);
                 if (max == size) {
                     break;
                 }
@@ -103,7 +122,7 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
                     max = size;
                 }
             }
-            file = taskExportCommon.createExcel();
+            File file = taskExportCommon.createExcel(mkdir.getPath());
             //写入excel并上传附件
             fos = new FileOutputStream(file);
             wb.write(fos);
@@ -112,12 +131,7 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
             log.info("导出考场数据结束,============耗时============:{}秒", (end - start) / 1000);
         } catch (Exception e) {
             e.printStackTrace();
-            txtList = taskExportCommon.exception(min, y, e, txtList);
-            if (e instanceof BusinessException) {
-                throw new BusinessException(e.getMessage());
-            } else {
-                throw new RuntimeException(e);
-            }
+            taskExportCommon.exception(min, y, e, taskExportCommon.getTxtList());
         } finally {
             if (Objects.nonNull(wb)) {
                 wb.dispose();
@@ -127,7 +141,7 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
                 fos.close();
             }
             //这里写入txt文件
-            taskExportCommon.writeExportResultTxt(file.getPath(), txtList.toString());
+            taskExportCommon.writeExportResultTxt(mkdir.getPath(), taskExportCommon.getTxtList().toString());
         }
         return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
     }

+ 15 - 99
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskRoomCodeImportTemplete.java

@@ -2,20 +2,12 @@ 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.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.RoomCodeImportDto;
-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.enums.RoleEnum;
-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.templete.service.TempleteLogicService;
 import com.qmth.themis.business.util.ExcelCallback;
 import com.qmth.themis.business.util.ExcelError;
 import com.qmth.themis.business.util.ExcelUtil;
@@ -25,9 +17,10 @@ import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.transaction.annotation.Transactional;
+import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
 
+import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -40,16 +33,12 @@ import java.util.*;
  * @Author: wangliang
  * @Date: 2020/7/15
  */
+@Service
 public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
     private final static Logger log = LoggerFactory.getLogger(TaskRoomCodeImportTemplete.class);
 
-    private TBUserService tbUserService = SpringContextHolder.getBean(TBUserService.class);
-    private TBUserRoleService tbUserRoleService = SpringContextHolder.getBean(TBUserRoleService.class);
-    private TBExamInvigilateUserService tbExamInvigilateUserService = SpringContextHolder.getBean(TBExamInvigilateUserService.class);
-
-    private List<TBUser> tbUserList = null;
-    private List<TBUserRole> tbUserRoleList = null;
-    private List<TBExamInvigilateUser> tbExamInvigilateUserList = null;
+    @Resource
+    TempleteLogicService templeteLogicService;
 
     /**
      * 考场导入模版
@@ -60,15 +49,13 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
      * @throws InterruptedException
      */
     @Override
-    @Transactional
     public Result importTask(Map<String, Object> map) throws IOException {
         TaskImportCommon taskImportCommon = new TaskImportCommon(map);
         taskImportCommon.init();
         File file = taskImportCommon.getUploadFile();
-        List<String> txtList = new ArrayList();
+        taskImportCommon.setTxtList(new ArrayList());
         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(RoomCodeImportDto.class), new ExcelCallback() {
             @Override
             public List<LinkedMultiValueMap<Integer, Object>> callback(List<LinkedMultiValueMap<Integer, Object>> finalList, List<LinkedMultiValueMap<Integer, String>> finalColumnNameList) throws IllegalAccessException, IOException {
@@ -85,9 +72,9 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
                     }
                 }
                 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.writeImportResultTxt(finalTxtList.toString());
+                    taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString());
                     throw new BusinessException(JSONObject.toJSONString(excelErrorList));
                 }
                 return finalList;
@@ -97,91 +84,20 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
         if (Objects.nonNull(finalList) && finalList.size() > 0) {
             log.info("开始导入考场数据");
             long start = System.currentTimeMillis();
-
-            tbUserList = new ArrayList<>();
-            tbUserRoleList = new ArrayList<>();
-            tbExamInvigilateUserList = new ArrayList<>();
-            int y = 0, min = 0;
             try {
-                //保存用户
-                for (int i = 0; i < finalList.size(); i++) {
-                    LinkedMultiValueMap<Integer, Object> finalMap = finalList.get(i);
-                    List<Object> examStudentDtoImportList = finalMap.get(i);
-                    min = 0;
-                    y = 0;
-                    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 < subList.size(); y++) {
-                            RoomCodeImportDto roomCodeImportDto = (RoomCodeImportDto) subList.get(y);
-                            dataVerify(roomCodeImportDto.getTeacher1(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), taskImportCommon.getOrgId(), taskImportCommon.getCreateId());
-                            dataVerify(roomCodeImportDto.getTeacher2(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), taskImportCommon.getOrgId(), taskImportCommon.getCreateId());
-                            dataVerify(roomCodeImportDto.getTeacher3(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), taskImportCommon.getOrgId(), taskImportCommon.getCreateId());
-                        }
-                        txtList = taskImportCommon.progress(max, min, size, txtList);
-                        if (max == size) {
-                            break;
-                        }
-                        min = max;
-                        max += SystemConstant.MAX_IMPORT_SIZE;
-                        if (max >= size) {
-                            max = size;
-                        }
-                    }
-                }
+                map = templeteLogicService.execImportRoomCodeLogic(finalList, map);
                 long end = System.currentTimeMillis();
                 log.info("导入考场数据结束,============耗时============:{}秒", (end - start) / 1000);
             } catch (Exception e) {
                 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 {
                 //这里写入txt文件
-                taskImportCommon.writeImportResultTxt(txtList.toString());
+                taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString());
             }
         }
         return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
     }
-
-    /**
-     * 查询监考帐号是否存在
-     *
-     * @param userName
-     * @param roomCode
-     * @param roomName
-     * @param orgId
-     * @param createId
-     */
-    void dataVerify(String userName, String roomCode, String roomName, Long orgId, Long createId) {
-        if (Objects.nonNull(userName)) {
-            //先查询监考帐号是否存在
-            QueryWrapper<TBUser> tbUserQueryWrapper = new QueryWrapper<>();
-            tbUserQueryWrapper.lambda().eq(TBUser::getLoginName, userName).eq(TBUser::getOrgId, orgId);
-            TBUser tbUser = tbUserService.getOne(tbUserQueryWrapper);
-            if (Objects.isNull(tbUser)) {
-                //新增用户
-                tbUser = new TBUser(orgId, userName, userName, createId);
-                tbUserService.save(tbUser);
-                tbUserList.add(tbUser);
-
-                //新增用户角色
-//                TBUserRole tbUserRole = new TBUserRole(tbUser.getId(), RoleEnum.TEACHER.name());
-//                tbUserRoleService.save(tbUserRole);
-                TBUserRole tbUserRole = new TBUserRole(tbUser.getId(), RoleEnum.INVIGILATE.name());
-                tbUserRoleService.save(tbUserRole);
-                tbUserRoleList.add(tbUserRole);
-            }
-            //新增考场
-            TBExamInvigilateUser tbExamInvigilateUser = new TBExamInvigilateUser(orgId, tbUser.getId(), roomCode, roomName);
-            tbExamInvigilateUserService.save(tbExamInvigilateUser);
-            tbExamInvigilateUserList.add(tbExamInvigilateUser);
-        }
-    }
 }

+ 43 - 0
themis-business/src/main/java/com/qmth/themis/business/templete/service/TempleteLogicService.java

@@ -0,0 +1,43 @@
+package com.qmth.themis.business.templete.service;
+
+import com.qmth.themis.business.dto.RoomCodeExportDto;
+import org.springframework.util.LinkedMultiValueMap;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 导入导出模版处理逻辑
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/7/31
+ */
+public interface TempleteLogicService {
+
+    /**
+     * 考生导入逻辑
+     *
+     * @param finalList
+     * @param map
+     * @return
+     */
+    public Map<String, Object> execImportExamStudentLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map);
+
+    /**
+     * 考场导入逻辑
+     *
+     * @param finalList
+     * @param map
+     * @return
+     */
+    public Map<String, Object> execImportRoomCodeLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map);
+
+    /**
+     * 考场导出逻辑
+     *
+     * @param map
+     * @return
+     */
+    public Map<String, Object> execExportRoomCodeLogic(Map<String, Object> map);
+}

+ 325 - 0
themis-business/src/main/java/com/qmth/themis/business/templete/service/impl/TempleteLogicServiceImpl.java

@@ -0,0 +1,325 @@
+package com.qmth.themis.business.templete.service.impl;
+
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.google.gson.Gson;
+import com.qmth.themis.business.config.SystemConfig;
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.dto.ExamStudentImportDto;
+import com.qmth.themis.business.dto.RoomCodeImportDto;
+import com.qmth.themis.business.entity.*;
+import com.qmth.themis.business.enums.RoleEnum;
+import com.qmth.themis.business.enums.TaskStatusEnum;
+import com.qmth.themis.business.service.*;
+import com.qmth.themis.business.templete.service.TempleteLogicService;
+import com.qmth.themis.business.util.OssUtil;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.LinkedMultiValueMap;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @Description: 导入导出模版处理逻辑 impl
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/7/31
+ */
+@Service
+public class TempleteLogicServiceImpl implements TempleteLogicService {
+
+    @Resource
+    TBTaskHistoryService tbTaskHistoryService;
+
+    @Resource
+    SystemConfig systemConfig;
+
+    @Resource
+    OssUtil ossUtil;
+
+    @Resource
+    TEExamStudentService teExamStudentService;
+
+    @Resource
+    TEStudentService teStudentService;
+
+    @Resource
+    TBExamInvigilateUserService tbExamInvigilateUserService;
+
+    @Resource
+    TBUserService tbUserService;
+
+    @Resource
+    TBUserRoleService tbUserRoleService;
+
+    /**
+     * 考生导入逻辑
+     *
+     * @param finalList
+     * @param map
+     * @return
+     */
+    @Override
+    @Transactional
+    public Map<String, Object> execImportExamStudentLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map) {
+        Long orgId = Long.parseLong(String.valueOf(map.get("orgId")));
+        Long examId = Long.parseLong(String.valueOf(map.get("examId")));
+        Long createId = Long.parseLong(String.valueOf(map.get("createId")));
+        List<String> txtList = (List<String>) map.get("txtList");
+        TBTaskHistory tbTaskHistory = (TBTaskHistory) map.get("tbTaskHistory");
+        String timeFormat = String.valueOf(map.get("timeFormat"));
+        List<TEExamStudent> teExamStudentList = new ArrayList<>();
+        List<TEStudent> teStudentList = new ArrayList<>();
+        List<TBExamInvigilateUser> tbExamInvigilateUserList = new ArrayList<>();
+        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);
+            int min = 0;
+            int 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, orgId);
+                        TEStudent teStudent = teStudentService.getOne(teStudentQueryWrapper);
+                        if (Objects.isNull(teStudent)) {//如果学生数据为空则插入学生数据
+                            //先插入学生档案数据
+                            teStudent = new TEStudent(orgId, examStudentImportDto.getIdentity(), examStudentImportDto.getName(), createId);
+                            teStudentService.save(teStudent);
+                            teStudentList.add(teStudent);
+                        }
+                        teExamStudent = gson.fromJson(gson.toJson(examStudentImportDto), TEExamStudent.class);
+                        teExamStudent.setExamId(examId);
+                        teExamStudent.setExamActivityId(teExamActivity.getId());
+                        teExamStudent.setStudentId(teStudent.getId());
+                        teExamStudent.setCreateId(createId);
+                    } else {
+                        teExamStudent.setUpdateId(createId);
+                        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 = this.importProgress(max, min, size, txtList, tbTaskHistory, timeFormat);
+                map.put("min", min);
+                map.put("y", y);
+                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(orgId, strs[0], strs[1]);
+                    tbExamInvigilateUserService.save(tbExamInvigilateUser);
+                    tbExamInvigilateUserList.add(tbExamInvigilateUser);
+                    count.getAndIncrement();
+                }
+            });
+            if (count.get() > 0) {
+                txtList.add(DateUtil.format(new Date(), timeFormat) + "->创建了" + count + "条考场数据");
+            }
+        }
+        return map;
+    }
+
+    /**
+     * 考场导入逻辑
+     *
+     * @param finalList
+     * @param map
+     * @return
+     */
+    @Override
+    @Transactional
+    public Map<String, Object> execImportRoomCodeLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map) {
+        Long orgId = null;
+        if (Objects.nonNull(map.get("orgId"))) {
+            orgId = Long.parseLong(String.valueOf(map.get("orgId")));
+        }
+        Long examId = null;
+        if (Objects.nonNull(map.get("examId"))) {
+            examId = Long.parseLong(String.valueOf(map.get("examId")));
+        }
+        Long createId = Long.parseLong(String.valueOf(map.get("createId")));
+        List<String> txtList = (List<String>) map.get("txtList");
+        TBTaskHistory tbTaskHistory = (TBTaskHistory) map.get("tbTaskHistory");
+        String timeFormat = String.valueOf(map.get("timeFormat"));
+        //保存用户
+        for (int i = 0; i < finalList.size(); i++) {
+            LinkedMultiValueMap<Integer, Object> finalMap = finalList.get(i);
+            List<Object> examStudentDtoImportList = finalMap.get(i);
+            int min = 0;
+            int y = 0;
+            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 < subList.size(); y++) {
+                    RoomCodeImportDto roomCodeImportDto = (RoomCodeImportDto) subList.get(y);
+                    dataVerify(roomCodeImportDto.getTeacher1(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), orgId, createId);
+                    dataVerify(roomCodeImportDto.getTeacher2(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), orgId, createId);
+                    dataVerify(roomCodeImportDto.getTeacher3(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), orgId, createId);
+                }
+                txtList = this.importProgress(max, min, size, txtList, tbTaskHistory, timeFormat);
+                if (max == size) {
+                    break;
+                }
+                min = max;
+                max += SystemConstant.MAX_IMPORT_SIZE;
+                if (max >= size) {
+                    max = size;
+                }
+            }
+        }
+        return map;
+    }
+
+    /**
+     * 考场导出逻辑
+     *
+     * @param map
+     * @return
+     */
+    @Override
+    @Transactional
+    public Map<String, Object> execExportRoomCodeLogic(Map<String, Object> map) {
+        List<String> txtList = (List<String>) map.get("txtList");
+        TBTaskHistory tbTaskHistory = (TBTaskHistory) map.get("tbTaskHistory");
+        Integer max = Integer.parseInt(String.valueOf(map.get("max")));
+        Integer min = Integer.parseInt(String.valueOf(map.get("min")));
+        Integer size = Integer.parseInt(String.valueOf(map.get("size")));
+        String timeFormat = String.valueOf(map.get("timeFormat"));
+        this.exportProgress(max, min, size, txtList, tbTaskHistory, timeFormat);
+        return map;
+    }
+
+    /**
+     * 查询监考帐号是否存在
+     *
+     * @param userName
+     * @param roomCode
+     * @param roomName
+     * @param orgId
+     * @param createId
+     */
+    public void dataVerify(String userName, String roomCode, String roomName, Long orgId, Long createId) {
+        if (Objects.nonNull(userName)) {
+            //先查询监考帐号是否存在
+            QueryWrapper<TBUser> tbUserQueryWrapper = new QueryWrapper<>();
+            tbUserQueryWrapper.lambda().eq(TBUser::getLoginName, userName).eq(TBUser::getOrgId, orgId);
+            TBUser tbUser = tbUserService.getOne(tbUserQueryWrapper);
+            if (Objects.isNull(tbUser)) {
+                //新增用户
+                tbUser = new TBUser(orgId, userName, userName, createId);
+                tbUserService.save(tbUser);
+
+                TBUserRole tbUserRole = new TBUserRole(tbUser.getId(), RoleEnum.INVIGILATE.name());
+                tbUserRoleService.save(tbUserRole);
+            }
+            //新增考场
+            TBExamInvigilateUser tbExamInvigilateUser = new TBExamInvigilateUser(orgId, tbUser.getId(), roomCode, roomName);
+            tbExamInvigilateUserService.save(tbExamInvigilateUser);
+        }
+    }
+
+    /**
+     * 导入换算进度
+     *
+     * @param max
+     * @param min
+     * @param size
+     * @param txtList
+     * @param tbTaskHistory
+     * @param timeFormat
+     * @return
+     */
+    public List<String> importProgress(int max, int min, int size, List<String> txtList, TBTaskHistory tbTaskHistory, String timeFormat) {
+        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);
+        if (progress.intValue() == 100) {
+            tbTaskHistory.setStatus(TaskStatusEnum.finish);
+            tbTaskHistory.setSummary("共处理了" + size + "条数据");
+            tbTaskHistory.setFinishTime(new Date());
+            txtList.add(DateUtil.format(new Date(), timeFormat) + "->数据处理完毕," + tbTaskHistory.getSummary());
+        } else {
+            tbTaskHistory.setStatus(TaskStatusEnum.running);
+            tbTaskHistory.setSummary("正在处理第" + min + "条至" + max + "条数据");
+            txtList.add(DateUtil.format(new Date(), timeFormat) + "->数据处理中," + tbTaskHistory.getSummary());
+        }
+        tbTaskHistory.setProgress(progress.doubleValue());
+        tbTaskHistoryService.updateById(tbTaskHistory);
+        return txtList;
+    }
+
+    /**
+     * 导出换算进度
+     *
+     * @param max
+     * @param min
+     * @param size
+     * @param txtList
+     * @param tbTaskHistory
+     * @param timeFormat
+     * @return
+     */
+    public List<String> exportProgress(int max, int min, int size, List<String> txtList, TBTaskHistory tbTaskHistory, String timeFormat) {
+        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);
+        if (progress.intValue() == 100) {
+            tbTaskHistory.setStatus(TaskStatusEnum.finish);
+            tbTaskHistory.setSummary("共导出了" + size + "条数据");
+            tbTaskHistory.setFinishTime(new Date());
+            txtList.add(DateUtil.format(new Date(), timeFormat) + "->数据导出完毕," + tbTaskHistory.getSummary());
+        } else {
+            tbTaskHistory.setStatus(TaskStatusEnum.running);
+            tbTaskHistory.setSummary("正在导出第" + min + "条至" + max + "条数据");
+            txtList.add(DateUtil.format(new Date(), timeFormat) + "->数据导出中," + tbTaskHistory.getSummary());
+        }
+        tbTaskHistory.setProgress(progress.doubleValue());
+        tbTaskHistoryService.updateById(tbTaskHistory);
+        return txtList;
+    }
+}