Răsfoiți Sursa

异常修改

wangliang 4 ani în urmă
părinte
comite
8e8a9f757d

+ 1 - 1
themis-backend/src/main/java/com/qmth/themis/backend/api/TBExamInvigilateUserController.java

@@ -94,7 +94,7 @@ public class TBExamInvigilateUserController {
             String userId = String.valueOf(mapParameter.get("userId"));
             String[] userIds = userId.split(",");
             if (userIds.length > 3) {
-                throw new BusinessException(ExceptionResultEnum.ERROR.getCode(), "一个考场最多设置3名监考员");
+                throw new BusinessException(ExceptionResultEnum.ERROR.getStatusCode(), ExceptionResultEnum.ERROR.getCode(), "一个考场最多设置3名监考员");
             }
             TBOrg tbOrg = (TBOrg) ServletUtil.getRequestOrg();
             QueryWrapper<TBExamInvigilateUser> tbExamInvigilateUserQueryWrapper = new QueryWrapper<>();

+ 1 - 1
themis-backend/src/main/java/com/qmth/themis/backend/api/TBUserController.java

@@ -130,7 +130,7 @@ public class TBUserController {
         //密码错误
         String aesPassword = AesUtil.decryptCs7(user.getPassword(), Constants.AES_RULE);
         if (!Objects.equals(loginPassword, aesPassword)) {
-            throw new BusinessException(ExceptionResultEnum.PASSWORD_NO);
+            throw new BusinessException(ExceptionResultEnum.PASSWORD_ERROR);
         }
         return userLoginCommon(user);
     }

+ 1 - 7
themis-backend/src/main/java/com/qmth/themis/backend/interceptor/AuthInterceptor.java

@@ -7,7 +7,6 @@ import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
 import com.qmth.themis.business.entity.TBSession;
 import com.qmth.themis.business.entity.TBUser;
-import com.qmth.themis.business.enums.RoleEnum;
 import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TBUserService;
 import com.qmth.themis.business.util.RedisUtil;
@@ -67,12 +66,6 @@ public class AuthInterceptor implements HandlerInterceptor {
         }
         Platform platform = Platform.valueOf(ServletUtil.getRequestPlatform());
         String deviceId = ServletUtil.getRequestDeviceId();
-        if (Objects.isNull(platform) || Objects.equals(platform, "")) {
-            throw new BusinessException(ExceptionResultEnum.PLATFORM_INVALID);
-        }
-        if (Objects.isNull(deviceId) || Objects.equals(deviceId, "")) {
-            throw new BusinessException(ExceptionResultEnum.DEVICE_ID_INVALID);
-        }
         String authorization = ServletUtil.getRequestAuthorization();
         String time = ServletUtil.getRequestTime();
         log.info("platform:{},deviceId:{},authorization:{},method:{},time:{}", platform, deviceId, authorization, method, time);
@@ -142,6 +135,7 @@ public class AuthInterceptor implements HandlerInterceptor {
 //        } else {
 //            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
 //        }
+        response.setStatus(ExceptionResultEnum.SUCCESS.getStatusCode());
         return true;
     }
 

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

@@ -31,7 +31,7 @@ public class ServletUtil {
      * @param message
      * @throws IOException
      */
-    public static void responseError(String code, String message) throws IOException {
+    public static void responseError(int code, String message) throws IOException {
         Result result = ResultUtil.error(code, message);
         String json = JacksonUtil.parseJson(result);
         getResponse().getWriter().print(json);
@@ -66,7 +66,7 @@ public class ServletUtil {
         if (Objects.isNull(platform)) {
             platform = request.getParameter(Constants.HEADER_PLATFORM);
             if (Objects.isNull(platform)) {
-                throw new BusinessException(ExceptionResultEnum.PLATFORM_IS_NULL);
+                throw new BusinessException(ExceptionResultEnum.PLATFORM_INVALID);
             }
         }
         return platform;
@@ -85,7 +85,7 @@ public class ServletUtil {
         if (Objects.isNull(deviceId)) {
             deviceId = request.getParameter(Constants.HEADER_DEVICE_ID);
             if (Objects.isNull(deviceId)) {
-                throw new BusinessException(ExceptionResultEnum.DEVICE_ID_IS_NULL);
+                throw new BusinessException(ExceptionResultEnum.DEVICE_ID_INVALID);
             }
         }
         return deviceId;
@@ -104,7 +104,7 @@ public class ServletUtil {
         if (Objects.isNull(time)) {
             time = request.getParameter(Constants.HEADER_TIME);
             if (Objects.isNull(time)) {
-                throw new BusinessException(ExceptionResultEnum.TIME_IS_NULL);
+                throw new BusinessException(ExceptionResultEnum.TIME_INVALID);
             }
         }
         return time;
@@ -123,7 +123,7 @@ public class ServletUtil {
         if (Objects.isNull(authorization)) {
             authorization = request.getParameter(Constants.HEADER_AUTHORIZATION);
             if (Objects.isNull(authorization)) {
-                throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_IS_NULL);
+                throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_INVALID);
             }
         }
         return authorization;

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/constant/SpringContextHolder.java

@@ -63,7 +63,7 @@ public class SpringContextHolder implements ApplicationContextAware {
      */
     private static void assertApplicationContext() {
         if (SpringContextHolder.applicationContext == null) {
-            throw new BusinessException("SpringContextHolderException", "applicaitonContext属性为null,请检查是否注入了SpringContextHolder!");
+            throw new BusinessException(500, 500, "applicaitonContext属性为null,请检查是否注入了SpringContextHolder!");
         }
     }
 }

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

@@ -101,7 +101,7 @@ public class ExcelUtil {
                     }
                 }
                 if (oList.size() == 0 && finalOList.size() == 0) {
-                    throw new BusinessException(ExceptionResultEnum.EXCEL_IS_NULL);
+                    throw new BusinessException(ExceptionResultEnum.EXCEL_NO);
                 }
                 if (oList.size() > 0) {
                     finalOList.add(oList);

+ 5 - 1
themis-common/pom.xml

@@ -61,7 +61,11 @@
 			<artifactId>commons-io</artifactId>
 			<version>2.6</version>
 		</dependency>
-		<!-- <dependency> -->
+        <dependency>
+            <groupId>org.apache.tomcat.embed</groupId>
+            <artifactId>tomcat-embed-core</artifactId>
+        </dependency>
+        <!-- <dependency> -->
 		<!-- <groupId>org.slf4j</groupId> -->
 		<!-- <artifactId>slf4j-api</artifactId> -->
 		<!-- <version>2.0.0-alpha1</version> -->

+ 102 - 86
themis-common/src/main/java/com/qmth/themis/common/enums/ExceptionResultEnum.java

@@ -8,179 +8,195 @@ package com.qmth.themis.common.enums;
  * @Date: 2019/10/11
  */
 public enum ExceptionResultEnum {
-    UNKONW_ERROR("-2", "未知错误:请联系管理员"),
+    /**
+     * 系统预置
+     */
+    UNKONW_ERROR(500, 500001, "未知错误:请联系管理员"),
 
-    EXCEPTION_ERROR("-1", "系统异常:请联系管理员"),
+    EXCEPTION_ERROR(500, 500002, "系统异常:请联系管理员"),
 
-    SUCCESS("0", "成功"),
+    SUCCESS(200, 200, "成功"),
 
-    ERROR("500", "失败"),
+    ERROR(500, 500, "失败"),
 
-    SQL_ERROR("502", "sql异常:"),
+    SQL_ERROR(500, 500003, "sql异常:"),
 
-    INVOCATIONTARGET_ERROR("503", "反射异常:"),
+    INVOCATIONTARGET_ERROR(500, 500004, "反射异常:"),
 
-    USERNAME_ILLEGALITY("100", "用户名非法"),
+    SERVICE_NOT_FOUND(500, 500004, "服务器错误"),
 
-    PARAMS_ILLEGALITY("102", "参数不能为空"),
+    /**
+     * 400
+     */
+    USERNAME_ILLEGALITY(400, 400001, "用户名非法"),
 
-    TASK_ID_IS_NULL("102", "任务id不能为空"),
+    PARAMS_ILLEGALITY(400, 400002, "参数不能为空"),
 
-    TASK_TYPE_IS_NULL("102", "任务类型不能为空"),
+    TASK_ID_IS_NULL(400, 400003, "任务id不能为空"),
 
-    TASK_TYPE_ERROR("102", "任务类型不匹配"),
+    TASK_TYPE_IS_NULL(400, 400004, "任务类型不能为空"),
 
-    EXAM_ID_IS_NULL("102", "考试批次id不能为空"),
+    TASK_TYPE_ERROR(400, 400005, "任务类型不匹配"),
 
-    RECORD_ID_IS_NULL("102", "考试记录id不能为空"),
+    EXAM_ID_IS_NULL(400, 400006, "考试批次id不能为空"),
 
-    RECORD_NO("102", "考试记录不存在"),
+    RECORD_ID_IS_NULL(400, 400007, "考试记录id不能为空"),
 
-    EXAM_INFO_IS_NULL("102", "考试批次信息不能为空"),
+    EXAM_INFO_IS_NULL(400, 400008, "考试批次信息不能为空"),
 
-    EXAM_IS_NULL("102", "考试不能为空"),
+    EXAM_IS_NULL(400, 400009, "考试不能为空"),
 
-    EXAM_STUDENT_ID_IS_NULL("102", "考生id不能为空"),
+    EXAM_STUDENT_ID_IS_NULL(400, 400010, "考生id不能为空"),
 
-    EXAM_STUDENT_INFO_IS_NULL("102", "待修改的考生信息不能为空"),
+    EXAM_STUDENT_INFO_IS_NULL(400, 400011, "待修改的考生信息不能为空"),
 
-    EXAM_DETAIL_ID_IS_NULL("102", "考试详情id不能为空"),
+    EXAM_DETAIL_ID_IS_NULL(400, 400012, "考试详情id不能为空"),
 
-    STUDENT_ID_IS_NULL("102", "学生id不能为空"),
+    STUDENT_ID_IS_NULL(400, 400013, "学生id不能为空"),
 
-    ROOMCODE_IS_NULL("102", "考场代码不能为空"),
+    ROOMCODE_IS_NULL(400, 400014, "考场代码不能为空"),
 
-    STUDENT_INFO_IS_NULL("102", "待修改的学生信息不能为空"),
+    STUDENT_INFO_IS_NULL(400, 400015, "待修改的学生信息不能为空"),
 
-    LOGIN_NAME_IS_NULL("102", "用户名不能为空"),
+    LOGIN_NAME_IS_NULL(400, 400016, "用户名不能为空"),
 
-    SHORT_CODE_IS_NULL("102", "考试口令不能为空"),
+    SHORT_CODE_IS_NULL(400, 400017, "考试口令不能为空"),
 
-    PASSWORD_IS_NULL("102", "密码不能为空"),
+    PASSWORD_IS_NULL(400, 400018, "密码不能为空"),
 
-    VERIFYCODE_IS_NULL("102", "验证码不能为空"),
+    VERIFYCODE_IS_NULL(400, 400019, "验证码不能为空"),
 
-    ORG_INFO_IS_NULL("102", "机构信息不能为空"),
+    ORG_INFO_IS_NULL(400, 400020, "机构信息不能为空"),
 
-    ORG_ID_IS_NULL("102", "机构id不能为空"),
+    ORG_ID_IS_NULL(400, 400021, "机构id不能为空"),
 
-    ORG_CODE_IS_NULL("102", "机构代码不能为空"),
+    ORG_CODE_IS_NULL(400, 400022, "机构代码不能为空"),
 
-    ORG_NO("102","机构信息不存在"),
+    USER_INFO_IS_NULL(400, 400023, "用户信息不能为空"),
 
-    USER_INFO_IS_NULL("102", "用户信息不能为空"),
+    MD5_IS_NULL(400, 400024, "附件MD5不能为空"),
 
-    MD5_IS_NULL("102", "附件MD5不能为空"),
+    ATTACHMENT_IS_NULL(400, 400025, "请上传附件"),
 
-    ATTACHMENT_IS_NULL("102", "请上传附件"),
+    ATTACHMENT_TYPE_IS_NULL(400, 400026, "请上传文件类型"),
 
-    ATTACHMENT_TYPE_IS_NULL("102", "请上传文件类型"),
+    DOWNLOAD_FILE_TYPE_IS_NULL(400, 400027, "下载文件类型不能为空"),
 
-    DOWNLOAD_FILE_TYPE_IS_NULL("102", "下载文件类型不能为空"),
+    NAME_IS_NULL(400, 400028, "姓名不能为空"),
 
-    DOWNLOAD_FILE_TYPE_ERROR("102", "下载文件类型错误"),
+    ROLE_CODE_IS_NULL(400, 400029, "角色编码不能为空"),
 
-    PASSWORD_NO("102", "密码不正确"),
+    USER_ID_IS_NULL(400, 400030, "userId不能为空"),
 
-    TASK_NO("102", "任务不存在"),
+    ENABLE_IS_NULL(400, 400031, "禁用/启用状态不能为空"),
 
-    USER_NO("102", "用户不存在"),
+    STUDENT_IS_NULL(400, 400032, "学生信息不能为空"),
 
-    EXAM_NO("102", "考试批次信息不存在"),
+    EXAM_CODE_IS_NULL(400, 400033, "考试批次编码不能为空"),
 
-    EXAM_ACTIVITY_NO("102", "考试场次信息不存在"),
+    EXAM_NAME_IS_NULL(400, 400034, "考试批次名称不能为空"),
 
-    TOKEN_NO("102", "token已过期"),
+    ATTACHMENT_ID_IS_NULL(400, 400035, "附件id不能为空"),
 
-    EXCEL_IS_NULL("102", "excel没有数据"),
+    SCENE_NUMBER_ID_IS_NULL(400, 400036, "场次id不能为空"),
 
-    NAME_IS_NULL("102", "姓名不能为空"),
+    EXAM_SITE_IS_NULL(400, 400037, "考点不能为空"),
 
-    ROLE_CODE_IS_NULL("102", "角色编码不能为空"),
+    EXAM_ROOM_ID_IS_NULL(400, 400038, "考场id不能为空"),
 
-    USER_ID_IS_NULL("102", "userId不能为空"),
+    COURSE_INFO_IS_NULL(400, 400039, "科目信息不能为空"),
 
-    ENABLE_IS_NULL("102", "禁用/启用状态不能为空"),
+    PAPER_INFO_IS_NULL(400, 400040, "试卷信息不能为空"),
 
-    STUDENT_IS_NULL("102", "学生信息不能为空"),
+    COURSE_ID_IS_NULL(400, 400041, "科目id不能为空"),
 
-    EXAM_CODE_IS_NULL("102", "考试批次编码不能为空"),
+    COURSE_CODE_IS_NULL(400, 400042, "科目编码不能为空"),
 
-    EXAM_NAME_IS_NULL("102", "考试批次名称不能为空"),
+    COURSE_NAME_IS_NULL(400, 400043, "科目名称不能为空"),
 
-    ATTACHMENT_ID_IS_NULL("102", "附件id不能为空"),
+    EXCEL_NO(400, 400044, "excel没有数据"),
 
-    ATTACHMENT_NO("102", "附件不存在"),
+    /**
+     * 401
+     */
+    TOKEN_TIME_OUT(401, 401001, "token已过期"),
 
-    STUDENT_NO("102", "学生不存在"),
+    TOKEN_INVALID(401, 401002, "token无效"),
 
-    EXAM_STUDENT_NO("102", "考生不存在"),
+    UN_AUTHORIZATION(401, 401003, "没有权限"),
 
-    LOGIN_NO("102", "请先登录"),
+    AUTHORIZATION_ERROR(401, 401004, "签名验证失败"),
 
-    SCENE_NUMBER_ID_IS_NULL("102", "场次id不能为空"),
+    PLATFORM_INVALID(401, 401005, "platform无效"),
 
-    EXAM_SITE_IS_NULL("102", "考点不能为空"),
+    DEVICE_ID_INVALID(401, 401006, "deviceId无效"),
 
-    EXAM_ROOM_ID_IS_NULL("102", "考场id不能为空"),
+    TIME_INVALID(401, 401007, "time无效"),
 
-    COURSE_INFO_IS_NULL("102", "科目信息不能为空"),
+    AUTHORIZATION_INVALID(401, 401008, "authorization无效"),
 
-    PAPER_INFO_IS_NULL("102", "试卷信息不能为空"),
+    /**
+     * 404
+     */
+    NOT_FOUND(404, 404001, "请求地址错误"),
 
-    COURSE_ID_IS_NULL("102", "科目id不能为空"),
+    /**
+     * 500
+     */
 
-    COURSE_CODE_IS_NULL("102", "科目编码不能为空"),
+    DOWNLOAD_FILE_TYPE_ERROR(500, 500001, "下载文件类型错误"),
 
-    COURSE_NAME_IS_NULL("102", "科目名称不能为空"),
+    PASSWORD_ERROR(500, 500002, "密码不正确"),
 
-    PASSWORD_ILLEGALITY("101", "密码非法"),
+    EXAM_ACTIVITY_NO(500, 500003, "考试场次信息不存在"),
 
-    TOKEN_INVALID("107", "token无效"),
+    RECORD_NO(500, 500004, "考试记录不存在"),
 
-    DEVICE_ID_INVALID("107", "deviceId无效"),
+    ORG_NO(500, 500005, "机构信息不存在"),
 
-    PLATFORM_INVALID("107", "平台无效"),
+    TASK_NO(500, 500006, "任务不存在"),
 
-    USER_ENABLE("109", "用户已停用"),
+    USER_NO(500, 500007, "用户不存在"),
 
-    STUDENT_ENABLE("109", "学生已停用"),
+    EXAM_NO(500, 500008, "考试批次信息不存在"),
 
-    NOT_FOUND("404", "请求地址错误"),
+    ATTACHMENT_NO(500, 500009, "附件不存在"),
 
-    SERVICE_NOT_FOUND("500", "服务器错误"),
+    STUDENT_NO(500, 500010, "学生不存在"),
 
-    ATTACHMENT_ERROR("500", "上传文件失败"),
+    EXAM_STUDENT_NO(500, 500011, "考生不存在"),
 
-    UN_AUTHORIZATION("401", "没有权限"),
+    LOGIN_NO(500, 500012, "请先登录"),
 
-    AUTHORIZATION_ERROR("401", "签名验证失败"),
+    PASSWORD_ILLEGALITY(500, 500013, "密码非法"),
 
-    AUTHORIZATION_SESSION_ERROR("401", "sessionId验证失败"),
-	
-    REQUEST_AWAIT("500", "请求等待:请稍后重试"),
+    USER_ENABLE(500, 500014, "用户已停用"),
 
-    PLATFORM_IS_NULL("500","platform不能为空"),
+    STUDENT_ENABLE(500, 500015, "学生已停用"),
 
-    DEVICE_ID_IS_NULL("500","deviceId不能为空"),
+    REQUEST_AWAIT(500, 500016, "请求等待:请稍后重试"),
 
-    TIME_IS_NULL("500","time不能为空"),
+    ATTACHMENT_ERROR(500, 500017,"上传文件失败");
 
-    AUTHORIZATION_IS_NULL("500","authorization不能为空");
-
-    private String code;
+    private int statusCode;
+    private int code;
     private String message;
 
-    ExceptionResultEnum(String code, String message) {
+    ExceptionResultEnum(int statusCode, int code, String message) {
+        this.statusCode = statusCode;
         this.code = code;
         this.message = message;
     }
 
-    public String getCode() {
+    public int getStatusCode() {
+        return statusCode;
+    }
+
+    public int getCode() {
         return code;
     }
 
     public String getMessage() {
         return message;
     }
-}
+    }

+ 23 - 4
themis-common/src/main/java/com/qmth/themis/common/exception/BusinessException.java

@@ -1,6 +1,8 @@
 package com.qmth.themis.common.exception;
 
 import com.qmth.themis.common.enums.ExceptionResultEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.Serializable;
 
@@ -12,7 +14,10 @@ import java.io.Serializable;
  * @Date: 2019/10/11
  */
 public class BusinessException extends RuntimeException implements Serializable {
-    private String code;  //错误码
+    private final static Logger log = LoggerFactory.getLogger(BusinessException.class);
+
+    private int statusCode;
+    private int code;  //错误码
     private String message;
 
     public BusinessException() {
@@ -21,27 +26,33 @@ public class BusinessException extends RuntimeException implements Serializable
 
     public BusinessException(ExceptionResultEnum exceptionResultEnum) {
         super(exceptionResultEnum.getMessage());
+        this.statusCode = exceptionResultEnum.getStatusCode();
         this.code = exceptionResultEnum.getCode();
         this.message = exceptionResultEnum.getMessage();
+        log.error("code:{}\nmessage:{}\nexception:{}", this.getCode(), this.getMessage(), this.getStackTrace());
     }
 
-    public BusinessException(String code, String message) {
+    public BusinessException(int statusCode, int code, String message) {
         super(message);
+        this.statusCode = statusCode;
         this.code = code;
         this.message = message;
+        log.error("code:{}\nmessage:{}\nexception:{}", this.getCode(), this.getMessage(), this.getStackTrace());
     }
 
     public BusinessException(String message) {
         super(message);
+        this.statusCode = ExceptionResultEnum.ERROR.getStatusCode();
         this.code = ExceptionResultEnum.ERROR.getCode();
         this.message = message;
+        log.error("code:{}\nmessage:{}\nexception:{}", this.getCode(), this.getMessage(), this.getStackTrace());
     }
 
-    public String getCode() {
+    public int getCode() {
         return code;
     }
 
-    public void setCode(String code) {
+    public void setCode(int code) {
         this.code = code;
     }
 
@@ -53,4 +64,12 @@ public class BusinessException extends RuntimeException implements Serializable
     public void setMessage(String message) {
         this.message = message;
     }
+
+    public int getStatusCode() {
+        return statusCode;
+    }
+
+    public void setStatusCode(int statusCode) {
+        this.statusCode = statusCode;
+    }
 }

+ 12 - 3
themis-common/src/main/java/com/qmth/themis/common/exception/GlobalDefultExceptionHandler.java

@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import javax.servlet.http.HttpServletResponse;
 import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
 
@@ -24,21 +25,25 @@ public class GlobalDefultExceptionHandler {
      * excetion异常处理
      *
      * @param e
+     * @param response
      * @param <T>
      * @return
      */
     @ExceptionHandler(Exception.class)
     @ResponseBody
-    public <T> Result defultExcepitonHandler(Exception e) {
+    public <T> Result defultExcepitonHandler(Exception e, HttpServletResponse response) {
         e.printStackTrace();
         if (e instanceof BusinessException) {
             BusinessException businessException = (BusinessException) e;
+            response.setStatus(businessException.getStatusCode());
             return ResultUtil.error(businessException.getCode(), businessException.getMessage());
         } else if (e instanceof IllegalArgumentException) {
+            response.setStatus(ExceptionResultEnum.EXCEPTION_ERROR.getStatusCode());
             if (e.getMessage().contains("No enum constant com.qmth.themis.common.enums.Platform")) {
                 return ResultUtil.error(ExceptionResultEnum.EXCEPTION_ERROR.getCode(), "暂不支持此平台");
             }
         }
+        response.setStatus(ExceptionResultEnum.EXCEPTION_ERROR.getStatusCode());
         //Exception错误
         return ResultUtil.error(ExceptionResultEnum.EXCEPTION_ERROR.getCode(), e.getMessage());
     }
@@ -47,12 +52,14 @@ public class GlobalDefultExceptionHandler {
      * sql异常处理
      *
      * @param e
+     * @param response
      * @param <T>
      * @return
      */
     @ExceptionHandler(SQLException.class)
     @ResponseBody
-    public <T> Result sqlExceptionHandler(SQLException e) {
+    public <T> Result sqlExceptionHandler(SQLException e, HttpServletResponse response) {
+        response.setStatus(ExceptionResultEnum.SQL_ERROR.getStatusCode());
         return ResultUtil.error(ExceptionResultEnum.SQL_ERROR.getCode(), e.getMessage());
     }
 
@@ -60,12 +67,14 @@ public class GlobalDefultExceptionHandler {
      * 反射异常处理
      *
      * @param e
+     * @param response
      * @param <T>
      * @return
      */
     @ExceptionHandler(InvocationTargetException.class)
     @ResponseBody
-    public <T> Result invocationTargetExceptionHandler(InvocationTargetException e) {
+    public <T> Result invocationTargetExceptionHandler(InvocationTargetException e, HttpServletResponse response) {
+        response.setStatus(ExceptionResultEnum.INVOCATIONTARGET_ERROR.getStatusCode());
         return ResultUtil.error(ExceptionResultEnum.INVOCATIONTARGET_ERROR.getCode(), ExceptionResultEnum.INVOCATIONTARGET_ERROR.name() + e.getTargetException());
     }
 }

+ 5 - 5
themis-common/src/main/java/com/qmth/themis/common/util/Result.java

@@ -10,7 +10,7 @@ import java.io.Serializable;
  * @Date: 2019/10/11
  */
 public class Result implements Serializable {
-    private String code;
+    private int code;
     private String message;
     private Object data;
 
@@ -22,22 +22,22 @@ public class Result implements Serializable {
         this.message = message;
     }
 
-    public Result(String code, String message) {
+    public Result(int code, String message) {
         this.code = code;
         this.message = message;
     }
 
-    public Result(String code, String message, Object data) {
+    public Result(int code, String message, Object data) {
         this.code = code;
         this.message = message;
         this.data = data;
     }
 
-    public String getCode() {
+    public int getCode() {
         return code;
     }
 
-    public void setCode(String code) {
+    public void setCode(int code) {
         this.code = code;
     }
 

+ 6 - 6
themis-common/src/main/java/com/qmth/themis/common/util/ResultUtil.java

@@ -21,7 +21,7 @@ public class ResultUtil {
         return success(null);
     }
 
-    public static Result error(String code, String message) {
+    public static Result error(int code, String message) {
         return new Result(code, message);
     }
 
@@ -30,16 +30,16 @@ public class ResultUtil {
     }
 
     public static Result error(String message) {
-        throw new BusinessException(ExceptionResultEnum.ERROR.getCode(), message);
+        throw new BusinessException(ExceptionResultEnum.ERROR.getStatusCode(), ExceptionResultEnum.ERROR.getCode(), message);
     }
 
     public static Result ok(String message) {
-        return new Result(String.valueOf(HttpStatus.HTTP_OK), message);
+        return new Result(HttpStatus.HTTP_OK, message);
     }
 
     public static Result ok(Object data) {
         Result r = new Result();
-        r.setCode(String.valueOf(HttpStatus.HTTP_OK));
+        r.setCode(HttpStatus.HTTP_OK);
         r.setData(data);
         r.setMessage(ExceptionResultEnum.SUCCESS.getMessage());
         return r;
@@ -47,7 +47,7 @@ public class ResultUtil {
 
     public static Result ok(Object data, String message) {
         Result r = new Result();
-        r.setCode(String.valueOf(HttpStatus.HTTP_OK));
+        r.setCode(HttpStatus.HTTP_OK);
         r.setData(data);
         r.setMessage(message);
         return r;
@@ -55,7 +55,7 @@ public class ResultUtil {
 
     public static Result ok() {
         Result r = new Result();
-        r.setCode(String.valueOf(HttpStatus.HTTP_OK));
+        r.setCode(HttpStatus.HTTP_OK);
         return r;
     }
 }

+ 1 - 1
themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java

@@ -115,7 +115,7 @@ public class TEStudentController {
         //密码错误
         String aesPassword = AesUtil.decryptCs7(user.getPassword(), Constants.AES_RULE);
         if (!Objects.equals(loginPassword, aesPassword)) {
-            throw new BusinessException(ExceptionResultEnum.PASSWORD_NO);
+            throw new BusinessException(ExceptionResultEnum.PASSWORD_ERROR);
         }
         return userLoginCommon(user, examId, orgId);
     }

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

@@ -67,12 +67,6 @@ public class AuthInterceptor implements HandlerInterceptor {
         }
         Platform platform = Platform.valueOf(ServletUtil.getRequestPlatform());
         String deviceId = ServletUtil.getRequestDeviceId();
-        if (Objects.isNull(platform) || Objects.equals(platform, "")) {
-            throw new BusinessException(ExceptionResultEnum.PLATFORM_INVALID);
-        }
-        if (Objects.isNull(deviceId) || Objects.equals(deviceId, "")) {
-            throw new BusinessException(ExceptionResultEnum.DEVICE_ID_INVALID);
-        }
         String authorization = ServletUtil.getRequestAuthorization();
         String time = ServletUtil.getRequestTime();
         log.info("platform:{},deviceId:{},authorization:{},method:{},time:{}", platform, deviceId, authorization, method, time);
@@ -142,6 +136,7 @@ public class AuthInterceptor implements HandlerInterceptor {
 //        } else {
 //            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
 //        }
+        response.setStatus(ExceptionResultEnum.SUCCESS.getStatusCode());
         return true;
     }
 

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

@@ -31,7 +31,7 @@ public class ServletUtil {
      * @param message
      * @throws IOException
      */
-    public static void responseError(String code, String message) throws IOException {
+    public static void responseError(int code, String message) throws IOException {
         Result result = ResultUtil.error(code, message);
         String json = JacksonUtil.parseJson(result);
         getResponse().getWriter().print(json);
@@ -66,7 +66,7 @@ public class ServletUtil {
         if (Objects.isNull(platform)) {
             platform = request.getParameter(Constants.HEADER_PLATFORM);
             if (Objects.isNull(platform)) {
-                throw new BusinessException(ExceptionResultEnum.PLATFORM_IS_NULL);
+                throw new BusinessException(ExceptionResultEnum.PLATFORM_INVALID);
             }
         }
         return platform;
@@ -85,7 +85,7 @@ public class ServletUtil {
         if (Objects.isNull(deviceId)) {
             deviceId = request.getParameter(Constants.HEADER_DEVICE_ID);
             if (Objects.isNull(deviceId)) {
-                throw new BusinessException(ExceptionResultEnum.DEVICE_ID_IS_NULL);
+                throw new BusinessException(ExceptionResultEnum.DEVICE_ID_INVALID);
             }
         }
         return deviceId;
@@ -104,7 +104,7 @@ public class ServletUtil {
         if (Objects.isNull(time)) {
             time = request.getParameter(Constants.HEADER_TIME);
             if (Objects.isNull(time)) {
-                throw new BusinessException(ExceptionResultEnum.TIME_IS_NULL);
+                throw new BusinessException(ExceptionResultEnum.TIME_INVALID);
             }
         }
         return time;
@@ -123,7 +123,7 @@ public class ServletUtil {
         if (Objects.isNull(authorization)) {
             authorization = request.getParameter(Constants.HEADER_AUTHORIZATION);
             if (Objects.isNull(authorization)) {
-                throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_IS_NULL);
+                throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_INVALID);
             }
         }
         return authorization;