新增extension模块

This commit is contained in:
邢鹏成 2022-03-07 17:28:08 +08:00
parent 9d95764196
commit ac0e5bbc97
19 changed files with 82 additions and 54 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easy-es-parent</artifactId>
<groupId>io.github.xpc1024</groupId>
<version>0.9.6</version>
<version>0.9.7</version>
<relativePath>../easy-es-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -21,7 +21,12 @@
<dependency>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-core</artifactId>
<version>0.9.6</version>
<version>0.9.7</version>
</dependency>
<dependency>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-extension</artifactId>
<version>0.9.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -1,7 +1,8 @@
package com.xpc.easyes.autoconfig.config;
import com.xpc.easyes.core.plugin.interceptor.Interceptor;
import com.xpc.easyes.core.plugin.interceptor.InterceptorChain;
import com.xpc.easyes.extension.plugins.Interceptor;
import com.xpc.easyes.extension.plugins.InterceptorChain;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ -66,6 +67,7 @@ public class EsConfigProperties {
/**
* 添加拦截器
*
* @param interceptor
*/
public void addInterceptor(Interceptor interceptor) {

View File

@ -2,10 +2,10 @@ package com.xpc.easyes.autoconfig.register;
import com.xpc.easyes.autoconfig.config.EsConfigProperties;
import com.xpc.easyes.core.cache.BaseCache;
import com.xpc.easyes.core.plugin.interceptor.Interceptor;
import com.xpc.easyes.core.plugin.interceptor.InterceptorChain;
import com.xpc.easyes.core.plugin.interceptor.Intercepts;
import com.xpc.easyes.core.proxy.EsMapperProxy;
import com.xpc.easyes.extension.anno.Intercepts;
import com.xpc.easyes.extension.plugins.Interceptor;
import com.xpc.easyes.extension.plugins.InterceptorChain;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -7,13 +7,13 @@
<parent>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-parent</artifactId>
<version>0.9.6</version>
<version>0.9.7</version>
<relativePath>../easy-es-parent</relativePath>
</parent>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-core</artifactId>
<version>0.9.6</version>
<version>0.9.7</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

23
easy-es-extension/pom.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-parent</artifactId>
<version>0.9.7</version>
<relativePath>../easy-es-parent</relativePath>
</parent>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-extension</artifactId>
<version>0.9.7</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor;
package com.xpc.easyes.extension.anno;
import java.lang.annotation.*;

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor;
package com.xpc.easyes.extension.anno;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor;
package com.xpc.easyes.extension.plugins;
/**
* <p>

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor;
package com.xpc.easyes.extension.plugins;
import java.util.ArrayList;
import java.util.Collections;

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor;
package com.xpc.easyes.extension.plugins;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

View File

@ -1,8 +1,9 @@
package com.xpc.easyes.core.plugin.interceptor;
package com.xpc.easyes.extension.plugins;
import com.xpc.easyes.core.exception.EasyEsException;
import com.xpc.easyes.core.utils.ExceptionUtil;
import com.xpc.easyes.extension.anno.Intercepts;
import com.xpc.easyes.extension.anno.Signature;
import com.xpc.easyes.extension.utils.ExceptionUtil;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@ -64,7 +65,7 @@ public class Plugin implements InvocationHandler {
Intercepts interceptsAnnotation = interceptor.getClass().getAnnotation(Intercepts.class);
// 检查类是否被@Intercepts标记
if (interceptsAnnotation == null) {
throw new EasyEsException("No @Intercepts annotation was found in interceptor " + interceptor.getClass().getName());
throw new RuntimeException("No @Intercepts annotation was found in interceptor " + interceptor.getClass().getName());
}
Signature[] sigs = interceptsAnnotation.value();
Map<Class<?>, Set<Method>> signatureMap = new HashMap<>();
@ -75,7 +76,7 @@ public class Plugin implements InvocationHandler {
Method method = sig.type().getMethod(sig.method(), sig.args());
methods.add(method);
} catch (NoSuchMethodException e) {
throw new EasyEsException("Could not find method on " + sig.type() + " named " + sig.method() + ". Cause: " + e, e);
throw new RuntimeException("Could not find method on " + sig.type() + " named " + sig.method() + ". Cause: " + e, e);
}
}
return signatureMap;

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.utils;
package com.xpc.easyes.extension.utils;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;

View File

@ -6,7 +6,7 @@
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-parent</artifactId>
<version>0.9.6</version>
<version>0.9.7</version>
<name>easy-es-parent</name>
<description>easy use for elastic search</description>
@ -22,6 +22,7 @@
<modules>
<module>../easy-es-core</module>
<module>../easy-es-boot-starter</module>
<module>../easy-es-extension</module>
</modules>
<properties>

View File

@ -9,7 +9,7 @@
<parent>
<artifactId>easy-es</artifactId>
<groupId>io.github.xpc1024</groupId>
<version>0.9.6</version>
<version>0.9.7</version>
</parent>
<properties>
@ -21,7 +21,7 @@
<dependency>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-boot-starter</artifactId>
<version>0.9.6</version>
<version>0.9.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -1,18 +1,15 @@
package com.xpc.easyes.sample;
import com.xpc.easyes.autoconfig.annotation.EsMapperScan;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
/**
* 启动类
* <p>
* Copyright © 2021 xpc1024 All Rights Reserved
**/
@SpringBootApplication(scanBasePackages = {"com.xpc.easyes"})
@SpringBootApplication
@EsMapperScan("com.xpc.easyes.sample.mapper")
public class EasyEsApplication {
public static void main(String[] args) {

View File

@ -14,7 +14,7 @@ import lombok.Data;
public class GeneralBean {
/**
* 删除状态
* 逻辑删除状态
*/
private Boolean existStatus;

View File

@ -2,11 +2,10 @@ package com.xpc.easyes.sample.interceptor;
import com.xpc.easyes.core.conditions.LambdaEsQueryWrapper;
import com.xpc.easyes.core.conditions.interfaces.BaseEsMapper;
import com.xpc.easyes.core.plugin.interceptor.Interceptor;
import com.xpc.easyes.core.plugin.interceptor.Intercepts;
import com.xpc.easyes.core.plugin.interceptor.Invocation;
import com.xpc.easyes.core.plugin.interceptor.Signature;
import com.xpc.easyes.sample.entity.GeneralBean;
import com.xpc.easyes.extension.anno.Intercepts;
import com.xpc.easyes.extension.anno.Signature;
import com.xpc.easyes.extension.plugins.Interceptor;
import com.xpc.easyes.extension.plugins.Invocation;
import org.springframework.stereotype.Component;
/**
@ -29,8 +28,8 @@ public class DeleteInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
// 统一逻辑删除拦截
System.out.println("啊啊啊,我拦截到了删除,禁止删除");
// 这里直接改为update
System.out.println("啊啊啊,我拦截到了删除,禁止直接删除");
// 这里直接改为update逻辑删除...
return 0;
}

View File

@ -2,10 +2,10 @@ package com.xpc.easyes.sample.interceptor;
import com.xpc.easyes.core.conditions.LambdaEsQueryWrapper;
import com.xpc.easyes.core.conditions.interfaces.BaseEsMapper;
import com.xpc.easyes.core.plugin.interceptor.Interceptor;
import com.xpc.easyes.core.plugin.interceptor.Intercepts;
import com.xpc.easyes.core.plugin.interceptor.Invocation;
import com.xpc.easyes.core.plugin.interceptor.Signature;
import com.xpc.easyes.extension.anno.Intercepts;
import com.xpc.easyes.extension.anno.Signature;
import com.xpc.easyes.extension.plugins.Interceptor;
import com.xpc.easyes.extension.plugins.Invocation;
import com.xpc.easyes.sample.entity.GeneralBean;
import org.springframework.stereotype.Component;
@ -29,9 +29,9 @@ public class QueryInterceptor implements Interceptor {
public Object intercept(Invocation invocation) throws Throwable {
System.out.println("啊啊啊,我拦截到了查询,统一增加查询条件");
// 统一逻辑删除拦截
Object[] args = invocation.getArgs();
LambdaEsQueryWrapper<GeneralBean> arg = (LambdaEsQueryWrapper) args[0];
arg.eq(GeneralBean::getExistStatus, true);
// Object[] args = invocation.getArgs();
// LambdaEsQueryWrapper<GeneralBean> arg = (LambdaEsQueryWrapper) args[0];
// arg.eq(GeneralBean::getExistStatus, true);
return invocation.proceed();
}

View File

@ -6,7 +6,7 @@
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es</artifactId>
<version>0.9.6</version>
<version>0.9.7</version>
<name>easy-es</name>
<description>easy use for elastic search</description>