Browse Source

Merge branch 'dev' into release
1

wangliang 4 years ago
parent
commit
945824a2bf

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

@@ -145,47 +145,41 @@ public class TaskExportCommon {
      * @throws IOException
      */
     public void writeExportResultTxt(String path, String txtStr, String excelFilePath) throws IOException {
-        FileWriter fileWriter = null;
+        ByteArrayOutputStream out = null;
+        InputStream inputStream = null;
         try {
-            File file = new File(path + File.separator + String.valueOf(UUID.randomUUID()).replaceAll("-", "")
-                    + SystemConstant.TXT_PREFIX);
-            if (!file.exists()) {
-                file.getParentFile().mkdirs();
-                file.createNewFile();
-            }
-            fileWriter = new FileWriter(file);
-            fileWriter.write(txtStr);
+            out = new ByteArrayOutputStream();
+            out.write(txtStr.getBytes("UTF-8"));
+            byte[] bookByteAry = out.toByteArray();
+            inputStream = new ByteArrayInputStream(bookByteAry);
             JSONObject json = new JSONObject();
-            if (Objects.equals(this.type, SystemConstant.OSS)) {
-                json.put("path", file.getPath().replaceAll("\\\\", "/"));
-            } else {
-                json.put("path", file.getPath());
+            StringJoiner stringJoiner = new StringJoiner("");
+            if (Objects.equals(this.type, SystemConstant.OSS)) {//上传至oss
+                stringJoiner.add(path).add(File.separator).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
+                        .add(SystemConstant.TXT_PREFIX).toString();
+                this.ossUtil.upload(false, stringJoiner.toString(), inputStream, null);
             }
+            json.put("path", stringJoiner.toString());
             json.put("type", this.type);
             json.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.file.ordinal());
             this.tbTaskHistory.setReportFilePath(json.toJSONString());
             if (Objects.nonNull(excelFilePath)) {
                 JSONObject excelJson = new JSONObject();
-                if (Objects.equals(this.type, SystemConstant.OSS)) {
-                    excelJson.put("path", excelFilePath);
-                } else {
-                    excelJson.put("path", excelFilePath);
-                }
+                excelJson.put("path", excelFilePath);
                 excelJson.put("type", this.type);
                 excelJson.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.file.ordinal());
                 this.tbTaskHistory.setResultFilePath(excelJson.toJSONString());
             }
-            if (Objects.equals(this.type, SystemConstant.OSS)) {
-                this.ossUtil.upload(false, file.getPath().replaceAll("\\\\", "/"), txtStr);
-                file.delete();
-            }
             tbTaskHistoryService.updateById(this.tbTaskHistory);
         } catch (IOException e) {
             log.error("请求出错", e);
         } finally {
-            if (Objects.nonNull(fileWriter)) {
-                fileWriter.flush();
-                fileWriter.close();
+            if (Objects.nonNull(inputStream)) {
+                inputStream.close();
+            }
+            if (Objects.nonNull(out)) {
+                out.flush();
+                out.close();
             }
         }
     }

+ 22 - 25
themis-business/src/main/java/com/qmth/themis/business/templete/TaskImportCommon.java

@@ -12,9 +12,7 @@ import com.qmth.themis.business.util.OssUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
+import java.io.*;
 import java.util.*;
 
 /**
@@ -121,39 +119,38 @@ public class TaskImportCommon {
      * @throws IOException
      */
     public void writeImportResultTxt(String txtStr, File excelFile) throws IOException {
-        FileWriter fileWriter = null;
+        ByteArrayOutputStream out = null;
+        InputStream inputStream = null;
         try {
-            if (Objects.equals(this.type, SystemConstant.LOCAL)) {
-                this.path = SystemConstant.FILES_DIR + File.separator + this.path;
-            }
+            out = new ByteArrayOutputStream();
+            out.write(txtStr.getBytes("UTF-8"));
+            byte[] bookByteAry = out.toByteArray();
+            inputStream = new ByteArrayInputStream(bookByteAry);
+            StringJoiner stringJoiner = new StringJoiner("");
             this.path = this.path.substring(0, this.path.lastIndexOf(File.separator) + 1);
-            File file = new File(
-                    this.path + String.valueOf(UUID.randomUUID()).replaceAll("-", "") + SystemConstant.TXT_PREFIX);
-            if (!file.exists()) {
-                file.getParentFile().mkdirs();
-                file.createNewFile();
+            if (Objects.equals(this.type, SystemConstant.OSS)) {//上传至oss
+                stringJoiner.add(path).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
+                        .add(SystemConstant.TXT_PREFIX).toString();
+                this.ossUtil.upload(false, stringJoiner.toString(), inputStream, null);
             }
-            fileWriter = new FileWriter(file);
-            fileWriter.write(txtStr);
             JSONObject json = new JSONObject();
-            json.put("path", file.getPath());
+            json.put("path", stringJoiner.toString());
             json.put("type", this.type);
             json.put(SystemConstant.UPLOAD_TYPE, this.uploadType);
             this.tbTaskHistory.setReportFilePath(json.toJSONString());
-            if (Objects.equals(this.type, SystemConstant.OSS)) {
-                this.ossUtil.upload(false, file.getPath(), txtStr);
-                file.delete();
-                if (Objects.nonNull(excelFile)) {
-                    excelFile.delete();
-                }
-            }
             tbTaskHistoryService.updateById(this.tbTaskHistory);
         } catch (IOException e) {
             log.error("请求出错", e);
         } finally {
-            if (Objects.nonNull(fileWriter)) {
-                fileWriter.flush();
-                fileWriter.close();
+            if (Objects.nonNull(inputStream)) {
+                inputStream.close();
+            }
+            if (Objects.nonNull(out)) {
+                out.flush();
+                out.close();
+            }
+            if (Objects.nonNull(excelFile)) {
+                excelFile.delete();
             }
         }
     }

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

@@ -172,6 +172,8 @@ public class TaskMarkResultSimpleExportTemplete implements TaskExportTemplete {
             log.error("导出报错", e);
             taskExportCommon.exception(min, y, e, taskExportCommon.getTxtList());
         } finally {
+            //这里写入txt文件
+            taskExportCommon.writeExportResultTxt(stringJoiner.toString(), taskExportCommon.getTxtList().toString(), excelFilePath);
             if (Objects.nonNull(wb)) {
                 wb.dispose();
             }
@@ -182,8 +184,6 @@ public class TaskMarkResultSimpleExportTemplete implements TaskExportTemplete {
                 out.flush();
                 out.close();
             }
-            //这里写入txt文件
-            taskExportCommon.writeExportResultTxt(stringJoiner.toString(), taskExportCommon.getTxtList().toString(), excelFilePath);
         }
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
     }

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

@@ -283,6 +283,8 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
             log.error("导出报错", e);
             taskExportCommon.exception(min, y, e, taskExportCommon.getTxtList());
         } finally {
+            //这里写入txt文件
+            taskExportCommon.writeExportResultTxt(stringJoiner.toString(), taskExportCommon.getTxtList().toString(), excelFilePath);
             if (Objects.nonNull(wb)) {
                 wb.dispose();
             }
@@ -293,8 +295,6 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
                 out.flush();
                 out.close();
             }
-            //这里写入txt文件
-            taskExportCommon.writeExportResultTxt(stringJoiner.toString(), taskExportCommon.getTxtList().toString(), excelFilePath);
         }
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
     }

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

@@ -135,6 +135,8 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
             log.error("导出报错", e);
             taskExportCommon.exception(min, y, e, taskExportCommon.getTxtList());
         } finally {
+            //这里写入txt文件
+            taskExportCommon.writeExportResultTxt(stringJoiner.toString(), taskExportCommon.getTxtList().toString(), excelFilePath);
             if (Objects.nonNull(wb)) {
                 wb.dispose();
             }
@@ -145,8 +147,6 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
                 out.flush();
                 out.close();
             }
-            //这里写入txt文件
-            taskExportCommon.writeExportResultTxt(stringJoiner.toString(), taskExportCommon.getTxtList().toString(), excelFilePath);
         }
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
     }

+ 0 - 6
themis-exam/src/main/java/com/qmth/themis/exam/interceptor/AuthInterceptor.java

@@ -77,10 +77,6 @@ public class AuthInterceptor implements HandlerInterceptor {
                 if (Objects.isNull(tbSession)) {
                     throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
                 } else {
-                    log.info("info.validate(tbSession.getAccessToken():{}", info.validate(tbSession.getAccessToken()));
-                    log.info("info.getTimestamp() < tbSession.getExpireTime():{}", info.getTimestamp() < tbSession.getExpireTime());
-                    log.info("platform.name().equalsIgnoreCase(tbSession.getPlatform()):{}", platform.name().equalsIgnoreCase(tbSession.getPlatform()));
-                    log.info("Objects.equals(deviceId, tbSession.getDeviceId()):{}", Objects.equals(deviceId, tbSession.getDeviceId()));
                     if (info.validate(tbSession.getAccessToken()) && info.getTimestamp() < tbSession.getExpireTime()
                             && platform.name().equalsIgnoreCase(tbSession.getPlatform()) && Objects.equals(deviceId, tbSession.getDeviceId())) {
                         userId = Long.parseLong(tbSession.getIdentity());
@@ -130,11 +126,9 @@ public class AuthInterceptor implements HandlerInterceptor {
                     }
                 }
             } else {
-                log.info("SignatureInfo info is null");
                 throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
             }
         } else {
-            log.info("SystemConstant.expire(timestamp.longValue()):{}", SystemConstant.expire(timestamp.longValue()));
             throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
         }
         response.setStatus(ExceptionResultEnum.SUCCESS.getCode());