wangliang преди 5 години
родител
ревизия
2c148995a7

+ 21 - 19
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -143,25 +143,27 @@ public class SystemConstant {
      * @return
      */
     public static Map timeTransform(Map map) {
-        if (Objects.nonNull(map.get("createTime")) && map.get("createTime") instanceof Long) {
-            Date date = new Date();
-            date.setTime(Long.parseLong(String.valueOf(map.get("createTime"))));
-            map.put("createTime", date);
-        }
-        if (Objects.nonNull(map.get("startTime")) && map.get("startTime") instanceof Long) {
-            Date date = new Date();
-            date.setTime(Long.parseLong(String.valueOf(map.get("startTime"))));
-            map.put("startTime", date);
-        }
-        if (Objects.nonNull(map.get("finishTime")) && map.get("finishTime") instanceof Long) {
-            Date date = new Date();
-            date.setTime(Long.parseLong(String.valueOf(map.get("finishTime"))));
-            map.put("finishTime", date);
-        }
-        if (Objects.nonNull(map.get("updateTime")) && map.get("updateTime") instanceof Long) {
-            Date date = new Date();
-            date.setTime(Long.parseLong(String.valueOf(map.get("updateTime"))));
-            map.put("updateTime", date);
+        if (Objects.nonNull(map)) {
+            if (Objects.nonNull(map.get("createTime")) && map.get("createTime") instanceof Long) {
+                Date date = new Date();
+                date.setTime(Long.parseLong(String.valueOf(map.get("createTime"))));
+                map.put("createTime", date);
+            }
+            if (Objects.nonNull(map.get("startTime")) && map.get("startTime") instanceof Long) {
+                Date date = new Date();
+                date.setTime(Long.parseLong(String.valueOf(map.get("startTime"))));
+                map.put("startTime", date);
+            }
+            if (Objects.nonNull(map.get("finishTime")) && map.get("finishTime") instanceof Long) {
+                Date date = new Date();
+                date.setTime(Long.parseLong(String.valueOf(map.get("finishTime"))));
+                map.put("finishTime", date);
+            }
+            if (Objects.nonNull(map.get("updateTime")) && map.get("updateTime") instanceof Long) {
+                Date date = new Date();
+                date.setTime(Long.parseLong(String.valueOf(map.get("updateTime"))));
+                map.put("updateTime", date);
+            }
         }
         return map;
     }

+ 12 - 12
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentTemplete.java

@@ -94,7 +94,8 @@ public class TaskExamStudentTemplete implements TaskImportTemplete {
             }
         });
         boolean exception = false;
-        String timeFormat = "yyyy-MM-dd HH:mm:ss:sss";
+//        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("开始导入考生数据");
@@ -107,9 +108,9 @@ public class TaskExamStudentTemplete implements TaskImportTemplete {
             List<TEStudent> teStudentList = new ArrayList<>();
             List<TBUserRole> tbUserRoleList = new ArrayList<>();
             List<TBExamInvigilateUser> tbExamInvigilateUserList = new ArrayList<>();
-            JSONObject jsonObject = new JSONObject(new LinkedHashMap<>());
+            List txtList = new ArrayList();
             TBTaskHistory tbTaskHistory = null;
-            jsonObject.put(DateUtil.format(new Date(), timeFormat), "开始准备处理导入的考生数据");
+            txtList.add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导入的考生数据");
             int y = 0, min = 0;
             try {
                 Gson gson = new Gson();
@@ -179,11 +180,11 @@ public class TaskExamStudentTemplete implements TaskImportTemplete {
                             tbTaskHistory.setStatus(TaskTypeExecEnum.finish.ordinal());
                             tbTaskHistory.setSummary("共处理了" + size + "条数据");
                             tbTaskHistory.setFinishTime(new Date());
-                            jsonObject.put(DateUtil.format(new Date(), timeFormat), "考生数据处理完毕," + tbTaskHistory.getSummary());
+                            txtList.add(DateUtil.format(new Date(), timeFormat) + "->考生数据处理完毕," + tbTaskHistory.getSummary());
                         } else {
                             tbTaskHistory.setStatus(TaskTypeExecEnum.running.ordinal());
                             tbTaskHistory.setSummary("正在处理第" + min + "条至" + max + "条数据");
-                            jsonObject.put(DateUtil.format(new Date(), timeFormat), "考生数据处理中," + tbTaskHistory.getSummary());
+                            txtList.add(DateUtil.format(new Date(), timeFormat) + "->考生数据处理中," + tbTaskHistory.getSummary());
                         }
                         tbTaskHistory.setProgress(progress.doubleValue());
                         tbTaskHistoryService.updateById(tbTaskHistory);
@@ -211,7 +212,7 @@ public class TaskExamStudentTemplete implements TaskImportTemplete {
                         }
                     });
                     if (count.get() > 0) {
-                        jsonObject.put(DateUtil.format(new Date(), timeFormat), "创建了" + count + "条考场数据");
+                        txtList.add(DateUtil.format(new Date(), timeFormat) + "->创建了" + count + "条考场数据");
                     }
                 }
                 long end = System.currentTimeMillis();
@@ -220,7 +221,7 @@ public class TaskExamStudentTemplete implements TaskImportTemplete {
                 e.printStackTrace();
                 exception = true;
                 String exceptionStr = "考生数据处理到第" + (min + y + 1) + "条时发生异常:" + e.getMessage();
-                jsonObject.put(DateUtil.format(new Date(), timeFormat), exceptionStr);
+                txtList.add(DateUtil.format(new Date(), timeFormat) + "->" + exceptionStr);
                 tbTaskHistory.setSummary(exceptionStr);
                 tbTaskHistoryService.updateById(tbTaskHistory);
                 if (Objects.nonNull(teStudentList) && teStudentList.size() > 0) {
@@ -242,8 +243,7 @@ public class TaskExamStudentTemplete implements TaskImportTemplete {
                 }
             } finally {
                 //这里写入txt文件
-                log.info("jsonObject:{}", jsonObject.toJSONString());
-                writeImportResultTxt(exception, ossUtil, tbTaskHistoryService, tbTaskHistory, jsonObject, path, type, ossEnv);
+                writeImportResultTxt(exception, ossUtil, tbTaskHistoryService, tbTaskHistory, txtList.toString(), path, type, ossEnv);
             }
         }
         return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
@@ -287,7 +287,7 @@ public class TaskExamStudentTemplete implements TaskImportTemplete {
      * @param ossEnv
      * @throws IOException
      */
-    void writeImportResultTxt(boolean exception, OssUtil ossUtil, TBTaskHistoryService tbTaskHistoryService, TBTaskHistory tbTaskHistory, JSONObject jsonObject, String path, String type, Map<String, Object> 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);
@@ -296,7 +296,7 @@ public class TaskExamStudentTemplete implements TaskImportTemplete {
                 file.createNewFile();
             }
             fileWriter = new FileWriter(file);
-            fileWriter.write(jsonObject.toJSONString());
+            fileWriter.write(txtStr);
             JSONObject json = new JSONObject();
             json.put("path", file.getPath());
             json.put("type", type);
@@ -306,7 +306,7 @@ public class TaskExamStudentTemplete implements TaskImportTemplete {
                 tbTaskHistory.setResultFilePath(json.toJSONString());
             }
             if (Objects.equals(type, SystemConstant.OSS)) {
-                ossUtil.ossUpload(ossEnv, file.getPath(), jsonObject.toJSONString());
+                ossUtil.ossUpload(ossEnv, file.getPath(), txtStr);
                 file.delete();
             }
             tbTaskHistoryService.updateById(tbTaskHistory);

+ 1 - 0
themis-business/src/main/java/com/qmth/themis/business/util/ExcelUtil.java

@@ -105,6 +105,7 @@ public class ExcelUtil {
                     finalOList.add(oList);
                     finalColumnNameList.add(columnNameList);
                 }
+                log.info("读取了{}条数据", oList.get(0).size());
             }
             long end = System.currentTimeMillis();
             log.info("读取excel里的数据结束,============耗时============:{}秒", (end - start) / 1000);