mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
新增extension模块
This commit is contained in:
parent
9d95764196
commit
ac0e5bbc97
@ -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,12 +21,17 @@
|
||||
<dependency>
|
||||
<groupId>io.github.xpc1024</groupId>
|
||||
<artifactId>easy-es-core</artifactId>
|
||||
<version>0.9.6</version>
|
||||
<version>0.9.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
<groupId>io.github.xpc1024</groupId>
|
||||
<artifactId>easy-es-extension</artifactId>
|
||||
<version>0.9.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -58,14 +59,15 @@ public class EsConfigProperties {
|
||||
*/
|
||||
protected InterceptorChain interceptorChain;
|
||||
|
||||
public void initInterceptorChain(){
|
||||
if(interceptorChain == null){
|
||||
interceptorChain = new InterceptorChain();
|
||||
public void initInterceptorChain() {
|
||||
if (interceptorChain == null) {
|
||||
interceptorChain = new InterceptorChain();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加拦截器
|
||||
*
|
||||
* @param interceptor
|
||||
*/
|
||||
public void addInterceptor(Interceptor interceptor) {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
23
easy-es-extension/pom.xml
Normal 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>
|
||||
@ -1,4 +1,4 @@
|
||||
package com.xpc.easyes.core.plugin.interceptor;
|
||||
package com.xpc.easyes.extension.anno;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@ -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;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.xpc.easyes.core.plugin.interceptor;
|
||||
package com.xpc.easyes.extension.plugins;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -35,7 +36,7 @@ public class Plugin implements InvocationHandler {
|
||||
/**
|
||||
* 包装代理
|
||||
*
|
||||
* @param t 泛型
|
||||
* @param t 泛型
|
||||
* @param interceptor 拦截器
|
||||
* @return 泛型
|
||||
*/
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -14,7 +14,7 @@ import lombok.Data;
|
||||
public class GeneralBean {
|
||||
|
||||
/**
|
||||
* 删除状态
|
||||
* 逻辑删除状态
|
||||
*/
|
||||
private Boolean existStatus;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
/**
|
||||
@ -26,12 +25,12 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class DeleteInterceptor implements Interceptor {
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
// 统一逻辑删除拦截
|
||||
System.out.println("啊啊啊,我拦截到了删除,禁止删除");
|
||||
// 这里直接改为update
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
// 统一逻辑删除拦截
|
||||
System.out.println("啊啊啊,我拦截到了删除,禁止直接删除");
|
||||
// 这里直接改为update逻辑删除...
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user