wangliang преди 4 години
родител
ревизия
f937e561f1

+ 1 - 0
themis-backend/src/main/java/com/qmth/themis/backend/api/TEExamStudentController.java

@@ -200,6 +200,7 @@ public class TEExamStudentController {
             }
             transMap.put("mode", teExam.getMode());
             transMap.put("orgId", teExam.getOrgId());
+            transMap.put("examCount", teExam.getExamCount());
 
             //获取该批次下的所有考场,校验考场id是否存在
             QueryWrapper<TEExamActivity> teExamActivityQueryWrapper = new QueryWrapper<>();

+ 15 - 2
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentImportTemplete.java

@@ -4,7 +4,9 @@ import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.qmth.themis.business.dto.ExamStudentImportDto;
+import com.qmth.themis.business.entity.TEExamActivity;
 import com.qmth.themis.business.enums.ExamModeEnum;
+import com.qmth.themis.business.enums.TaskStatusEnum;
 import com.qmth.themis.business.templete.TaskImportCommon;
 import com.qmth.themis.business.templete.TaskImportTemplete;
 import com.qmth.themis.business.templete.service.TempleteLogicService;
@@ -58,6 +60,7 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
         String timeFormat = taskImportCommon.getTimeFormat();
         taskImportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导入的考生数据");
         Map<String, Object> finalMap = map;
+        Map<String, TEExamActivity> teExamActivityMap = (Map<String, TEExamActivity>) map.get("teExamActivityMap");
         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 {
@@ -74,14 +77,24 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
                             excelErrorList.addAll(excelErrorTemp);
                         }
                         //校验考试模式,如果是集中统一,则需填写考试场次
-                        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 (Objects.equals(taskImportCommon.getMode(), ExamModeEnum.TOGETHER.name())) {
+                            if (Objects.isNull(examStudentImportDto.getExamActivityCode())) {
+                                excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[场次]为空"));
+                            } else {
+                                if (Objects.nonNull(teExamActivityMap) && Objects.isNull(teExamActivityMap.get(examStudentImportDto.getExamActivityCode()))) {
+                                    excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[场次]不存在"));
+                                }
+                            }
                         }
                     }
                 }
                 if (excelErrorList.size() > 0) {
                     taskImportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->数据校验异常:" + JSONObject.toJSONString(excelErrorList));
                     taskImportCommon.setException(true);
+                    taskImportCommon.getTbTaskHistory().setFinishTime(new Date());
+                    taskImportCommon.getTbTaskHistory().setProgress(0d);
+                    taskImportCommon.getTbTaskHistory().setStatus(TaskStatusEnum.FINISH);
+                    taskImportCommon.getTbTaskHistory().setSummary(taskImportCommon.getTxtList().toString());
                     taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString(), file);
                     throw new BusinessException(JSONObject.toJSONString(excelErrorList));
                 }

+ 5 - 0
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskRoomCodeImportTemplete.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.qmth.themis.business.dto.RoomCodeImportDto;
+import com.qmth.themis.business.enums.TaskStatusEnum;
 import com.qmth.themis.business.templete.TaskImportCommon;
 import com.qmth.themis.business.templete.TaskImportTemplete;
 import com.qmth.themis.business.templete.service.TempleteLogicService;
@@ -72,6 +73,10 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
                 if (excelErrorList.size() > 0) {
                     taskImportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->数据校验异常:" + JSONObject.toJSONString(excelErrorList));
                     taskImportCommon.setException(true);
+                    taskImportCommon.getTbTaskHistory().setFinishTime(new Date());
+                    taskImportCommon.getTbTaskHistory().setProgress(0d);
+                    taskImportCommon.getTbTaskHistory().setStatus(TaskStatusEnum.FINISH);
+                    taskImportCommon.getTbTaskHistory().setSummary(taskImportCommon.getTxtList().toString());
                     taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString(), file);
                     throw new BusinessException(JSONObject.toJSONString(excelErrorList));
                 }

+ 22 - 10
themis-business/src/main/java/com/qmth/themis/business/templete/service/impl/TempleteLogicServiceImpl.java

@@ -8,6 +8,7 @@ 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.ExamModeEnum;
 import com.qmth.themis.business.enums.RoleEnum;
 import com.qmth.themis.business.enums.TaskStatusEnum;
 import com.qmth.themis.business.service.*;
@@ -87,6 +88,7 @@ public class TempleteLogicServiceImpl implements TempleteLogicService {
         Set<String> courseCodeSet = courseCodeMap.keySet().stream().collect(Collectors.toSet());
         teExamCourseQueryWrapper.lambda().in(TEExamCourse::getCourseCode, courseCodeSet);
         List<TEExamCourse> teExamCourseList = teExamCourseService.list(teExamCourseQueryWrapper);
+        Integer examCount = Integer.parseInt(String.valueOf(map.get("examCount")));
         if (Objects.nonNull(teExamCourseList) && teExamCourseList.size() > 0) {
             teExamCourseList.forEach(s -> {
                 courseCodeMap.remove(s.getCourseCode());
@@ -100,7 +102,17 @@ public class TempleteLogicServiceImpl implements TempleteLogicService {
         if (teExamCourses.size() > 0) {
             teExamCourseService.saveBatch(teExamCourses);
         }
-
+        TEExamActivity teExamActivity = null;
+        ExamModeEnum modeEnum = ExamModeEnum.valueOf(String.valueOf(map.get("mode")));
+        if (Objects.equals(modeEnum, ExamModeEnum.ANYTIME)) {
+            Iterator iterator = teExamActivityMap.entrySet().iterator();
+            while (iterator.hasNext()) {
+                Map.Entry<String, Map> entry = (Map.Entry<String, Map>) iterator.next();
+                Map m = entry.getValue();
+                m = SystemConstant.timeTransform(m);
+                teExamActivity = gson.fromJson(gson.toJson(m), TEExamActivity.class);
+            }
+        }
         //保存用户
         for (int i = 0; i < finalList.size(); i++) {
             LinkedMultiValueMap<Integer, Object> finalMap = finalList.get(i);
@@ -115,9 +127,11 @@ public class TempleteLogicServiceImpl implements TempleteLogicService {
                 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);
+                    if (Objects.equals(modeEnum, ExamModeEnum.TOGETHER)) {
+                        Map m = (Map) teExamActivityMap.get(examStudentImportDto.getExamActivityCode());
+                        m = SystemConstant.timeTransform(m);
+                        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());
@@ -135,13 +149,12 @@ public class TempleteLogicServiceImpl implements TempleteLogicService {
                         }
                         teExamStudent = gson.fromJson(gson.toJson(examStudentImportDto), TEExamStudent.class);
                         teExamStudent.setExamId(examId);
-                        if (Objects.nonNull(teExamActivity)) {
-                            teExamStudent.setExamActivityId(teExamActivity.getId());
-                        }
+                        teExamStudent.setExamActivityId(teExamActivity.getId());
                         teExamStudent.setStudentId(teStudent.getId());
                         teExamStudent.setCreateId(createId);
                         teExamStudent.setCourseCode(examStudentImportDto.getCourseCode());
                         teExamStudent.setCourseName(examStudentImportDto.getCourseName());
+                        teExamStudent.setLeftExamCount(examCount);
                     } else {
                         teExamStudent.setUpdateId(createId);
                         teExamStudent.setName(examStudentImportDto.getName());
@@ -152,9 +165,8 @@ public class TempleteLogicServiceImpl implements TempleteLogicService {
                         teExamStudent.setRoomName(examStudentImportDto.getRoomName());
                         teExamStudent.setCourseCode(examStudentImportDto.getCourseCode());
                         teExamStudent.setCourseName(examStudentImportDto.getCourseName());
-                        if (Objects.nonNull(teExamActivity)) {
-                            teExamStudent.setExamActivityId(teExamActivity.getId());
-                        }
+                        teExamStudent.setExamActivityId(teExamActivity.getId());
+                        teExamStudent.setLeftExamCount(examCount);
                     }
                     teExamStudentService.saveOrUpdate(teExamStudent);
                     roomCodeAndNameSet.add(teExamStudent.getRoomCode() + ":" + teExamStudent.getRoomName());