|
@@ -1,17 +1,7 @@
|
|
|
package com.chelvc.framework.base.interceptor;
|
|
|
|
|
|
-import java.lang.reflect.Method;
|
|
|
-
|
|
|
import ch.qos.logback.classic.Level;
|
|
|
-import com.chelvc.framework.base.annotation.Version;
|
|
|
-import com.chelvc.framework.base.annotation.Versions;
|
|
|
-import com.chelvc.framework.base.context.ApplicationContextHolder;
|
|
|
import com.chelvc.framework.base.context.LoggingContextHolder;
|
|
|
-import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
-import com.chelvc.framework.common.exception.ResourceUnavailableException;
|
|
|
-import com.chelvc.framework.common.model.Terminal;
|
|
|
-import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
-import com.chelvc.framework.common.util.StringUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
@@ -22,7 +12,6 @@ import org.aspectj.lang.reflect.MethodSignature;
|
|
|
import org.springframework.boot.web.servlet.error.ErrorController;
|
|
|
import org.springframework.core.Ordered;
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
-import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
|
@@ -54,53 +43,6 @@ public class ControllerAccessInterceptor {
|
|
|
&& LoggingContextHolder.level(signature.getDeclaringTypeName()) == Level.DEBUG;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 检查终端版本号
|
|
|
- *
|
|
|
- * @param point 接口方法拦截点
|
|
|
- */
|
|
|
- private void checkVersion(JoinPoint point) {
|
|
|
- Signature signature = point.getSignature();
|
|
|
- if (!(signature instanceof MethodSignature)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Terminal terminal = SessionContextHolder.getTerminal();
|
|
|
- if (terminal == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 接口方法/类版本注解校验
|
|
|
- Method method = ((MethodSignature) signature).getMethod();
|
|
|
- Version[] versions = ObjectUtils.ifNull(method.getAnnotation(Versions.class), Versions::value);
|
|
|
- if (ObjectUtils.isEmpty(versions)) {
|
|
|
- Class<?> declaring = signature.getDeclaringType();
|
|
|
- versions = ObjectUtils.ifNull(declaring.getAnnotation(Versions.class), Versions::value);
|
|
|
- }
|
|
|
- if (ObjectUtils.notEmpty(versions)) {
|
|
|
- Environment environment = ApplicationContextHolder.getEnvironment(false);
|
|
|
- for (Version version : versions) {
|
|
|
- if (version.terminal() == terminal && StringUtils.notEmpty(version.value())
|
|
|
- && !SessionContextHolder.isVersion(version)) {
|
|
|
- String message = version.message();
|
|
|
- if (environment != null && StringUtils.notEmpty(message)) {
|
|
|
- message = environment.resolvePlaceholders(message);
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(message)) {
|
|
|
- message = ApplicationContextHolder.getMessage("Version.Control.Limit");
|
|
|
- }
|
|
|
- throw new ResourceUnavailableException(message);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 终端最低版本配置校验
|
|
|
- String minimum = ApplicationContextHolder.getProperty(terminal.name().toLowerCase() + ".version.minimum");
|
|
|
- if (StringUtils.notEmpty(minimum) && !SessionContextHolder.isAfterVersion(terminal, minimum, true)) {
|
|
|
- throw new ResourceUnavailableException(ApplicationContextHolder.getMessage("Version.Control.Limit"));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 接口请求日志打印
|
|
|
*
|
|
@@ -114,7 +56,6 @@ public class ControllerAccessInterceptor {
|
|
|
if (debug) {
|
|
|
LoggingContextHolder.debug(log, point.getArgs());
|
|
|
}
|
|
|
- this.checkVersion(point);
|
|
|
Object value = point.proceed();
|
|
|
if (debug) {
|
|
|
LoggingContextHolder.debug(log, value);
|