Ver código fonte

Merge branch 'dev' into release

wangliang 4 anos atrás
pai
commit
1586d62b1f

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

@@ -75,6 +75,10 @@ public class AuthInterceptor implements HandlerInterceptor {
                 if (Objects.isNull(tbSession)) {
                     throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
                 } else {
+                    log.error("info.validate(tbSession.getAccessToken():{}", info.validate(tbSession.getAccessToken()));
+                    log.error("info.getTimestamp() < tbSession.getExpireTime():{}", info.getTimestamp() < tbSession.getExpireTime());
+                    log.error("platform.name().equalsIgnoreCase(tbSession.getPlatform()):{}", platform.name().equalsIgnoreCase(tbSession.getPlatform()));
+                    log.error("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());
@@ -122,9 +126,11 @@ public class AuthInterceptor implements HandlerInterceptor {
                     }
                 }
             } else {
+                log.error("SignatureInfo info is null");
                 throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
             }
         } else {
+            log.error("SystemConstant.expire(timestamp.longValue())", SystemConstant.expire(timestamp.longValue()));
             throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
         }
         response.setStatus(ExceptionResultEnum.SUCCESS.getCode());

+ 34 - 28
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentExportTemplete.java

@@ -1,5 +1,24 @@
 package com.qmth.themis.business.templete.impl;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.StringJoiner;
+
+import javax.annotation.Resource;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.response.TEExamStudentDto;
 import com.qmth.themis.business.enums.TaskStatusEnum;
@@ -9,17 +28,6 @@ import com.qmth.themis.business.templete.TaskExportCommon;
 import com.qmth.themis.business.templete.TaskExportTemplete;
 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.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.time.LocalDateTime;
-import java.util.*;
 
 /**
  * @Description: 考场导出任务
@@ -31,7 +39,7 @@ import java.util.*;
 @Service
 public class TaskExamStudentExportTemplete implements TaskExportTemplete {
     private final static Logger log = LoggerFactory.getLogger(TaskExamStudentExportTemplete.class);
-
+    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
     @Resource
     TEExamStudentService teExamStudentService;
 
@@ -47,8 +55,8 @@ public class TaskExamStudentExportTemplete implements TaskExportTemplete {
         long start = System.currentTimeMillis();
         TaskExportCommon taskExportCommon = new TaskExportCommon(transMap);
         taskExportCommon.init();
-        FileOutputStream fos = null;
-        File file = null;
+        ByteArrayOutputStream fos = null;
+        InputStream inputStream = null;
         StringJoiner stringJoiner = null;
         String excelFilePath = null;
         boolean oss = (boolean) taskExportCommon.getOssEnv().get(SystemConstant.OSS);
@@ -57,13 +65,8 @@ public class TaskExamStudentExportTemplete implements TaskExportTemplete {
             if (!oss) {
                 stringJoiner.add(SystemConstant.FILES_DIR).add(File.separator);
             }
-            LocalDateTime nowTime = LocalDateTime.now();
-            stringJoiner.add(String.valueOf(nowTime.getYear()))
-                    .add(File.separator).add(String.format("%02d", nowTime.getMonthValue()))
-                    .add(File.separator).add(String.format("%02d", nowTime.getDayOfMonth()));
-            file = new File(SystemConstant.TEMP_FILES_DIR + "/" + uuid() + SystemConstant.EXCEL_PREFIX);
-            file.createNewFile();
-            fos = new FileOutputStream(file);
+            stringJoiner.add(sdf.format(new Date()));
+            fos = new ByteArrayOutputStream();
             Long examId = (Long) transMap.get("examId");
             Long activityId = (Long) transMap.get("activityId");
             String identity = (String) transMap.get("identity");
@@ -77,7 +80,8 @@ public class TaskExamStudentExportTemplete implements TaskExportTemplete {
             List<TEExamStudentDto> list = teExamStudentService.examStudentList(examId, activityId, identity, name, roomCode, courseCode, grade,
                     enable, classNo, hasPhoto);
             ExportUtils.makeExcel(TEExamStudentDto.class, list, fos);
-            excelFilePath = taskExportCommon.ossUpload(new FileInputStream(file), stringJoiner.toString());
+            inputStream = new ByteArrayInputStream(fos.toByteArray());
+            excelFilePath = taskExportCommon.ossUpload(inputStream, stringJoiner.toString());
             taskExportCommon.getTbTaskHistory().setSummary("处理成功");
             long end = System.currentTimeMillis();
             log.info("导出考生数据结束,============耗时============:{}秒", (end - start) / 1000);
@@ -86,19 +90,21 @@ public class TaskExamStudentExportTemplete implements TaskExportTemplete {
             taskExportCommon.setException(true);
             taskExportCommon.getTbTaskHistory().setSummary("处理出错");
         } finally {
-            if (oss && file != null) {
-                file.delete();
-            }
+        	
             taskExportCommon.getTbTaskHistory().setFinishTime(System.currentTimeMillis());
             taskExportCommon.getTbTaskHistory().setStatus(TaskStatusEnum.FINISH);
             taskExportCommon.getTbTaskHistory().setProgress(100.0d);
             //这里写入txt文件
             taskExportCommon.writeExportResultTxt(stringJoiner.toString(), "", excelFilePath);
+            if (Objects.nonNull(fos)) {
+        		fos.flush();
+        		fos.close();
+        	}
+        	if (Objects.nonNull(inputStream)) {
+                inputStream.close();
+            }
         }
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
     }
 
-    private String uuid() {
-        return UUID.randomUUID().toString().replaceAll("-", "");
-    }
 }

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

@@ -77,6 +77,10 @@ public class AuthInterceptor implements HandlerInterceptor {
                 if (Objects.isNull(tbSession)) {
                     throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
                 } else {
+                    log.error("info.validate(tbSession.getAccessToken():{}", info.validate(tbSession.getAccessToken()));
+                    log.error("info.getTimestamp() < tbSession.getExpireTime():{}", info.getTimestamp() < tbSession.getExpireTime());
+                    log.error("platform.name().equalsIgnoreCase(tbSession.getPlatform()):{}", platform.name().equalsIgnoreCase(tbSession.getPlatform()));
+                    log.error("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());
@@ -126,9 +130,11 @@ public class AuthInterceptor implements HandlerInterceptor {
                     }
                 }
             } else {
+                log.error("SignatureInfo info is null");
                 throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
             }
         } else {
+            log.error("SystemConstant.expire(timestamp.longValue())", SystemConstant.expire(timestamp.longValue()));
             throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
         }
         response.setStatus(ExceptionResultEnum.SUCCESS.getCode());