wangliang 4 år sedan
förälder
incheckning
cc6ab5b3d1

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

@@ -119,13 +119,13 @@ public class TBUserController {
         QueryWrapper<TBUser> wrapper = new QueryWrapper<>();
         wrapper.lambda().eq(TBUser::getLoginName, loginName);
         TBUser user = tbUserService.getOne(wrapper);
-        if (Objects.nonNull(user.getOrgId()) && user.getOrgId().longValue() != tbOrg.getId().longValue()) {
-            throw new BusinessException("用户机构不匹配");
-        }
         //用户不存在
         if (Objects.isNull(user)) {
             throw new BusinessException(ExceptionResultEnum.USER_NO);
         }
+        if (Objects.nonNull(user.getOrgId()) && user.getOrgId().longValue() != tbOrg.getId().longValue()) {
+            throw new BusinessException("用户机构不匹配");
+        }
         String loginPassword = AesUtil.decryptCs7(password, Constants.AES_RULE);
         //密码错误
         String aesPassword = AesUtil.decryptCs7(user.getPassword(), Constants.AES_RULE);

+ 0 - 6
themis-common/src/main/java/com/qmth/themis/common/exception/BusinessException.java

@@ -1,8 +1,6 @@
 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;
 
@@ -14,7 +12,6 @@ import java.io.Serializable;
  * @Date: 2019/10/11
  */
 public class BusinessException extends RuntimeException implements Serializable {
-    private final static Logger log = LoggerFactory.getLogger(BusinessException.class);
 
     private int statusCode;
     private int code;  //错误码
@@ -29,7 +26,6 @@ public class BusinessException extends RuntimeException implements Serializable
         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(int statusCode, int code, String message) {
@@ -37,7 +33,6 @@ public class BusinessException extends RuntimeException implements Serializable
         this.statusCode = statusCode;
         this.code = code;
         this.message = message;
-        log.error("code:{}\nmessage:{}\nexception:{}", this.getCode(), this.getMessage(), this.getStackTrace());
     }
 
     public BusinessException(String message) {
@@ -45,7 +40,6 @@ public class BusinessException extends RuntimeException implements Serializable
         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 int getCode() {

+ 8 - 0
themis-common/src/main/java/com/qmth/themis/common/exception/GlobalDefultExceptionHandler.java

@@ -3,6 +3,8 @@ package com.qmth.themis.common.exception;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 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.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -20,6 +22,7 @@ import java.sql.SQLException;
  */
 @ControllerAdvice
 public class GlobalDefultExceptionHandler {
+    private final static Logger log = LoggerFactory.getLogger(GlobalDefultExceptionHandler.class);
 
     /**
      * excetion异常处理
@@ -36,14 +39,17 @@ public class GlobalDefultExceptionHandler {
         if (e instanceof BusinessException) {
             BusinessException businessException = (BusinessException) e;
             response.setStatus(businessException.getStatusCode());
+            log.error("statusCode:{}\ncode:{}\nmessage:{}\nexception:{}", businessException.getStatusCode(), businessException.getCode(), e.getMessage(), e.getStackTrace());
             return ResultUtil.error(businessException.getCode(), businessException.getMessage());
         } else if (e instanceof IllegalArgumentException) {
             response.setStatus(ExceptionResultEnum.EXCEPTION_ERROR.getStatusCode());
+            log.error("statusCode:{}\ncode:{}\nmessage:{}\nexception:{}", ExceptionResultEnum.EXCEPTION_ERROR.getStatusCode(), ExceptionResultEnum.EXCEPTION_ERROR.getCode(), e.getMessage(), e.getStackTrace());
             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());
+        log.error("statusCode:{}\ncode:{}\nmessage:{}\nexception:{}", ExceptionResultEnum.EXCEPTION_ERROR.getStatusCode(), ExceptionResultEnum.EXCEPTION_ERROR.getCode(), e.getMessage(), e.getStackTrace());
         //Exception错误
         return ResultUtil.error(ExceptionResultEnum.EXCEPTION_ERROR.getCode(), e.getMessage());
     }
@@ -60,6 +66,7 @@ public class GlobalDefultExceptionHandler {
     @ResponseBody
     public <T> Result sqlExceptionHandler(SQLException e, HttpServletResponse response) {
         response.setStatus(ExceptionResultEnum.SQL_ERROR.getStatusCode());
+        log.error("statusCode:{}\ncode:{}\nmessage:{}\nexception:{}", ExceptionResultEnum.SQL_ERROR.getStatusCode(), ExceptionResultEnum.SQL_ERROR.getCode(), e.getMessage(), e.getStackTrace());
         return ResultUtil.error(ExceptionResultEnum.SQL_ERROR.getCode(), e.getMessage());
     }
 
@@ -75,6 +82,7 @@ public class GlobalDefultExceptionHandler {
     @ResponseBody
     public <T> Result invocationTargetExceptionHandler(InvocationTargetException e, HttpServletResponse response) {
         response.setStatus(ExceptionResultEnum.INVOCATIONTARGET_ERROR.getStatusCode());
+        log.error("statusCode:{}\ncode:{}\nmessage:{}\nexception:{}", ExceptionResultEnum.INVOCATIONTARGET_ERROR.getStatusCode(), ExceptionResultEnum.INVOCATIONTARGET_ERROR.getCode(), e.getMessage(), e.getStackTrace());
         return ResultUtil.error(ExceptionResultEnum.INVOCATIONTARGET_ERROR.getCode(), ExceptionResultEnum.INVOCATIONTARGET_ERROR.name() + e.getTargetException());
     }
 }