From 323bc6b775f22688a92eca74bf1f801fa2206c2a Mon Sep 17 00:00:00 2001 From: Chopper Date: Tue, 30 Nov 2021 16:53:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E9=99=90=E5=88=B6=E9=A1=B9=E6=8F=90?= =?UTF-8?q?=E9=AB=98=E5=88=B0=E6=A1=86=E6=9E=B6common=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lili/common/aop/annotation/DemoSite.java | 18 ++++++++++ .../aop/interceptor/DemoInterceptor.java | 34 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 framework/src/main/java/cn/lili/common/aop/annotation/DemoSite.java create mode 100644 framework/src/main/java/cn/lili/common/aop/interceptor/DemoInterceptor.java diff --git a/framework/src/main/java/cn/lili/common/aop/annotation/DemoSite.java b/framework/src/main/java/cn/lili/common/aop/annotation/DemoSite.java new file mode 100644 index 00000000..48facbd3 --- /dev/null +++ b/framework/src/main/java/cn/lili/common/aop/annotation/DemoSite.java @@ -0,0 +1,18 @@ +package cn.lili.common.aop.annotation; + +import java.lang.annotation.*; + +/** + * 演示站点注解 + * + * @author Bulbasaur + * @since 2021/7/9 1:40 上午 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface DemoSite { + + +} diff --git a/framework/src/main/java/cn/lili/common/aop/interceptor/DemoInterceptor.java b/framework/src/main/java/cn/lili/common/aop/interceptor/DemoInterceptor.java new file mode 100644 index 00000000..fad76b48 --- /dev/null +++ b/framework/src/main/java/cn/lili/common/aop/interceptor/DemoInterceptor.java @@ -0,0 +1,34 @@ +package cn.lili.common.aop.interceptor; + +import cn.lili.common.enums.ResultCode; +import cn.lili.common.exception.ServiceException; +import cn.lili.common.properties.SystemSettingProperties; +import cn.lili.common.aop.annotation.DemoSite; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 演示站点拦截 + * DemoInterceptor + * + * @author Chopper + * @version v1.0 + * 2021-05-12 17:55 + */ +@Component +@Aspect +public class DemoInterceptor { + + @Autowired + private SystemSettingProperties systemSettingProperties; + + @Before("@annotation(demoSite)") + public void doAfter(DemoSite demoSite) { + if (systemSettingProperties.getIsDemoSite()) { + throw new ServiceException(ResultCode.DEMO_SITE_EXCEPTION); + } + } + +}