wangliang 4 năm trước cách đây
mục cha
commit
0209d9cb61

+ 50 - 49
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentImportTemplete.java

@@ -62,64 +62,65 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
         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 {
-                Map<String, String> courseCodeMap = new HashMap<>();
-                List<ExcelError> excelErrorList = new ArrayList<>();
-                for (int i = 0; i < finalList.size(); i++) {
-                    LinkedMultiValueMap<Integer, Object> map = finalList.get(i);
-                    List<Object> examStudentImportDtoList = map.get(i);
-                    for (int y = 0; y < examStudentImportDtoList.size(); y++) {
-                        ExamStudentImportDto examStudentImportDto = (ExamStudentImportDto) examStudentImportDtoList.get(y);
-                        courseCodeMap.put(examStudentImportDto.getCourseCode(), examStudentImportDto.getCourseName());
-                        List<ExcelError> excelErrorTemp = ExcelUtil.checkExcelField(examStudentImportDto, y, i);
-                        if (excelErrorTemp.size() > 0) {
-                            excelErrorList.addAll(excelErrorTemp);
-                        }
-                        //校验考试模式,如果是集中统一,则需填写考试场次
-                        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) + "行[场次]不存在"));
+        try {
+            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 {
+                    Map<String, String> courseCodeMap = new HashMap<>();
+                    List<ExcelError> excelErrorList = new ArrayList<>();
+                    for (int i = 0; i < finalList.size(); i++) {
+                        LinkedMultiValueMap<Integer, Object> map = finalList.get(i);
+                        List<Object> examStudentImportDtoList = map.get(i);
+                        for (int y = 0; y < examStudentImportDtoList.size(); y++) {
+                            ExamStudentImportDto examStudentImportDto = (ExamStudentImportDto) examStudentImportDtoList.get(y);
+                            courseCodeMap.put(examStudentImportDto.getCourseCode(), examStudentImportDto.getCourseName());
+                            List<ExcelError> excelErrorTemp = ExcelUtil.checkExcelField(examStudentImportDto, y, i);
+                            if (excelErrorTemp.size() > 0) {
+                                excelErrorList.addAll(excelErrorTemp);
+                            }
+                            //校验考试模式,如果是集中统一,则需填写考试场次
+                            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(System.currentTimeMillis());
+                        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));
+                    }
+                    finalMap.put("courseCodeMap", courseCodeMap);
+                    return finalList;
                 }
-                if (excelErrorList.size() > 0) {
-                    taskImportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->数据校验异常:" + JSONObject.toJSONString(excelErrorList));
-                    taskImportCommon.setException(true);
-                    taskImportCommon.getTbTaskHistory().setFinishTime(System.currentTimeMillis());
-                    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));
-                }
-                finalMap.put("courseCodeMap", courseCodeMap);
-                return finalList;
-            }
-        });
-        //保存数据到数据库
-        if (Objects.nonNull(finalList) && finalList.size() > 0) {
-            log.info("开始导入考生数据");
-            long start = System.currentTimeMillis();
-            try {
+            });
+            //保存数据到数据库
+            if (Objects.nonNull(finalList) && finalList.size() > 0) {
+                log.info("开始导入考生数据");
+                long start = System.currentTimeMillis();
+
                 map = templeteLogicService.execImportExamStudentLogic(finalList, map);
                 long end = System.currentTimeMillis();
                 log.info("导入考生数据结束,============耗时============:{}秒", (end - start) / 1000);
-            } catch (Exception e) {
-                log.error("导入报错", 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(taskImportCommon.getTxtList().toString(), file);
             }
+        } catch (Exception e) {
+            log.error("导入报错", 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(taskImportCommon.getTxtList().toString(), file);
         }
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
     }

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

@@ -56,51 +56,51 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
         taskImportCommon.setTxtList(new ArrayList());
         String timeFormat = taskImportCommon.getTimeFormat();
         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 {
-                List<ExcelError> excelErrorList = new ArrayList<>();
-                for (int i = 0; i < finalList.size(); i++) {
-                    LinkedMultiValueMap<Integer, Object> map = finalList.get(i);
-                    List<Object> roomCodeImportDtoList = map.get(i);
-                    for (int y = 0; y < roomCodeImportDtoList.size(); y++) {
-                        RoomCodeImportDto roomCodeImportDto = (RoomCodeImportDto) roomCodeImportDtoList.get(y);
-                        List<ExcelError> excelErrorTemp = ExcelUtil.checkExcelField(roomCodeImportDto, y, i);
-                        if (excelErrorTemp.size() > 0) {
-                            excelErrorList.addAll(excelErrorTemp);
+        try {
+            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 {
+                    List<ExcelError> excelErrorList = new ArrayList<>();
+                    for (int i = 0; i < finalList.size(); i++) {
+                        LinkedMultiValueMap<Integer, Object> map = finalList.get(i);
+                        List<Object> roomCodeImportDtoList = map.get(i);
+                        for (int y = 0; y < roomCodeImportDtoList.size(); y++) {
+                            RoomCodeImportDto roomCodeImportDto = (RoomCodeImportDto) roomCodeImportDtoList.get(y);
+                            List<ExcelError> excelErrorTemp = ExcelUtil.checkExcelField(roomCodeImportDto, y, i);
+                            if (excelErrorTemp.size() > 0) {
+                                excelErrorList.addAll(excelErrorTemp);
+                            }
                         }
                     }
+                    if (excelErrorList.size() > 0) {
+                        taskImportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->数据校验异常:" + JSONObject.toJSONString(excelErrorList));
+                        taskImportCommon.setException(true);
+                        taskImportCommon.getTbTaskHistory().setFinishTime(System.currentTimeMillis());
+                        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));
+                    }
+                    return finalList;
                 }
-                if (excelErrorList.size() > 0) {
-                    taskImportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->数据校验异常:" + JSONObject.toJSONString(excelErrorList));
-                    taskImportCommon.setException(true);
-                    taskImportCommon.getTbTaskHistory().setFinishTime(System.currentTimeMillis());
-                    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));
-                }
-                return finalList;
-            }
-        });
-        //保存数据到数据库
-        if (Objects.nonNull(finalList) && finalList.size() > 0) {
-            log.info("开始导入考场数据");
-            long start = System.currentTimeMillis();
-            try {
+            });
+            //保存数据到数据库
+            if (Objects.nonNull(finalList) && finalList.size() > 0) {
+                log.info("开始导入考场数据");
+                long start = System.currentTimeMillis();
                 map = templeteLogicService.execImportRoomCodeLogic(finalList, map);
                 long end = System.currentTimeMillis();
                 log.info("导入考场数据结束,============耗时============:{}秒", (end - start) / 1000);
-            } catch (Exception e) {
-                log.error("导入报错", 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(taskImportCommon.getTxtList().toString(), file);
             }
+        } catch (Exception e) {
+            log.error("导入报错", 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(taskImportCommon.getTxtList().toString(), file);
         }
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
     }