Ver Fonte

mq修改

wangliang há 4 anos atrás
pai
commit
b39a9569ee

+ 2 - 2
themis-backend/src/main/java/com/qmth/themis/backend/aspect/ApiControllerAspect.java

@@ -58,8 +58,8 @@ public class ApiControllerAspect {
 //            log.info("============参数key:{},参数value===========:{}", JSONObject.toJSONString(paramsName), JSONObject.toJSONString(args));
             log.info("============platform===========:{}", ServletUtil.getRequestPlatform());
             log.info("============deviceId===========:{}", ServletUtil.getRequestDeviceId());
-            log.info("============Authorization===========:{}", ServletUtil.getRequestAuthorization());
-            log.info("============time===========:{}", ServletUtil.getRequestTime());
+            log.info("============Authorization===========:{}", ServletUtil.getRequestAuthorizationForAspect());
+            log.info("============time===========:{}", ServletUtil.getRequestTimeForTime());
             Object proceed = joinPoint.proceed();
             long end = System.currentTimeMillis();
             log.info("============耗时============:{}秒", (end - start) / 1000);

+ 46 - 0
themis-backend/src/main/java/com/qmth/themis/backend/util/ServletUtil.java

@@ -3,6 +3,8 @@ package com.qmth.themis.backend.util;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.util.JacksonUtil;
 import com.qmth.themis.common.contanst.Constants;
+import com.qmth.themis.common.enums.ExceptionResultEnum;
+import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import org.springframework.web.context.request.RequestContextHolder;
@@ -63,6 +65,9 @@ public class ServletUtil {
         // 如果header中不存在platform,则从参数中获取platform
         if (Objects.isNull(platform)) {
             platform = request.getParameter(Constants.HEADER_PLATFORM);
+            if (Objects.isNull(platform)) {
+                throw new BusinessException(ExceptionResultEnum.PLATFORM_IS_NULL);
+            }
         }
         return platform;
     }
@@ -79,6 +84,9 @@ public class ServletUtil {
         // 如果header中不存在deviceId,则从参数中获取deviceId
         if (Objects.isNull(deviceId)) {
             deviceId = request.getParameter(Constants.HEADER_DEVICE_ID);
+            if (Objects.isNull(deviceId)) {
+                throw new BusinessException(ExceptionResultEnum.DEVICE_ID_IS_NULL);
+            }
         }
         return deviceId;
     }
@@ -95,6 +103,9 @@ public class ServletUtil {
         // 如果header中不存在time,则从参数中获取time
         if (Objects.isNull(time)) {
             time = request.getParameter(Constants.HEADER_TIME);
+            if (Objects.isNull(time)) {
+                throw new BusinessException(ExceptionResultEnum.TIME_IS_NULL);
+            }
         }
         return time;
     }
@@ -111,10 +122,45 @@ public class ServletUtil {
         // 如果header中不存在authorization,则从参数中获取authorization
         if (Objects.isNull(authorization)) {
             authorization = request.getParameter(Constants.HEADER_AUTHORIZATION);
+            if (Objects.isNull(authorization)) {
+                throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_IS_NULL);
+            }
         }
         return authorization;
     }
 
+    /**
+     * 获取请求的Authorization
+     *
+     * @return
+     */
+    public static String getRequestAuthorizationForAspect() {
+        HttpServletRequest request = getRequest();
+        // 从header中获取authorization
+        String authorization = request.getHeader(Constants.HEADER_AUTHORIZATION);
+        // 如果header中不存在authorization,则从参数中获取authorization
+        if (Objects.isNull(authorization)) {
+            authorization = request.getParameter(Constants.HEADER_AUTHORIZATION);
+        }
+        return authorization;
+    }
+
+    /**
+     * 获取请求的time
+     *
+     * @return
+     */
+    public static String getRequestTimeForTime() {
+        HttpServletRequest request = getRequest();
+        // 从header中获取time
+        String time = request.getHeader(Constants.HEADER_TIME);
+        // 如果header中不存在time,则从参数中获取time
+        if (Objects.isNull(time)) {
+            time = request.getParameter(Constants.HEADER_TIME);
+        }
+        return time;
+    }
+
     /**
      * 获取请求的md5
      *

+ 9 - 1
themis-common/src/main/java/com/qmth/themis/common/enums/ExceptionResultEnum.java

@@ -158,7 +158,15 @@ public enum ExceptionResultEnum {
 
     AUTHORIZATION_SESSION_ERROR("401", "sessionId验证失败"),
 	
-    REQUEST_AWAIT("500", "请求等待:请稍后重试");
+    REQUEST_AWAIT("500", "请求等待:请稍后重试"),
+
+    PLATFORM_IS_NULL("500","platform不能为空"),
+
+    DEVICE_ID_IS_NULL("500","deviceId不能为空"),
+
+    TIME_IS_NULL("500","time不能为空"),
+
+    AUTHORIZATION_IS_NULL("500","authorization不能为空");
 
     private String code;
     private String message;

+ 2 - 2
themis-exam/src/main/java/com/qmth/themis/exam/aspect/ApiControllerAspect.java

@@ -58,8 +58,8 @@ public class ApiControllerAspect {
 //            log.info("============参数key:{},参数value===========:{}", JSONObject.toJSONString(paramsName), JSONObject.toJSONString(args));
             log.info("============platform===========:{}", ServletUtil.getRequestPlatform());
             log.info("============deviceId===========:{}", ServletUtil.getRequestDeviceId());
-            log.info("============Authorization===========:{}", ServletUtil.getRequestAuthorization());
-            log.info("============time===========:{}", ServletUtil.getRequestTime());
+            log.info("============Authorization===========:{}", ServletUtil.getRequestAuthorizationForAspect());
+            log.info("============time===========:{}", ServletUtil.getRequestTimeForTime());
             Object proceed = joinPoint.proceed();
             long end = System.currentTimeMillis();
             log.info("============耗时============:{}秒", (end - start) / 1000);

+ 46 - 9
themis-exam/src/main/java/com/qmth/themis/exam/util/ServletUtil.java

@@ -3,6 +3,8 @@ package com.qmth.themis.exam.util;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.util.JacksonUtil;
 import com.qmth.themis.common.contanst.Constants;
+import com.qmth.themis.common.enums.ExceptionResultEnum;
+import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import org.springframework.web.context.request.RequestContextHolder;
@@ -63,6 +65,9 @@ public class ServletUtil {
         // 如果header中不存在platform,则从参数中获取platform
         if (Objects.isNull(platform)) {
             platform = request.getParameter(Constants.HEADER_PLATFORM);
+            if (Objects.isNull(platform)) {
+                throw new BusinessException(ExceptionResultEnum.PLATFORM_IS_NULL);
+            }
         }
         return platform;
     }
@@ -79,6 +84,9 @@ public class ServletUtil {
         // 如果header中不存在deviceId,则从参数中获取deviceId
         if (Objects.isNull(deviceId)) {
             deviceId = request.getParameter(Constants.HEADER_DEVICE_ID);
+            if (Objects.isNull(deviceId)) {
+                throw new BusinessException(ExceptionResultEnum.DEVICE_ID_IS_NULL);
+            }
         }
         return deviceId;
     }
@@ -95,6 +103,9 @@ public class ServletUtil {
         // 如果header中不存在time,则从参数中获取time
         if (Objects.isNull(time)) {
             time = request.getParameter(Constants.HEADER_TIME);
+            if (Objects.isNull(time)) {
+                throw new BusinessException(ExceptionResultEnum.TIME_IS_NULL);
+            }
         }
         return time;
     }
@@ -111,10 +122,45 @@ public class ServletUtil {
         // 如果header中不存在authorization,则从参数中获取authorization
         if (Objects.isNull(authorization)) {
             authorization = request.getParameter(Constants.HEADER_AUTHORIZATION);
+            if (Objects.isNull(authorization)) {
+                throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_IS_NULL);
+            }
         }
         return authorization;
     }
 
+    /**
+     * 获取请求的Authorization
+     *
+     * @return
+     */
+    public static String getRequestAuthorizationForAspect() {
+        HttpServletRequest request = getRequest();
+        // 从header中获取authorization
+        String authorization = request.getHeader(Constants.HEADER_AUTHORIZATION);
+        // 如果header中不存在authorization,则从参数中获取authorization
+        if (Objects.isNull(authorization)) {
+            authorization = request.getParameter(Constants.HEADER_AUTHORIZATION);
+        }
+        return authorization;
+    }
+
+    /**
+     * 获取请求的time
+     *
+     * @return
+     */
+    public static String getRequestTimeForTime() {
+        HttpServletRequest request = getRequest();
+        // 从header中获取time
+        String time = request.getHeader(Constants.HEADER_TIME);
+        // 如果header中不存在time,则从参数中获取time
+        if (Objects.isNull(time)) {
+            time = request.getParameter(Constants.HEADER_TIME);
+        }
+        return time;
+    }
+
     /**
      * 获取请求的md5
      *
@@ -151,15 +197,6 @@ public class ServletUtil {
         return getRequest().getAttribute(SystemConstant.ACCOUNT);
     }
 
-    /**
-     * 获取请求的student account
-     *
-     * @return
-     */
-    public static Object getRequestStudentAccount() {
-        return getRequest().getAttribute(SystemConstant.STUDENT_ACCOUNT);
-    }
-
     /**
      * 获取请求的org
      *