Pārlūkot izejas kodu

用户模块 修复QQ登录判断逻辑,增加超过登录设备数异常701

songfuqiang 1 gadu atpakaļ
vecāks
revīzija
018fd895f5

+ 5 - 0
backend-common/src/main/java/constant/CommonConstant.java

@@ -74,6 +74,11 @@ public interface CommonConstant {
     int EXCEPTION_CODE_RUNTIME_ERROR = 700;
     String EXCEPTION_MSG_RUNTIME_ERROR = "运行时错误";
 
+    /**
+     * 设备数超出登录台数
+     */
+    int EXCEPTION_CODE_TOO_MANY_DEVICE_ERROR = 701;
+
     /**
      * 用户登录错误状态
      */

+ 23 - 0
backend-common/src/main/java/exception/TooManyDeviceException.java

@@ -0,0 +1,23 @@
+package exception;
+
+/**
+ * @author tangxiangan
+ */
+public class TooManyDeviceException extends RuntimeException {
+    public TooManyDeviceException() {
+        super();
+    }
+
+    public TooManyDeviceException(String message) {
+        super(message);
+    }
+
+    public TooManyDeviceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public TooManyDeviceException(Throwable cause) {
+        super(cause);
+    }
+
+}

+ 7 - 0
backend-core/src/main/java/cn/kdan/pdf/backend/core/config/ControllerExceptionHandler.java

@@ -2,6 +2,7 @@ package cn.kdan.pdf.backend.core.config;
 
 import constant.CommonConstant;
 import exception.BackendRuntimeException;
+import exception.TooManyDeviceException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.support.DefaultMessageSourceResolvable;
@@ -42,6 +43,12 @@ public class ControllerExceptionHandler {
         return new ResultMap<>(CommonConstant.EXCEPTION_CODE_RUNTIME_ERROR, e.getMessage());
     }
 
+    @ExceptionHandler(TooManyDeviceException.class)
+    @ResponseBody
+    public ResultMap<?> handlerDevOpsTooManyDeviceException(TooManyDeviceException e) {
+        return new ResultMap<>(CommonConstant.EXCEPTION_CODE_TOO_MANY_DEVICE_ERROR, e.getMessage());
+    }
+
     @ExceptionHandler(ConstraintViolationException.class)
     @ResponseBody
     public ResultMap<?> handlerConstraintViolationException(ConstraintViolationException e) {

+ 2 - 1
backend-core/src/main/java/cn/kdan/pdf/backend/core/service/impl/DeviceServiceImpl.java

@@ -8,6 +8,7 @@ import cn.kdan.pdf.backend.core.params.RelationParam;
 import cn.kdan.pdf.backend.core.service.DeviceService;
 import cn.kdan.pdf.backend.core.service.MemberService;
 import exception.BackendRuntimeException;
+import exception.TooManyDeviceException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
@@ -61,7 +62,7 @@ public class DeviceServiceImpl implements DeviceService {
             return list.get(0);
         }else{
             if(devices.size() >= 3){
-                throw new BackendRuntimeException("当前已登录3台设备,无法在进行登录");
+                throw new TooManyDeviceException("当前已登录3台设备,无法在进行登录");
             }else{
                 return null;
             }

+ 1 - 1
backend-core/src/main/java/cn/kdan/pdf/backend/core/utils/TencentUtils.java

@@ -65,7 +65,7 @@ public class TencentUtils {
             log.error("获取QQ用户信息失败:{},errorMsg:{}", resp,e.getMessage());
             throw new BackendRuntimeException("获取QQ用户信息失败");
         }
-        if(ObjectUtils.isNotEmpty(tencent) && StringUtils.isBlank(tencent.getUnionId())){
+        if(ObjectUtils.isNotEmpty(tencent) && StringUtils.isBlank(tencent.getNickname())){
             log.error("获取QQ用户信息失败:{}", resp);
             throw new BackendRuntimeException("获取QQ用户信息失败");
         }