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