mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
v2.0.0-beta2 完整版
This commit is contained in:
parent
105e80d27d
commit
61e07929ce
2
dist/pages/1cebb8/index.html
vendored
2
dist/pages/1cebb8/index.html
vendored
@ -221,7 +221,7 @@ must查询条件计算得分,filter不计算得分,因此在不需要计算得
|
||||
<span class="token class-name">List</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">Document</span><span class="token punctuation">></span></span> documents <span class="token operator">=</span> documentMapper<span class="token punctuation">.</span><span class="token function">selectList</span><span class="token punctuation">(</span>wrapper<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>documents<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token punctuation">}</span>
|
||||
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br></div></div><p>前端参数页面每传递一行查询参数,我们往sb中append对应参数就完事了,是不是很简单,没错,但是代码不优雅,可咋整? 老汉已经给你们想好出路了,我们提供了工具类,其全路径为:cn.easyes.core.toolkit.QueryUtils
|
||||
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br></div></div><p>前端参数页面每传递一行查询参数,我们往sb中append对应参数就完事了,是不是很简单,没错,但是代码不优雅,可咋整? 老汉已经给你们想好出路了,我们提供了工具类,其全路径为:QueryUtils
|
||||
我们用使用该工具类重构上面的代码,如下:</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code> <span class="token annotation punctuation">@Test</span>
|
||||
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">testQueryStringQueryMulti</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||||
<span class="token class-name">LambdaEsQueryWrapper</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">Document</span><span class="token punctuation">></span></span> wrapper <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">LambdaEsQueryWrapper</span><span class="token generics"><span class="token punctuation"><</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
|
||||
@ -102,7 +102,7 @@ queryStringQuery(String queryString);
|
||||
System.out.println(documents);
|
||||
}
|
||||
```
|
||||
前端参数页面每传递一行查询参数,我们往sb中append对应参数就完事了,是不是很简单,没错,但是代码不优雅,可咋整? 老汉已经给你们想好出路了,我们提供了工具类,其全路径为:cn.easyes.core.toolkit.QueryUtils
|
||||
前端参数页面每传递一行查询参数,我们往sb中append对应参数就完事了,是不是很简单,没错,但是代码不优雅,可咋整? 老汉已经给你们想好出路了,我们提供了工具类,其全路径为:QueryUtils
|
||||
我们用使用该工具类重构上面的代码,如下:
|
||||
```java
|
||||
@Test
|
||||
|
||||
@ -100,7 +100,7 @@ The above picture is taken as an example, I will demonstrate a scenario, please
|
||||
System.out.println(documents);
|
||||
}
|
||||
````
|
||||
Every time a line of query parameters is passed on the front-end parameter page, we append the corresponding parameters to sb and we are done. class, its full path is: cn.easyes.core.toolkit.QueryUtils
|
||||
Every time a line of query parameters is passed on the front-end parameter page, we append the corresponding parameters to sb and we are done. class, its full path is: QueryUtils
|
||||
We refactor the above code using this utility class as follows:
|
||||
````java
|
||||
@Test
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<groupId>org.dromara.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>2.0.0-beta2</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 距离注解
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Distance {
|
||||
/**
|
||||
* 保留小数位,默认不处理,不处理es返回距离,效率更高
|
||||
*
|
||||
* @return 保留小数位
|
||||
*/
|
||||
int decimalPlaces() default 0;
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
|
||||
import cn.easyes.annotation.rely.HighLightTypeEnum;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static cn.easyes.annotation.rely.AnnotationConstants.*;
|
||||
|
||||
|
||||
/**
|
||||
* 字段注解
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface HighLight {
|
||||
/**
|
||||
* 指定的高亮字段名称
|
||||
*
|
||||
* @return 高亮字段名称
|
||||
*/
|
||||
String mappingField() default "";
|
||||
|
||||
/**
|
||||
* 高亮字段截取长度,默认为100
|
||||
*
|
||||
* @return 高亮字段截取长度
|
||||
*/
|
||||
int fragmentSize() default DEFAULT_FRAGMENT_SIZE;
|
||||
|
||||
/**
|
||||
* 高亮前置标签
|
||||
*
|
||||
* @return 高亮前置标签
|
||||
*/
|
||||
String preTag() default HIGH_LIGHT_PRE_TAG;
|
||||
|
||||
/**
|
||||
* 高亮后置标签
|
||||
*
|
||||
* @return 高亮后置标签
|
||||
*/
|
||||
String postTag() default HIGH_LIGHT_POST_TAG;
|
||||
|
||||
/**
|
||||
* 使用的高亮模式
|
||||
*
|
||||
* @return 高亮模式
|
||||
*/
|
||||
HighLightTypeEnum highLightType() default HighLightTypeEnum.UNIFIED;
|
||||
}
|
||||
@ -1,109 +0,0 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
|
||||
import cn.easyes.annotation.rely.*;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 字段注解
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.FIELD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface IndexField {
|
||||
/**
|
||||
* 自定义字段在es中的名称
|
||||
*
|
||||
* @return 字段在es中的名称
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* 是否为数据库表字段 默认 true 存在,false 不存在
|
||||
*
|
||||
* @return 存在
|
||||
*/
|
||||
boolean exist() default true;
|
||||
|
||||
/**
|
||||
* 字段在es索引中的类型,建议根据业务场景指定,若不指定则由本框架自动推断
|
||||
*
|
||||
* @return 类型
|
||||
*/
|
||||
FieldType fieldType() default FieldType.NONE;
|
||||
|
||||
/**
|
||||
* 设置text、keyword_text 可以进行聚合操作
|
||||
*
|
||||
* @return 是否设置可聚合
|
||||
*/
|
||||
boolean fieldData() default false;
|
||||
|
||||
/**
|
||||
* 索引文档时用的分词器
|
||||
*
|
||||
* @return 分词器
|
||||
*/
|
||||
String analyzer() default Analyzer.NONE;
|
||||
|
||||
/**
|
||||
* 查询分词器
|
||||
*
|
||||
* @return 分词器
|
||||
*/
|
||||
String searchAnalyzer() default Analyzer.NONE;
|
||||
|
||||
/**
|
||||
* 字段验证策略
|
||||
*
|
||||
* @return 默认策略
|
||||
*/
|
||||
FieldStrategy strategy() default FieldStrategy.DEFAULT;
|
||||
|
||||
/**
|
||||
* es索引中的日期格式
|
||||
*
|
||||
* @return 日期格式 例如yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
String dateFormat() default "";
|
||||
|
||||
/**
|
||||
* 是否忽略大小写 默认 false 不忽略,为true时则大小写不敏感,都可查
|
||||
*
|
||||
* @return 是否忽略大小写
|
||||
*/
|
||||
boolean ignoreCase() default false;
|
||||
|
||||
/**
|
||||
* 默认嵌套类
|
||||
*
|
||||
* @return 默认嵌套类
|
||||
*/
|
||||
Class<?> nestedClass() default DefaultNestedClass.class;
|
||||
|
||||
/**
|
||||
* 父名称
|
||||
*
|
||||
* @return 父名称
|
||||
*/
|
||||
String parentName() default "";
|
||||
|
||||
/**
|
||||
* 子名称
|
||||
*
|
||||
* @return 子名称
|
||||
*/
|
||||
String childName() default "";
|
||||
|
||||
/**
|
||||
* 父子类型关系字段类 如果使用自定义的类,需要在此处指明,否则采用默认(推荐)
|
||||
*
|
||||
* @return 默认子类
|
||||
*/
|
||||
Class<?> joinFieldClass() default JoinField.class;
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import cn.easyes.annotation.rely.IdType;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 主键注解
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface IndexId {
|
||||
/**
|
||||
* 主键ID
|
||||
*
|
||||
* @return 默认为未设置
|
||||
*/
|
||||
IdType type() default IdType.NONE;
|
||||
}
|
||||
@ -1,84 +0,0 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import cn.easyes.annotation.rely.DefaultChildClass;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static cn.easyes.annotation.rely.AnnotationConstants.*;
|
||||
|
||||
/**
|
||||
* 索引注解
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
|
||||
public @interface IndexName {
|
||||
/**
|
||||
* 实体对应的索引名
|
||||
*
|
||||
* @return 默认为空
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* 分片数
|
||||
*
|
||||
* @return 默认为1
|
||||
*/
|
||||
int shardsNum() default DEFAULT_SHARDS;
|
||||
|
||||
/**
|
||||
* 副本数
|
||||
*
|
||||
* @return 默认为1
|
||||
*/
|
||||
int replicasNum() default DEFAULT_REPLICAS;
|
||||
|
||||
/**
|
||||
* 默认最大返回数
|
||||
*
|
||||
* @return 默认1w条
|
||||
*/
|
||||
int maxResultWindow() default DEFAULT_MAX_RESULT_WINDOW;
|
||||
|
||||
/**
|
||||
* 索引别名
|
||||
*
|
||||
* @return 别名
|
||||
*/
|
||||
String aliasName() default DEFAULT_ALIAS;
|
||||
|
||||
/**
|
||||
* 是否保持使用全局的 tablePrefix 的值
|
||||
* 只生效于 既设置了全局的 tablePrefix 也设置了上面 value 的值
|
||||
* 如果是 false , 全局的 tablePrefix 不生效
|
||||
*
|
||||
* @return 默认为false
|
||||
*/
|
||||
boolean keepGlobalPrefix() default false;
|
||||
|
||||
/**
|
||||
* 父子类型
|
||||
*
|
||||
* @return 是否子文档 默认为否 若为true时,则该类型在自动挡模式下不自动创建索引,与父文档使用同一个索引
|
||||
*/
|
||||
boolean child() default false;
|
||||
|
||||
/**
|
||||
* 父子类型-默认子类
|
||||
*
|
||||
* @return 默认子类
|
||||
*/
|
||||
Class<?> childClass() default DefaultChildClass.class;
|
||||
|
||||
/**
|
||||
* 路由
|
||||
*
|
||||
* @return CRUD作用的路由
|
||||
*/
|
||||
String routing() default "";
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 拦截器
|
||||
* </p>
|
||||
*
|
||||
* @author lilu
|
||||
* @since 2022/3/4
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Intercepts {
|
||||
|
||||
Signature[] value();
|
||||
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 得分注解
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Score {
|
||||
/**
|
||||
* 保留小数位,默认不处理,不处理es得分,效率更高
|
||||
*
|
||||
* @return 保留小数位
|
||||
*/
|
||||
int decimalPlaces() default 0;
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 签名定义
|
||||
* </p>
|
||||
*
|
||||
* @author lilu
|
||||
* @since 2022/3/4
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({})
|
||||
public @interface Signature {
|
||||
|
||||
/**
|
||||
* Returns the java type.
|
||||
*
|
||||
* @return the java type
|
||||
*/
|
||||
Class<?> type();
|
||||
|
||||
/**
|
||||
* Returns the method name.
|
||||
*
|
||||
* @return the method name
|
||||
*/
|
||||
String method();
|
||||
|
||||
/**
|
||||
* Returns java types for method argument.
|
||||
*
|
||||
* @return java types for method argument
|
||||
*/
|
||||
Class<?>[] args();
|
||||
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 分词器 如果不包含用户所需分词器,可自行指定传入字符串
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface Analyzer {
|
||||
/**
|
||||
* 不指定分词器
|
||||
*/
|
||||
String NONE = "none";
|
||||
|
||||
//-----------------内置分词器,直接可以使用----------------
|
||||
/**
|
||||
* 标准分词器
|
||||
*/
|
||||
String STANDARD = "standard";
|
||||
|
||||
/**
|
||||
* 简单分词器
|
||||
*/
|
||||
String SIMPLE = "simple";
|
||||
|
||||
/**
|
||||
* 停用词分词器
|
||||
*/
|
||||
String STOP = "stop";
|
||||
/**
|
||||
* 空格分词器
|
||||
*/
|
||||
String WHITESPACE = "whitespace";
|
||||
/**
|
||||
* 关键词分词器
|
||||
*/
|
||||
String KEYWORD = "keyword";
|
||||
/**
|
||||
* 正则分词器
|
||||
*/
|
||||
String PATTERN = "pattern";
|
||||
/**
|
||||
* 语言分词器
|
||||
* 如:english、french、chinese
|
||||
*/
|
||||
String LANGUAGE = "language";
|
||||
/**
|
||||
* 雪球分词器
|
||||
*/
|
||||
String SNOWBALL = "snowball";
|
||||
|
||||
//-------------三方分词,需要另外安装配置,否则无法使用-------------
|
||||
/**
|
||||
* ik智能分词器
|
||||
*/
|
||||
String IK_SMART = "ik_smart";
|
||||
/**
|
||||
* ik最大拆分分词器
|
||||
*/
|
||||
String IK_MAX_WORD = "ik_max_word";
|
||||
/**
|
||||
* 拼音分词器
|
||||
*/
|
||||
String PINYIN = "pinyin";
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 注解依赖常量
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface AnnotationConstants {
|
||||
/**
|
||||
* 高亮默认前缀标签
|
||||
*/
|
||||
String HIGH_LIGHT_PRE_TAG = "<em>";
|
||||
/**
|
||||
* 高亮默认后缀标签
|
||||
*/
|
||||
String HIGH_LIGHT_POST_TAG = "</em>";
|
||||
/**
|
||||
* 高亮截取默认长度
|
||||
*/
|
||||
int DEFAULT_FRAGMENT_SIZE = 100;
|
||||
/**
|
||||
* 默认分片数
|
||||
*/
|
||||
int DEFAULT_SHARDS = 1;
|
||||
/**
|
||||
* 默认副本数
|
||||
*/
|
||||
int DEFAULT_REPLICAS = 1;
|
||||
/**
|
||||
* 默认最大返回数
|
||||
*/
|
||||
int DEFAULT_MAX_RESULT_WINDOW = 10000;
|
||||
/**
|
||||
* 默认索引别名
|
||||
*/
|
||||
String DEFAULT_ALIAS = "ee_default_alias";
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 父子类型-默认子类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class DefaultChildClass {
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 默认嵌套类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class DefaultNestedClass {
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 字段策略枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public enum FieldStrategy {
|
||||
/**
|
||||
* 忽略判断
|
||||
*/
|
||||
IGNORED,
|
||||
/**
|
||||
* 非NULL判断
|
||||
*/
|
||||
NOT_NULL,
|
||||
/**
|
||||
* 非空判断
|
||||
*/
|
||||
NOT_EMPTY,
|
||||
/**
|
||||
* 默认的,一般只用于注解里
|
||||
*/
|
||||
DEFAULT;
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Es支持的数据类型枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public enum FieldType {
|
||||
/**
|
||||
* none Required inside the framework, do not use 框架内部需要,切勿使用,若不慎使用则会被当做keyword类型
|
||||
*/
|
||||
NONE("none"),
|
||||
/**
|
||||
* core
|
||||
*/
|
||||
BYTE("byte"),
|
||||
SHORT("short"),
|
||||
INTEGER("integer"),
|
||||
LONG("long"),
|
||||
FLOAT("float"),
|
||||
DOUBLE("double"),
|
||||
HALF_FLOAT("half_float"),
|
||||
SCALED_FLOAT("scaled_float"),
|
||||
BOOLEAN("boolean"),
|
||||
DATE("date"),
|
||||
RANGE("range"),
|
||||
BINARY("binary"),
|
||||
KEYWORD("keyword"),
|
||||
TEXT("text"),
|
||||
KEYWORD_TEXT("keyword&text"),
|
||||
WILDCARD("wildcard"),
|
||||
/**
|
||||
* mix
|
||||
*/
|
||||
/**
|
||||
* If it is an array, configure its field type to text, and use match for query,如果是数组,请配置其字段类型为text,查询用match
|
||||
*/
|
||||
@Deprecated
|
||||
ARRAY("array"),
|
||||
/**
|
||||
* If it is an object, configure its field type as nested, and indicate nested Class,如果是对象,请配置其字段类型为nested,并在@IndexField注解中指明nestedClass
|
||||
*/
|
||||
@Deprecated
|
||||
OBJECT("object"),
|
||||
NESTED("nested"),
|
||||
JOIN("join"),
|
||||
/**
|
||||
* geo
|
||||
*/
|
||||
GEO_POINT("geo_point"),
|
||||
GEO_SHAPE("geo_shape"),
|
||||
/**
|
||||
* special
|
||||
*/
|
||||
IP("ip"),
|
||||
COMPLETION("completion"),
|
||||
TOKEN("token"),
|
||||
ATTACHMENT("attachment"),
|
||||
PERCOLATOR("percolator");
|
||||
|
||||
private String type;
|
||||
|
||||
FieldType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型字符串获取对应枚举
|
||||
*
|
||||
* @param type 类型字符串
|
||||
* @return 对应枚举
|
||||
*/
|
||||
public static FieldType getByType(String type) {
|
||||
return Arrays.stream(FieldType.values())
|
||||
.filter(v -> v.getType().equals(type))
|
||||
.findFirst()
|
||||
.orElse(FieldType.KEYWORD_TEXT);
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 高亮类型枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
|
||||
public enum HighLightTypeEnum {
|
||||
/**
|
||||
* unified(通用高亮策略,缺省配置时,默认采用此策略)
|
||||
* 其使用的是Lucene的Unified Highlighter。此高亮策略将文本分解成句子,并使用BM25算法对单个句子进行评分,支持精确的短语和多术语(模糊、前缀、正则表达式)突出显示。这个是默认的高亮策略。
|
||||
*/
|
||||
UNIFIED("unified"),
|
||||
/**
|
||||
* plain (普通高亮策略)
|
||||
* 其使用的是Lucene的standard Lucene highlighter。
|
||||
* 它试图在理解词的重要性和短语查询中的任何词定位标准方面反映查询匹配逻辑。
|
||||
* 此高亮策略是和在单个字段中突出显示简单的查询匹配。如果想用复杂的查询在很多文档中突出显示很多字段,还是使用unified
|
||||
*/
|
||||
PLAIN("plain"),
|
||||
/**
|
||||
* Fast vector highlighter(快速向量策略)
|
||||
* 其使用的是Lucene的Fast Vector highlighter。
|
||||
* 注意:使用此策略需要在映射中将对应字段中的属性term_vector设置为with_positions_offsets。
|
||||
*/
|
||||
FVH("fvh");
|
||||
|
||||
/**
|
||||
* 聚合类型英文名
|
||||
*/
|
||||
private final String value;
|
||||
|
||||
HighLightTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 主键类型枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public enum IdType {
|
||||
/**
|
||||
* 该类型为未设置主键类型,由es自动生成
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* 全局唯一ID (UUID)
|
||||
*/
|
||||
UUID,
|
||||
/**
|
||||
* 用户自定义,由用户传入
|
||||
*/
|
||||
CUSTOMIZE;
|
||||
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 父子类型统一关系字段,推荐直接使用此类,不要重复造轮子
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class JoinField {
|
||||
/**
|
||||
* 字段名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 父文档id
|
||||
*/
|
||||
private String parent;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(String parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JoinField{" +
|
||||
"name='" + name + '\'' +
|
||||
", parent='" + parent + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@
|
||||
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">
|
||||
<parent>
|
||||
<groupId>org.dromara.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<version>2.0.0-beta2</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<groupId>org.dromara.easy-es</groupId>
|
||||
<artifactId>easy-es-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
package cn.easyes.starter.config;
|
||||
|
||||
import cn.easyes.core.config.GlobalConfig;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* easy-es基础配置项
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(value = "easy-es")
|
||||
@ConditionalOnProperty(prefix = "easy-es", name = {"enable"}, havingValue = "true", matchIfMissing = true)
|
||||
public class EasyEsConfigProperties {
|
||||
/**
|
||||
* 是否开启easy-es 默认开启
|
||||
*/
|
||||
private boolean enable = true;
|
||||
/**
|
||||
* 是否开启easy-es LOGO BANNER的打印
|
||||
*/
|
||||
private boolean banner = true;
|
||||
/**
|
||||
* es client address es客户端地址
|
||||
*/
|
||||
private String address = "127.0.0.1:9200";
|
||||
/**
|
||||
* schema 模式
|
||||
*/
|
||||
private String schema = "http";
|
||||
/**
|
||||
* username of es 用户名,可缺省
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* password of es 密码,可缺省
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* maxConnectTotal 最大连接数
|
||||
*/
|
||||
private Integer maxConnTotal;
|
||||
/**
|
||||
* maxConnectPerRoute 最大连接路由数
|
||||
*/
|
||||
private Integer maxConnPerRoute;
|
||||
/**
|
||||
* connectTimeout timeUnit:millis 连接超时时间 单位毫秒
|
||||
*/
|
||||
private Integer connectTimeout;
|
||||
/**
|
||||
* socketTimeout timeUnit:millis 通讯超时时间 单位毫秒 默认10分钟 以免小白踩坑平滑模式下数据量过大迁移超时失败
|
||||
*/
|
||||
private Integer socketTimeout = 600000;
|
||||
/***
|
||||
* 保持心跳时间 timeUnit:millis 单位毫秒 默认30秒 防止小白白出现服务首次调用不成时不知所措
|
||||
*/
|
||||
private Integer keepAliveMillis = 30000;
|
||||
/**
|
||||
* connectionRequestTimeout timeUnit:millis 连接请求超时时间 单位毫秒
|
||||
*/
|
||||
private Integer connectionRequestTimeout;
|
||||
/**
|
||||
* global config 全局配置
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private GlobalConfig globalConfig = new GlobalConfig();
|
||||
}
|
||||
@ -1,101 +0,0 @@
|
||||
package cn.easyes.starter.config;
|
||||
|
||||
import cn.easyes.common.utils.ExceptionUtils;
|
||||
import cn.easyes.common.utils.RestHighLevelClientBuilder;
|
||||
import cn.easyes.common.utils.StringUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.easyes.common.constants.BaseEsConstants.COLON;
|
||||
import static cn.easyes.common.constants.BaseEsConstants.DEFAULT_SCHEMA;
|
||||
|
||||
/**
|
||||
* es自动配置
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Configuration
|
||||
@ConditionalOnClass(RestHighLevelClient.class)
|
||||
@EnableConfigurationProperties(EasyEsConfigProperties.class)
|
||||
@ConditionalOnProperty(prefix = "easy-es", name = {"enable"}, havingValue = "true", matchIfMissing = true)
|
||||
public class EsAutoConfiguration {
|
||||
@Autowired
|
||||
private EasyEsConfigProperties easyEsConfigProperties;
|
||||
|
||||
/**
|
||||
* 装配RestHighLevelClient
|
||||
*
|
||||
* @return RestHighLevelClient bean
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public RestHighLevelClient restHighLevelClient() {
|
||||
// 处理地址
|
||||
String address = easyEsConfigProperties.getAddress();
|
||||
if (StringUtils.isEmpty(address)) {
|
||||
throw ExceptionUtils.eee("please config the es address");
|
||||
}
|
||||
if (!address.contains(COLON)) {
|
||||
throw ExceptionUtils.eee("the address must contains port and separate by ':'");
|
||||
}
|
||||
String schema = StringUtils.isEmpty(easyEsConfigProperties.getSchema())
|
||||
? DEFAULT_SCHEMA : easyEsConfigProperties.getSchema();
|
||||
List<HttpHost> hostList = new ArrayList<>();
|
||||
Arrays.stream(easyEsConfigProperties.getAddress().split(","))
|
||||
.forEach(item -> hostList.add(new HttpHost(item.split(":")[0],
|
||||
Integer.parseInt(item.split(":")[1]), schema)));
|
||||
|
||||
// 转换成 HttpHost 数组
|
||||
HttpHost[] httpHost = hostList.toArray(new HttpHost[]{});
|
||||
|
||||
// 构建连接对象
|
||||
RestClientBuilder builder = RestClient.builder(httpHost);
|
||||
builder.setHttpClientConfigCallback(httpClientBuilder -> {
|
||||
// 设置心跳时间,最大连接数,最大连接路由
|
||||
Optional.ofNullable(easyEsConfigProperties.getKeepAliveMillis()).ifPresent(p -> httpClientBuilder.setKeepAliveStrategy((response, context) -> p));
|
||||
Optional.ofNullable(easyEsConfigProperties.getMaxConnTotal()).ifPresent(httpClientBuilder::setMaxConnTotal);
|
||||
Optional.ofNullable(easyEsConfigProperties.getMaxConnPerRoute()).ifPresent(httpClientBuilder::setMaxConnPerRoute);
|
||||
|
||||
// 设置账号密码
|
||||
String username = easyEsConfigProperties.getUsername();
|
||||
String password = easyEsConfigProperties.getPassword();
|
||||
if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
|
||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
credentialsProvider.setCredentials(AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(username, password));
|
||||
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
|
||||
}
|
||||
return httpClientBuilder;
|
||||
});
|
||||
|
||||
// 设置超时时间之类的
|
||||
builder.setRequestConfigCallback(requestConfigBuilder -> {
|
||||
Optional.ofNullable(easyEsConfigProperties.getConnectTimeout()).ifPresent(requestConfigBuilder::setConnectTimeout);
|
||||
Optional.ofNullable(easyEsConfigProperties.getSocketTimeout()).ifPresent(requestConfigBuilder::setSocketTimeout);
|
||||
Optional.ofNullable(easyEsConfigProperties.getConnectionRequestTimeout())
|
||||
.ifPresent(requestConfigBuilder::setConnectionRequestTimeout);
|
||||
return requestConfigBuilder;
|
||||
});
|
||||
|
||||
return RestHighLevelClientBuilder.build(builder);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
package cn.easyes.starter.factory;
|
||||
|
||||
|
||||
import cn.easyes.starter.config.EasyEsConfigProperties;
|
||||
import cn.easyes.starter.service.AutoProcessIndexService;
|
||||
import cn.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||
import cn.easyes.common.utils.ExceptionUtils;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 自动托管索引策略工厂
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Component
|
||||
@ConditionalOnClass(RestHighLevelClient.class)
|
||||
@ConditionalOnProperty(prefix = "easy-es", name = {"enable"}, havingValue = "true", matchIfMissing = true)
|
||||
public class IndexStrategyFactory implements ApplicationContextAware, InitializingBean {
|
||||
/**
|
||||
* 配置
|
||||
*/
|
||||
@Autowired
|
||||
private EasyEsConfigProperties esConfigProperties;
|
||||
/**
|
||||
* 预估初始策略工厂容量
|
||||
*/
|
||||
private static final Integer DEFAULT_SIZE = 4;
|
||||
/**
|
||||
* spring上下文
|
||||
*/
|
||||
private ApplicationContext applicationContext;
|
||||
/**
|
||||
* 策略容器
|
||||
*/
|
||||
private static final Map<Integer, AutoProcessIndexService> SERVICE_MAP = new HashMap<>(DEFAULT_SIZE);
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
// 是否开启自动托管模式,默认开启
|
||||
if (!ProcessIndexStrategyEnum.MANUAL.equals(esConfigProperties.getGlobalConfig().getProcessIndexMode())) {
|
||||
// 将bean注册进工厂
|
||||
applicationContext.getBeansOfType(AutoProcessIndexService.class)
|
||||
.values()
|
||||
.forEach(v -> SERVICE_MAP.putIfAbsent(v.getStrategyType(), v));
|
||||
}
|
||||
}
|
||||
|
||||
public AutoProcessIndexService getByStrategyType(Integer strategyType) {
|
||||
return Optional.ofNullable(SERVICE_MAP.get(strategyType))
|
||||
.orElseThrow(() -> ExceptionUtils.eee("no such service strategyType:{}", strategyType));
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,95 +0,0 @@
|
||||
package cn.easyes.starter.register;
|
||||
|
||||
import cn.easyes.core.core.BaseEsMapper;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 扫描指定路径下的所有接口
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner {
|
||||
public ClassPathMapperScanner(BeanDefinitionRegistry registry) {
|
||||
super(registry, false);
|
||||
}
|
||||
|
||||
public void registerFilters() {
|
||||
// default include filter that accepts all classes
|
||||
addIncludeFilter((metadataReader, metadataReaderFactory) -> {
|
||||
// 跳过非ee的mapper,比如瞎几把写的接口,没有继承BaseEsMapper
|
||||
String className = metadataReader.getClassMetadata().getClassName();
|
||||
try {
|
||||
Class<?> clazz = Class.forName(className);
|
||||
return BaseEsMapper.class.isAssignableFrom(clazz);
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.debug("mapper not found" + e);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// exclude package-info.java
|
||||
addExcludeFilter((metadataReader, metadataReaderFactory) -> {
|
||||
String className = metadataReader.getClassMetadata().getClassName();
|
||||
return className.endsWith("package-info");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
|
||||
Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
|
||||
if (beanDefinitions.isEmpty()) {
|
||||
logger.warn("No Easy-Es mapper was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration.");
|
||||
} else {
|
||||
processBeanDefinitions(beanDefinitions);
|
||||
}
|
||||
return beanDefinitions;
|
||||
}
|
||||
|
||||
private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
|
||||
GenericBeanDefinition definition;
|
||||
for (BeanDefinitionHolder holder : beanDefinitions) {
|
||||
definition = (GenericBeanDefinition) holder.getBeanDefinition();
|
||||
String beanClassName = definition.getBeanClassName();
|
||||
logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName()
|
||||
+ "' and '" + beanClassName + "' mapperInterface");
|
||||
|
||||
// the mapper interface is the original class of the bean
|
||||
// but, the actual class of the bean is MapperFactoryBean
|
||||
definition.getConstructorArgumentValues().addGenericArgumentValue(beanClassName);
|
||||
definition.setBeanClass(MapperFactoryBean.class);
|
||||
|
||||
logger.debug("Enabling autowire by type for MapperFactoryBean with name '" + holder.getBeanName() + "'.");
|
||||
definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
|
||||
return beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition) {
|
||||
if (super.checkCandidate(beanName, beanDefinition)) {
|
||||
return true;
|
||||
} else {
|
||||
logger.warn("Skipping MapperFactoryBean with name '" + beanName
|
||||
+ "' and '" + beanDefinition.getBeanClassName() + "' mapperInterface"
|
||||
+ ". Bean already defined with the same name!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package cn.easyes.starter.register;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 全局Mapper扫描注解
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Import(MapperScannerRegister.class)
|
||||
public @interface EsMapperScan {
|
||||
String value();
|
||||
}
|
||||
@ -1,125 +0,0 @@
|
||||
package cn.easyes.starter.register;
|
||||
|
||||
import cn.easyes.annotation.Intercepts;
|
||||
import cn.easyes.annotation.rely.DefaultChildClass;
|
||||
import cn.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||
import cn.easyes.common.utils.LogUtils;
|
||||
import cn.easyes.common.utils.TypeUtils;
|
||||
import cn.easyes.core.biz.EntityInfo;
|
||||
import cn.easyes.core.cache.BaseCache;
|
||||
import cn.easyes.core.cache.GlobalConfigCache;
|
||||
import cn.easyes.core.config.GlobalConfig;
|
||||
import cn.easyes.core.proxy.EsMapperProxy;
|
||||
import cn.easyes.core.toolkit.EntityInfoHelper;
|
||||
import cn.easyes.extension.context.Interceptor;
|
||||
import cn.easyes.extension.context.InterceptorChain;
|
||||
import cn.easyes.extension.context.InterceptorChainHolder;
|
||||
import cn.easyes.starter.config.EasyEsConfigProperties;
|
||||
import cn.easyes.starter.factory.IndexStrategyFactory;
|
||||
import cn.easyes.starter.service.AutoProcessIndexService;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 代理类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class MapperFactoryBean<T> implements FactoryBean<T> {
|
||||
private Class<T> mapperInterface;
|
||||
|
||||
@Autowired
|
||||
private RestHighLevelClient client;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
private IndexStrategyFactory indexStrategyFactory;
|
||||
|
||||
@Autowired
|
||||
private EasyEsConfigProperties esConfigProperties;
|
||||
|
||||
public MapperFactoryBean() {
|
||||
}
|
||||
|
||||
public MapperFactoryBean(Class<T> mapperInterface) {
|
||||
this.mapperInterface = mapperInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getObject() throws Exception {
|
||||
|
||||
EsMapperProxy<T> esMapperProxy = new EsMapperProxy<>(mapperInterface);
|
||||
|
||||
// 获取实体类
|
||||
Class<?> entityClass = TypeUtils.getInterfaceT(mapperInterface, 0);
|
||||
|
||||
// 初始化缓存
|
||||
GlobalConfigCache.setGlobalConfig(esConfigProperties.getGlobalConfig());
|
||||
BaseCache.initCache(mapperInterface, entityClass, client);
|
||||
|
||||
// 创建代理
|
||||
T t = (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[]{mapperInterface}, esMapperProxy);
|
||||
|
||||
// 初始化拦截器链
|
||||
InterceptorChain interceptorChain = this.initInterceptorChain();
|
||||
|
||||
// 异步处理索引创建/更新/数据迁移等
|
||||
GlobalConfig globalConfig = esConfigProperties.getGlobalConfig();
|
||||
if (!ProcessIndexStrategyEnum.MANUAL.equals(globalConfig.getProcessIndexMode())) {
|
||||
// 父子类型,仅针对父类型创建索引,子类型不创建索引
|
||||
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
||||
if (!entityInfo.isChild()) {
|
||||
AutoProcessIndexService autoProcessIndexService = indexStrategyFactory
|
||||
.getByStrategyType(globalConfig.getProcessIndexMode().getStrategyType());
|
||||
autoProcessIndexService.processIndexAsync(entityClass, client);
|
||||
|
||||
// 将子文档索引激活为父文档索引
|
||||
if (!DefaultChildClass.class.equals(entityInfo.getChildClass())) {
|
||||
Optional.ofNullable(entityInfo.getChildClass())
|
||||
.flatMap(childClass -> Optional.ofNullable(EntityInfoHelper.getEntityInfo(childClass)))
|
||||
.ifPresent(childEntityInfo -> childEntityInfo.setIndexName(entityInfo.getIndexName()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LogUtils.info("===> manual index mode activated");
|
||||
}
|
||||
return interceptorChain.pluginAll(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return this.mapperInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private InterceptorChain initInterceptorChain() {
|
||||
InterceptorChainHolder interceptorChainHolder = InterceptorChainHolder.getInstance();
|
||||
InterceptorChain interceptorChain = interceptorChainHolder.getInterceptorChain();
|
||||
if (interceptorChain == null) {
|
||||
synchronized (this) {
|
||||
interceptorChainHolder.initInterceptorChain();
|
||||
Map<String, Object> beansWithAnnotation = this.applicationContext.getBeansWithAnnotation(Intercepts.class);
|
||||
beansWithAnnotation.forEach((key, val) -> {
|
||||
if (val instanceof Interceptor) {
|
||||
Interceptor interceptor = (Interceptor) val;
|
||||
interceptorChainHolder.addInterceptor(interceptor);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return interceptorChainHolder.getInterceptorChain();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,106 +0,0 @@
|
||||
package cn.easyes.starter.register;
|
||||
|
||||
import cn.easyes.common.utils.EEVersionUtils;
|
||||
import cn.easyes.common.utils.LogUtils;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.easyes.common.constants.BaseEsConstants.ENABLE_BANNER;
|
||||
import static cn.easyes.common.constants.BaseEsConstants.ENABLE_PREFIX;
|
||||
|
||||
/**
|
||||
* 注册bean
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware {
|
||||
private ResourceLoader resourceLoader;
|
||||
private Environment environment;
|
||||
|
||||
@Override
|
||||
public void setResourceLoader(ResourceLoader resourceLoader) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
||||
Boolean enable = Optional.ofNullable(environment.getProperty(ENABLE_PREFIX)).map(Boolean::parseBoolean).orElse(Boolean.TRUE);
|
||||
if (!enable) {
|
||||
LogUtils.info("===> Easy-Es is not enabled");
|
||||
return;
|
||||
}
|
||||
|
||||
//打印banner @author dazer007
|
||||
boolean banner = Optional.ofNullable(environment.getProperty(ENABLE_BANNER)).map(Boolean::parseBoolean).orElse(Boolean.TRUE);
|
||||
if (banner) {
|
||||
String versionStr = EEVersionUtils.getJarVersion(this.getClass());
|
||||
System.out.println("\n" +
|
||||
"___ _ _ ___\n" +
|
||||
" | __| __ _ ___ | || | ___ | __| ___\n" +
|
||||
" | _| / _` | (_-< \\_, | |___| | _| (_-<\n" +
|
||||
" |___| \\__,_| /__/_ _|__/ _____ |___| /__/_\n" +
|
||||
"_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_| \"\"\"\"|_| |_|\"\"\"\"\"|_|\"\"\"\"\"|\n" +
|
||||
"\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\n" +
|
||||
"------------------------------------------------------>"
|
||||
);
|
||||
|
||||
// 版本长度并不固定,比如beta版,所以需要特殊处理
|
||||
int width = 38;
|
||||
int blank = width - versionStr.length();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(":: version :: ")
|
||||
.append(versionStr);
|
||||
for (int i = 0; i < blank; i++) {
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append(">");
|
||||
System.out.println(sb);
|
||||
System.out.println(":: home :: https://easy-es.cn/ >");
|
||||
System.out.println(":: community :: https://dromara.org/ >");
|
||||
System.out.println(":: wechat :: 252645816, add and become muscle man! >");
|
||||
System.out.println("------------------------------------------------------>");
|
||||
}
|
||||
|
||||
AnnotationAttributes mapperScanAttrs = AnnotationAttributes
|
||||
.fromMap(importingClassMetadata.getAnnotationAttributes(EsMapperScan.class.getName()));
|
||||
if (mapperScanAttrs != null) {
|
||||
registerBeanDefinitions(mapperScanAttrs, registry);
|
||||
}
|
||||
}
|
||||
|
||||
void registerBeanDefinitions(AnnotationAttributes annoAttrs, BeanDefinitionRegistry registry) {
|
||||
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
|
||||
// this check is needed in Spring 3.1
|
||||
Optional.ofNullable(resourceLoader).ifPresent(scanner::setResourceLoader);
|
||||
List<String> basePackages = new ArrayList<>();
|
||||
basePackages.addAll(
|
||||
Arrays.stream(annoAttrs.getStringArray("value"))
|
||||
.filter(StringUtils::hasText)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
scanner.registerFilters();
|
||||
scanner.doScan(StringUtils.toStringArray(basePackages));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("252645816, add and become muscle man! >".length());
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package cn.easyes.starter.service;
|
||||
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
/**
|
||||
* 自动托管索引接口
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface AutoProcessIndexService {
|
||||
/**
|
||||
* 获取当前策略类型
|
||||
*
|
||||
* @return 策略类型
|
||||
*/
|
||||
Integer getStrategyType();
|
||||
|
||||
/**
|
||||
* 异步处理索引
|
||||
*
|
||||
* @param entityClass 实体类
|
||||
* @param client restHighLevelClient
|
||||
*/
|
||||
void processIndexAsync(Class<?> entityClass, RestHighLevelClient client);
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
package cn.easyes.starter.service.impl;
|
||||
|
||||
import cn.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||
import cn.easyes.common.utils.LogUtils;
|
||||
import cn.easyes.core.biz.CreateIndexParam;
|
||||
import cn.easyes.core.biz.EntityInfo;
|
||||
import cn.easyes.core.biz.EsIndexInfo;
|
||||
import cn.easyes.core.toolkit.EntityInfoHelper;
|
||||
import cn.easyes.core.toolkit.IndexUtils;
|
||||
import cn.easyes.starter.service.AutoProcessIndexService;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 自动非平滑托管索引实现类, 重建索引时原索引数据会被删除
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Service
|
||||
@ConditionalOnClass(RestHighLevelClient.class)
|
||||
@ConditionalOnProperty(prefix = "easy-es", name = {"enable"}, havingValue = "true", matchIfMissing = true)
|
||||
public class AutoProcessIndexNotSmoothlyServiceImpl implements AutoProcessIndexService {
|
||||
|
||||
@Override
|
||||
public Integer getStrategyType() {
|
||||
return ProcessIndexStrategyEnum.NOT_SMOOTHLY.getStrategyType();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processIndexAsync(Class<?> entityClass, RestHighLevelClient client) {
|
||||
LogUtils.info("===> Not smoothly process index mode activated");
|
||||
IndexUtils.supplyAsync(this::process, entityClass, client);
|
||||
}
|
||||
|
||||
private boolean process(Class<?> entityClass, RestHighLevelClient client) {
|
||||
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
||||
// 是否存在索引
|
||||
boolean existsIndex = IndexUtils.existsIndexWithRetry(entityInfo, client);
|
||||
if (existsIndex) {
|
||||
// 更新
|
||||
LogUtils.info("===> Index exists, automatically updating index by easy-es...");
|
||||
return doUpdateIndex(entityInfo, client);
|
||||
} else {
|
||||
// 新建
|
||||
LogUtils.info("===> Index not exists, automatically creating index by easy-es...");
|
||||
return doCreateIndex(entityInfo, client);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doUpdateIndex(EntityInfo entityInfo, RestHighLevelClient client) {
|
||||
// 获取索引信息
|
||||
EsIndexInfo esIndexInfo = IndexUtils.getIndexInfo(client, entityInfo.getRetrySuccessIndexName());
|
||||
|
||||
// 索引是否有变化 若有则直接删除旧索引,创建新索引 若无则直接返回托管成功
|
||||
boolean isIndexNeedChange = IndexUtils.isIndexNeedChange(esIndexInfo, entityInfo);
|
||||
if (!isIndexNeedChange) {
|
||||
LogUtils.info("===> index has nothing changed");
|
||||
entityInfo.setIndexName(entityInfo.getRetrySuccessIndexName());
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
// 直接删除旧索引
|
||||
IndexUtils.deleteIndex(client, entityInfo.getRetrySuccessIndexName());
|
||||
|
||||
// 初始化创建索引参数
|
||||
CreateIndexParam createIndexParam = IndexUtils.getCreateIndexParam(entityInfo);
|
||||
|
||||
// 执行创建
|
||||
return IndexUtils.createIndex(client, entityInfo, createIndexParam);
|
||||
}
|
||||
|
||||
private boolean doCreateIndex(EntityInfo entityInfo, RestHighLevelClient client) {
|
||||
// 初始化创建索引参数
|
||||
CreateIndexParam createIndexParam = IndexUtils.getCreateIndexParam(entityInfo);
|
||||
|
||||
// 执行创建
|
||||
return IndexUtils.createIndex(client, entityInfo, createIndexParam);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,134 +0,0 @@
|
||||
package cn.easyes.starter.service.impl;
|
||||
|
||||
import cn.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||
import cn.easyes.common.utils.LogUtils;
|
||||
import cn.easyes.core.biz.CreateIndexParam;
|
||||
import cn.easyes.core.biz.EntityInfo;
|
||||
import cn.easyes.core.biz.EsIndexInfo;
|
||||
import cn.easyes.core.toolkit.EntityInfoHelper;
|
||||
import cn.easyes.core.toolkit.IndexUtils;
|
||||
import cn.easyes.starter.service.AutoProcessIndexService;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static cn.easyes.common.constants.BaseEsConstants.S1_SUFFIX;
|
||||
import static cn.easyes.common.constants.BaseEsConstants.SO_SUFFIX;
|
||||
|
||||
/**
|
||||
* 自动平滑托管索引实现类,本框架默认模式,过程零停机,数据会自动转移至新索引
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Service
|
||||
@ConditionalOnClass(RestHighLevelClient.class)
|
||||
@ConditionalOnProperty(prefix = "easy-es", name = {"enable"}, havingValue = "true", matchIfMissing = true)
|
||||
public class AutoProcessIndexSmoothlyServiceImpl implements AutoProcessIndexService {
|
||||
@Override
|
||||
public Integer getStrategyType() {
|
||||
return ProcessIndexStrategyEnum.SMOOTHLY.getStrategyType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processIndexAsync(Class<?> entityClass, RestHighLevelClient client) {
|
||||
LogUtils.info("===> Smoothly process index mode activated");
|
||||
IndexUtils.supplyAsync(this::process, entityClass, client);
|
||||
}
|
||||
|
||||
|
||||
private synchronized boolean process(Class<?> entityClass, RestHighLevelClient client) {
|
||||
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
||||
|
||||
// 索引是否已存在
|
||||
boolean existsIndex = IndexUtils.existsIndexWithRetryAndSetActiveIndex(entityInfo, client);
|
||||
if (existsIndex) {
|
||||
// 更新
|
||||
LogUtils.info("===> Index exists, automatically updating index by easy-es...");
|
||||
return doUpdateIndex(entityInfo, client);
|
||||
} else {
|
||||
// 新建
|
||||
LogUtils.info("===> Index not exists, automatically creating index by easy-es...");
|
||||
return doCreateIndex(entityInfo, client);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean doUpdateIndex(EntityInfo entityInfo, RestHighLevelClient client) {
|
||||
// 获取索引信息
|
||||
EsIndexInfo esIndexInfo = IndexUtils.getIndexInfo(client, entityInfo.getIndexName());
|
||||
|
||||
// 是否存在默认别名,若无则给添加
|
||||
if (!esIndexInfo.getHasDefaultAlias()) {
|
||||
IndexUtils.addDefaultAlias(client, entityInfo.getIndexName());
|
||||
}
|
||||
|
||||
// 索引是否有变化 若有则创建新索引并无感迁移, 若无则直接返回托管成功
|
||||
boolean isIndexNeedChange = IndexUtils.isIndexNeedChange(esIndexInfo, entityInfo);
|
||||
if (!isIndexNeedChange) {
|
||||
LogUtils.info("===> index has nothing changed");
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
// 创建新索引
|
||||
String releaseIndexName = generateReleaseIndexName(entityInfo.getIndexName());
|
||||
entityInfo.setReleaseIndexName(releaseIndexName);
|
||||
boolean isCreateIndexSuccess = doCreateIndex(entityInfo, client);
|
||||
if (!isCreateIndexSuccess) {
|
||||
LogUtils.error("create release index failed", "releaseIndex:" + releaseIndexName);
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
// 迁移数据至新创建的索引
|
||||
boolean isDataMigrationSuccess = doDataMigration(entityInfo.getIndexName(), releaseIndexName, client);
|
||||
if (!isDataMigrationSuccess) {
|
||||
LogUtils.error("migrate data failed", "oldIndex:" + entityInfo.getIndexName(), "releaseIndex:" + releaseIndexName);
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
// 原子操作 切换别名:将默认别名关联至新索引,并将旧索引的默认别名移除
|
||||
boolean isChangeAliasSuccess = IndexUtils.changeAliasAtomic(client, entityInfo.getIndexName(), releaseIndexName);
|
||||
if (!isChangeAliasSuccess) {
|
||||
LogUtils.error("change alias atomically failed", "oldIndex:" + entityInfo.getIndexName(), "releaseIndex:" + releaseIndexName);
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
// 删除旧索引
|
||||
boolean isDeletedIndexSuccess = IndexUtils.deleteIndex(client, entityInfo.getIndexName());
|
||||
if (!isDeletedIndexSuccess) {
|
||||
LogUtils.error("delete old index failed", "oldIndex:" + entityInfo.getIndexName());
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
// 用最新索引覆盖缓存中的老索引
|
||||
entityInfo.setIndexName(releaseIndexName);
|
||||
|
||||
// 将新索引名称记录至ee-distribute-lock索引中,以便在分布式环境下其它机器能够感知到
|
||||
IndexUtils.saveReleaseIndex(releaseIndexName,client);
|
||||
|
||||
// done.
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private String generateReleaseIndexName(String oldIndexName) {
|
||||
if (oldIndexName.endsWith(SO_SUFFIX)) {
|
||||
return oldIndexName.split(SO_SUFFIX)[0] + S1_SUFFIX;
|
||||
} else if (oldIndexName.endsWith(S1_SUFFIX)) {
|
||||
return oldIndexName.split(S1_SUFFIX)[0] + SO_SUFFIX;
|
||||
} else {
|
||||
return oldIndexName + SO_SUFFIX;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doDataMigration(String oldIndexName, String releaseIndexName, RestHighLevelClient client) {
|
||||
return IndexUtils.reindex(client, oldIndexName, releaseIndexName);
|
||||
}
|
||||
|
||||
private boolean doCreateIndex(EntityInfo entityInfo, RestHighLevelClient client) {
|
||||
// 初始化创建索引参数
|
||||
CreateIndexParam createIndexParam = IndexUtils.getCreateIndexParam(entityInfo);
|
||||
// 执行创建
|
||||
return IndexUtils.createIndex(client, entityInfo, createIndexParam);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
# Auto Configure
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.easyes.starter.config.EsAutoConfiguration,\
|
||||
cn.easyes.starter.factory.IndexStrategyFactory,\
|
||||
cn.easyes.starter.service.impl.AutoProcessIndexSmoothlyServiceImpl,\
|
||||
cn.easyes.starter.service.impl.AutoProcessIndexNotSmoothlyServiceImpl
|
||||
org.dromara.easyes.starter.config.EsAutoConfiguration,\
|
||||
org.dromara.easyes.starter.factory.IndexStrategyFactory,\
|
||||
org.dromara.easyes.starter.service.impl.AutoProcessIndexSmoothlyServiceImpl,\
|
||||
org.dromara.easyes.starter.service.impl.AutoProcessIndexNotSmoothlyServiceImpl
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
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>cn.easy-es</groupId>
|
||||
<groupId>org.dromara.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>2.0.0-beta2</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
|
||||
@ -1,243 +0,0 @@
|
||||
package cn.easyes.common.constants;
|
||||
|
||||
/**
|
||||
* EasyEs的常量
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface BaseEsConstants {
|
||||
/**
|
||||
* 是否启用本框架前缀, 默认启用
|
||||
*/
|
||||
String ENABLE_PREFIX = "easy-es.enable";
|
||||
/**
|
||||
* 是否打印本框架Banner
|
||||
*/
|
||||
String ENABLE_BANNER = "easy-es.banner";
|
||||
/**
|
||||
* 默认主键名称
|
||||
*/
|
||||
String DEFAULT_ID_NAME = "id";
|
||||
/**
|
||||
* Es 默认的主键名称
|
||||
*/
|
||||
String DEFAULT_ES_ID_NAME = "_id";
|
||||
/**
|
||||
* 数字0
|
||||
*/
|
||||
Integer ZERO = 0;
|
||||
/**
|
||||
* 数字1
|
||||
*/
|
||||
Integer ONE = 1;
|
||||
/**
|
||||
* 数字-1
|
||||
*/
|
||||
Integer MINUS_ONE = -1;
|
||||
|
||||
/**
|
||||
* 默认的当前页码
|
||||
*/
|
||||
Integer PAGE_NUM = 1;
|
||||
/**
|
||||
* 默认的每页显示条目数
|
||||
*/
|
||||
Integer PAGE_SIZE = 10;
|
||||
/**
|
||||
* 默认字段boost权重
|
||||
*/
|
||||
Float DEFAULT_BOOST = 1.0F;
|
||||
/**
|
||||
* 空字符串
|
||||
*/
|
||||
String EMPTY_STR = "";
|
||||
/**
|
||||
* 冒号
|
||||
*/
|
||||
String COLON = ":";
|
||||
/**
|
||||
* 百分号
|
||||
*/
|
||||
String PERCENT_SIGN = "%";
|
||||
/**
|
||||
* ee内置es分布式锁索引名称
|
||||
*/
|
||||
String LOCK_INDEX = "ee-distribute-lock";
|
||||
/**
|
||||
* 当前激活索引key
|
||||
*/
|
||||
String ACTIVE_INDEX_KEY = "ee_active_index_key";
|
||||
/**
|
||||
* 索引更新时间key
|
||||
*/
|
||||
String GMT_MODIFIED = "gmt_modified";
|
||||
/**
|
||||
* get 方法前缀
|
||||
*/
|
||||
String GET_FUNC_PREFIX = "get";
|
||||
/**
|
||||
* set 方法前缀
|
||||
*/
|
||||
String SET_FUNC_PREFIX = "set";
|
||||
/**
|
||||
* 基本数据类型的get方法前缀
|
||||
*/
|
||||
String IS_FUNC_PREFIX = "is";
|
||||
/**
|
||||
* 分片数量字段
|
||||
*/
|
||||
String SHARDS_FIELD = "index.number_of_shards";
|
||||
/**
|
||||
* 副本数量字段
|
||||
*/
|
||||
String REPLICAS_FIELD = "index.number_of_replicas";
|
||||
/**
|
||||
* 最大返回个数字段
|
||||
*/
|
||||
String MAX_RESULT_WINDOW_FIELD = "index.max_result_window";
|
||||
/**
|
||||
* 索引特性
|
||||
*/
|
||||
String PROPERTIES = "properties";
|
||||
/**
|
||||
* 字段类型
|
||||
*/
|
||||
String TYPE = "type";
|
||||
/**
|
||||
* 日期格式化
|
||||
*/
|
||||
String FORMAT = "format";
|
||||
/**
|
||||
* 分词器
|
||||
*/
|
||||
String ANALYZER = "analyzer";
|
||||
/**
|
||||
* 查询分词器
|
||||
*/
|
||||
String SEARCH_ANALYZER = "search_analyzer";
|
||||
/**
|
||||
* 字段关系
|
||||
*/
|
||||
String RELATIONS = "relations";
|
||||
/**
|
||||
* 父子类型-父id字段
|
||||
*/
|
||||
String PARENT = "parent";
|
||||
/**
|
||||
* 通配符
|
||||
*/
|
||||
String WILDCARD_SIGN = "*";
|
||||
/**
|
||||
* es默认schema
|
||||
*/
|
||||
String DEFAULT_SCHEMA = "http";
|
||||
/**
|
||||
* 默认返回数
|
||||
*/
|
||||
Integer DEFAULT_SIZE = 10000;
|
||||
/**
|
||||
* DSL语句前缀
|
||||
*/
|
||||
String DSL_PREFIX = "===> Execute By Easy-Es: ";
|
||||
/**
|
||||
* count DSL语句前缀
|
||||
*/
|
||||
String COUNT_DSL_PREFIX = "===> Execute Count By Easy-Es(Note the size specified in wrapper won't affect the total count): ";
|
||||
/**
|
||||
* 分片数key
|
||||
*/
|
||||
String SHARDS_NUM_KEY = "index.number_of_shards";
|
||||
/**
|
||||
* 副本数key
|
||||
*/
|
||||
String REPLICAS_NUM_KEY = "index.number_of_replicas";
|
||||
/**
|
||||
* 默认迁移操作规则
|
||||
*/
|
||||
String DEFAULT_DEST_OP_TYPE = "create";
|
||||
/**
|
||||
* 默认冲突处理
|
||||
*/
|
||||
String DEFAULT_CONFLICTS = "proceed";
|
||||
/**
|
||||
* 更新索引时自动创建的索引后缀s 灵感来源于jvm young区s0,s1垃圾回收
|
||||
*/
|
||||
String S_SUFFIX = "_s";
|
||||
/**
|
||||
* 更新索引时自动创建的索引后缀s0
|
||||
*/
|
||||
String SO_SUFFIX = "_s0";
|
||||
/**
|
||||
* 更新索引时自动创建的索引后缀s1
|
||||
*/
|
||||
String S1_SUFFIX = "_s1";
|
||||
/**
|
||||
* 分布式锁提示内容
|
||||
*/
|
||||
String DISTRIBUTED_LOCK_TIP_JSON = "{\"tip\":\"Do not delete unless deadlock occurs\"}";
|
||||
/**
|
||||
* 获取/释放 分布式锁 最大失败重试次数
|
||||
*/
|
||||
Integer LOCK_MAX_RETRY = 3;
|
||||
/**
|
||||
* 初始任务执行延迟
|
||||
*/
|
||||
int INITIAL_DELAY = 30;
|
||||
|
||||
/**
|
||||
* 被折叠的重复数据数量的key
|
||||
*/
|
||||
String REPEAT_NUM_KEY = "repeat_num";
|
||||
/**
|
||||
* 默认最大拓展数
|
||||
*/
|
||||
int DEFAULT_MAX_EXPANSIONS = 50;
|
||||
/**
|
||||
* 默认最小匹配百分比
|
||||
*/
|
||||
int DEFAULT_MIN_SHOULD_MATCH = 60;
|
||||
/**
|
||||
* 嵌套类型 path和field连接符
|
||||
*/
|
||||
String PATH_FIELD_JOIN = ".";
|
||||
/**
|
||||
* 父子类型索引-eager_global_ordinals
|
||||
*/
|
||||
String EAGER_GLOBAL_ORDINALS_KEY = "eager_global_ordinals";
|
||||
/**
|
||||
* 索引权重key
|
||||
*/
|
||||
String BOOST_KEY = "boost";
|
||||
/**
|
||||
* 针对text进行聚合
|
||||
*/
|
||||
String FIELD_DATA = "fielddata";
|
||||
/**
|
||||
* 未知的版本号
|
||||
*/
|
||||
String UNKNOWN = "unknown";
|
||||
/**
|
||||
* keyword后缀
|
||||
*/
|
||||
String KEYWORD_SUFFIX = ".keyword";
|
||||
/**
|
||||
* 执行SQL x-pack 固定地址
|
||||
*/
|
||||
String SQL_ENDPOINT = "/_xpack/sql?format=json";
|
||||
/**
|
||||
* 执行DSL 查询固定地址
|
||||
*/
|
||||
String DSL_ENDPOINT = "/_search";
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
String QUERY = "query";
|
||||
|
||||
/**
|
||||
* 忽略大小写key
|
||||
*/
|
||||
String CUSTOM_TYPE = "index.analysis.normalizer.lowercase_normalizer.type";
|
||||
String CUSTOM_FILTER = "index.analysis.normalizer.lowercase_normalizer.filter";
|
||||
String NORMALIZER = "normalizer";
|
||||
String LOWERCASE_NORMALIZER = "lowercase_normalizer";
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 聚合枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AggregationTypeEnum {
|
||||
/**
|
||||
* 求均值
|
||||
*/
|
||||
AVG("Avg"),
|
||||
/**
|
||||
* 求最小值
|
||||
*/
|
||||
MIN("Min"),
|
||||
/**
|
||||
* 求最大值
|
||||
*/
|
||||
MAX("Max"),
|
||||
/**
|
||||
* 求和
|
||||
*/
|
||||
SUM("Sum"),
|
||||
/**
|
||||
* 按字段分组,相当于mysql group by
|
||||
*/
|
||||
TERMS("Terms");
|
||||
|
||||
/**
|
||||
* 聚合类型英文名
|
||||
*/
|
||||
private final String value;
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 参数类型
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@AllArgsConstructor
|
||||
public enum BaseEsParamTypeEnum {
|
||||
/**
|
||||
* AND开头左括号 (
|
||||
*/
|
||||
AND_LEFT_BRACKET(1),
|
||||
/**
|
||||
* AND开头右括号 )
|
||||
*/
|
||||
AND_RIGHT_BRACKET(2),
|
||||
/**
|
||||
* OR开头左括号 (
|
||||
*/
|
||||
OR_LEFT_BRACKET(3),
|
||||
/**
|
||||
* OR开头右括号 )
|
||||
*/
|
||||
OR_RIGHT_BRACKET(4),
|
||||
/**
|
||||
* OR 左右括号都包含的情况 比如:
|
||||
* wrapper.eq(User::getName, "张三")
|
||||
* .or()
|
||||
* .eq(Document::getAge, 18);
|
||||
*/
|
||||
OR_ALL(5);
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Getter
|
||||
private Integer type;
|
||||
}
|
||||
@ -1,108 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
/**
|
||||
* 查询类型枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public enum EsQueryTypeEnum {
|
||||
/**
|
||||
* 精确值匹配 相当于MYSQL 等于
|
||||
*/
|
||||
TERM,
|
||||
/**
|
||||
* 精确值列表匹配 相当于MYSQL IN
|
||||
*/
|
||||
TERMS,
|
||||
/**
|
||||
* 模糊匹配 分词 相当于MYSQL LIKE
|
||||
*/
|
||||
MATCH,
|
||||
/**
|
||||
* 范围查询
|
||||
*/
|
||||
GE,
|
||||
GT,
|
||||
LE,
|
||||
LT,
|
||||
BETWEEN,
|
||||
/**
|
||||
* 存在查询 相当于MYSQL中的 字段 NOT NULL这种查询类型
|
||||
*/
|
||||
EXISTS,
|
||||
/**
|
||||
* 通配,相当于MYSQL中的LIKE
|
||||
*/
|
||||
WILDCARD,
|
||||
/**
|
||||
* 分词匹配 需要结果中也包含所有的分词,且顺序一样
|
||||
*/
|
||||
MATCH_PHRASE,
|
||||
/**
|
||||
* 前缀匹配
|
||||
*/
|
||||
MATCH_PHRASE_PREFIX,
|
||||
/**
|
||||
* 查询全部 相当于Mysql中的select * 无where条件 谨慎使用
|
||||
*/
|
||||
MATCH_ALL,
|
||||
/**
|
||||
* 多字段匹配
|
||||
*/
|
||||
MULTI_MATCH,
|
||||
/**
|
||||
* 所有字段中搜索
|
||||
*/
|
||||
QUERY_STRING,
|
||||
/**
|
||||
* 前缀查询
|
||||
*/
|
||||
PREFIX,
|
||||
/**
|
||||
* 地理位置查询
|
||||
*/
|
||||
GEO_BOUNDING_BOX,
|
||||
GEO_DISTANCE,
|
||||
GEO_POLYGON,
|
||||
GEO_SHAPE_ID,
|
||||
GEO_SHAPE,
|
||||
/**
|
||||
* 父子类型查询
|
||||
*/
|
||||
HAS_CHILD,
|
||||
HAS_PARENT,
|
||||
PARENT_ID,
|
||||
/**
|
||||
* 与条件,相当于MYSQL中的AND,必须满足且返回得分
|
||||
*/
|
||||
NESTED_AND,
|
||||
/**
|
||||
* 取反的与条件,必须不满足
|
||||
*/
|
||||
NESTED_NOT,
|
||||
/**
|
||||
* 与条件必须满足,但不返回得分,效率更高
|
||||
*/
|
||||
NESTED_FILTER,
|
||||
/**
|
||||
* 或条件,相当于MYSQL中的OR 和MP中的or嵌套用法一致
|
||||
*/
|
||||
NESTED_OR,
|
||||
/**
|
||||
* 嵌套查询 ES独有 对嵌套类型的查询
|
||||
*/
|
||||
NESTED,
|
||||
/**
|
||||
* 拼接OR,或条件,和MP中的拼接or用法一致
|
||||
*/
|
||||
OR,
|
||||
/**
|
||||
* 拼接NOT,非条件 表示必须不满足
|
||||
*/
|
||||
NOT,
|
||||
/**
|
||||
* 拼接filter,
|
||||
*/
|
||||
FILTER;
|
||||
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* java数据类型枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@AllArgsConstructor
|
||||
public enum JdkDataTypeEnum {
|
||||
BYTE("byte"),
|
||||
SHORT("short"),
|
||||
INT("int"),
|
||||
INTEGER("integer"),
|
||||
LONG("long"),
|
||||
FLOAT("float"),
|
||||
DOUBLE("double"),
|
||||
BIG_DECIMAL("bigdecimal"),
|
||||
BOOLEAN("boolean"),
|
||||
CHAR("char"),
|
||||
STRING("string"),
|
||||
DATE("date"),
|
||||
LOCAL_DATE("localdate"),
|
||||
LOCAL_DATE_TIME("localdatetime"),
|
||||
LIST("list");
|
||||
@Getter
|
||||
private String type;
|
||||
|
||||
public static JdkDataTypeEnum getByType(String typeName) {
|
||||
return Arrays.stream(JdkDataTypeEnum.values())
|
||||
.filter(v -> Objects.equals(v.type, typeName))
|
||||
.findFirst()
|
||||
.orElse(STRING);
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
/**
|
||||
* 嵌套及父子类型枚举
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public enum JoinTypeEnum {
|
||||
NESTED,
|
||||
HAS_CHILD,
|
||||
HAS_PARENT,
|
||||
PARENT_ID;
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
/**
|
||||
* 连接类型枚举
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public enum Link {
|
||||
/**
|
||||
* 与条件 默认
|
||||
*/
|
||||
AND,
|
||||
/**
|
||||
* 或条件
|
||||
*/
|
||||
OR;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
/**
|
||||
* 请求方法枚举
|
||||
* <p>
|
||||
* Copyright © 2023 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public enum MethodEnum {
|
||||
GET,
|
||||
POST,
|
||||
PUT,
|
||||
DELETE,
|
||||
HEAD;
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
/**
|
||||
* 查询参数Nested类型枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public enum NestedEnum {
|
||||
/**
|
||||
* 与条件,相当于mysql中的and,必须满足且返回得分
|
||||
*/
|
||||
MUST,
|
||||
/**
|
||||
* 取反的与条件,必须不满足
|
||||
*/
|
||||
MUST_NOT,
|
||||
/**
|
||||
* 与条件必须满足,但不返回得分,效率更高
|
||||
*/
|
||||
FILTER,
|
||||
/**
|
||||
* 或条件,相当于mysql中的or
|
||||
*/
|
||||
SHOULD;
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
/**
|
||||
* 排序器类型枚举
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public enum OrderTypeEnum {
|
||||
/**
|
||||
* 常规字段排序器
|
||||
*/
|
||||
FIELD,
|
||||
/**
|
||||
* 用户自定义的原生语法排序器
|
||||
*/
|
||||
CUSTOMIZE,
|
||||
/**
|
||||
* 得分排序器
|
||||
*/
|
||||
SCORE,
|
||||
/**
|
||||
* 地理位置排序器
|
||||
*/
|
||||
GEO;
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 索引策略枚举
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@AllArgsConstructor
|
||||
public enum ProcessIndexStrategyEnum {
|
||||
/**
|
||||
* 平滑迁移策略,零停机 默认策略
|
||||
*/
|
||||
SMOOTHLY(1),
|
||||
/**
|
||||
* 非平滑迁移策略 简单粗暴 备选
|
||||
*/
|
||||
NOT_SMOOTHLY(2),
|
||||
/**
|
||||
* 用户手动调用API处理索引
|
||||
*/
|
||||
MANUAL(3);
|
||||
@Getter
|
||||
private Integer strategyType;
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 查询类型枚举
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@AllArgsConstructor
|
||||
public enum Query {
|
||||
/**
|
||||
* 不分词匹配,默认为精确匹配,如果需要左模糊,右模糊或者左右都模糊,请在传入的查询字段值中拼接"*" 类似MySQL的like拼接%
|
||||
*/
|
||||
EQ(".keyword"),
|
||||
/**
|
||||
* 分词匹配
|
||||
*/
|
||||
MATCH("");
|
||||
@Getter
|
||||
private String text;
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 数据刷新策略枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@AllArgsConstructor
|
||||
public enum RefreshPolicy {
|
||||
/**
|
||||
* 默认不刷新
|
||||
*/
|
||||
NONE("false"),
|
||||
/**
|
||||
* 立即刷新,性能损耗高
|
||||
*/
|
||||
IMMEDIATE("true"),
|
||||
/**
|
||||
* 请求提交数据后,等待数据完成刷新(1s),再结束请求 性能损耗适中
|
||||
*/
|
||||
WAIT_UNTIL("wait_for");
|
||||
|
||||
/**
|
||||
* 刷新策略值
|
||||
*/
|
||||
@Getter
|
||||
private String value;
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
package cn.easyes.common.exception;
|
||||
|
||||
/**
|
||||
* EasyEs异常类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class EasyEsException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public EasyEsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public EasyEsException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public EasyEsException(String message, Throwable throwable) {
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package cn.easyes.common.params;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 函数式接口
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@FunctionalInterface
|
||||
public interface SFunction<T, R> extends Serializable {
|
||||
R apply(T t);
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
/**
|
||||
* array工具类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class ArrayUtils {
|
||||
private ArrayUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数据是否为空
|
||||
*
|
||||
* @param array 数组
|
||||
* @return 布尔
|
||||
*/
|
||||
public static boolean isEmpty(Object[] array) {
|
||||
return array == null || array.length == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数组是否不为空
|
||||
*
|
||||
* @param array 数组
|
||||
* @return 布尔
|
||||
*/
|
||||
public static boolean isNotEmpty(Object[] array) {
|
||||
return !isEmpty(array);
|
||||
}
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import cn.easyes.common.exception.EasyEsException;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 断言工具类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class Assert {
|
||||
private Assert() {
|
||||
}
|
||||
|
||||
public static void notNull(Object object, String message) {
|
||||
if (object == null) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isNull(Object object, String message) {
|
||||
if (object != null) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isTrue(boolean expression, String message) {
|
||||
if (!expression) {
|
||||
throw new EasyEsException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isFalse(boolean expression, String message) {
|
||||
if (expression) {
|
||||
throw new EasyEsException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isEmpty(Object[] array, String message) {
|
||||
if (!isEmpty(array)) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void notEmpty(Object[] array, String message) {
|
||||
if (isEmpty(array)) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void notEmpty(Collection<?> collection, String message) {
|
||||
if (CollectionUtils.isEmpty(collection)) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isEmpty(Collection<?> collection, String message) {
|
||||
if (CollectionUtils.isNotEmpty(collection)) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isEmpty(Object[] array) {
|
||||
return array == null || array.length == 0;
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 类工具类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public final class ClassUtils {
|
||||
/**
|
||||
* 代理 class 的名称
|
||||
*/
|
||||
private static final List<String> PROXY_CLASS_NAMES = Arrays.asList("net.sf.cglib.proxy.Factory"
|
||||
// cglib
|
||||
, "org.springframework.cglib.proxy.Factory"
|
||||
, "javassist.util.proxy.ProxyObject"
|
||||
// javassist
|
||||
, "org.apache.ibatis.javassist.util.proxy.ProxyObject");
|
||||
|
||||
private ClassUtils() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断是否为代理对象
|
||||
*
|
||||
* @param clazz 传入 class 对象
|
||||
* @return 如果对象class是代理 class,返回 true
|
||||
*/
|
||||
public static boolean isProxy(Class<?> clazz) {
|
||||
if (clazz != null) {
|
||||
for (Class<?> cls : clazz.getInterfaces()) {
|
||||
if (PROXY_CLASS_NAMES.contains(cls.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 获取当前对象的 class
|
||||
* </p>
|
||||
*
|
||||
* @param clazz 传入
|
||||
* @return 如果是代理的class,返回父 class,否则返回自身
|
||||
*/
|
||||
public static Class<?> getUserClass(Class<?> clazz) {
|
||||
if (Objects.isNull(clazz)) {
|
||||
throw ExceptionUtils.eee("Class must not be null");
|
||||
}
|
||||
return isProxy(clazz) ? clazz.getSuperclass() : clazz;
|
||||
}
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 集合工具类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class CollectionUtils {
|
||||
/**
|
||||
* 精度 double
|
||||
*/
|
||||
private final static double DOUBLE_ACCURACY = 0.001d;
|
||||
/**
|
||||
* 精度 float
|
||||
*/
|
||||
private final static float FLOAT_ACCURACY = 0.001f;
|
||||
|
||||
public CollectionUtils() {
|
||||
}
|
||||
|
||||
public static boolean isEmpty(Collection<?> collection) {
|
||||
return collection == null || collection.isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(Collection<?> collection) {
|
||||
return !isEmpty(collection);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断Map是否为空
|
||||
*
|
||||
* @param map 入参
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isEmpty(Map<?, ?> map) {
|
||||
return (map == null || map.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Map是否不为空
|
||||
*
|
||||
* @param map 入参
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isNotEmpty(Map<?, ?> map) {
|
||||
return !isEmpty(map);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.easyes.common.constants.BaseEsConstants.UNKNOWN;
|
||||
|
||||
/**
|
||||
* ee 版本工具类
|
||||
*
|
||||
* @author dys
|
||||
* @since 0.9.80
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class EEVersionUtils {
|
||||
|
||||
/**
|
||||
* 获取指定类版本号
|
||||
* <ul>
|
||||
* <li>只能获取jar包版本,并且打包后META-INF/MANIFEST.MF文件中存在 Implementation-Version</li>
|
||||
* <li>不存在 Implementation-Version 时返回 unknown</li>
|
||||
* <li>如果获取EE本身版本需要打包后获取,在test包测试用例中无法获取</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param <T> 泛型
|
||||
* @param objectClass T.getClass()
|
||||
* @return classVersion
|
||||
*/
|
||||
public static <T> String getJarVersion(Class<T> objectClass) {
|
||||
return Optional.ofNullable(objectClass.getPackage().getImplementationVersion()).
|
||||
orElse("UNKNOWN");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取elasticsearch client 版本
|
||||
* <p>
|
||||
* elasticsearch 客户端必须通过 restHighLevelClient.info 获取,无法使用getPackage.getImplementationVersion 获取
|
||||
* </p>
|
||||
*
|
||||
* @param restHighLevelClient es高级客户端
|
||||
* @return client version
|
||||
*/
|
||||
public static String getClientVersion(RestHighLevelClient restHighLevelClient) {
|
||||
try {
|
||||
return restHighLevelClient.info(RequestOptions.DEFAULT)
|
||||
.getVersion()
|
||||
.getNumber();
|
||||
} catch (IOException e) {
|
||||
LogUtils.formatWarn("get client version error");
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
@ -1,71 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
|
||||
import cn.easyes.common.exception.EasyEsException;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
|
||||
/**
|
||||
* 异常辅助工具类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public final class ExceptionUtils {
|
||||
|
||||
private ExceptionUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个新的异常,统一构建,方便统一处理
|
||||
*
|
||||
* @param msg 消息
|
||||
* @param t 异常
|
||||
* @param params 参数
|
||||
* @return 自定义异常
|
||||
*/
|
||||
public static EasyEsException eee(String msg, Throwable t, Object... params) {
|
||||
return new EasyEsException(String.format(msg, params), t);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载
|
||||
*
|
||||
* @param msg 消息
|
||||
* @param params 参数
|
||||
* @return 自定义异常
|
||||
*/
|
||||
public static EasyEsException eee(String msg, Object... params) {
|
||||
return new EasyEsException(String.format(msg, params));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载
|
||||
*
|
||||
* @param t 异常
|
||||
* @return 自定义异常
|
||||
*/
|
||||
public static EasyEsException eee(Throwable t) {
|
||||
return new EasyEsException(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异常包装
|
||||
*
|
||||
* @param wrapped 异常
|
||||
* @return 异常
|
||||
*/
|
||||
public static Throwable unwrapThrowable(Throwable wrapped) {
|
||||
Throwable unwrapped = wrapped;
|
||||
while (true) {
|
||||
if (unwrapped instanceof InvocationTargetException) {
|
||||
unwrapped = ((InvocationTargetException) unwrapped).getTargetException();
|
||||
} else if (unwrapped instanceof UndeclaredThrowableException) {
|
||||
unwrapped = ((UndeclaredThrowableException) unwrapped).getUndeclaredThrowable();
|
||||
} else {
|
||||
return unwrapped;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* fastjson 工具类
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class FastJsonUtils {
|
||||
/**
|
||||
* 设置fastjson toJsonString字段
|
||||
*
|
||||
* @param clazz 类
|
||||
* @param fields 字段列表
|
||||
* @return 前置过滤器
|
||||
*/
|
||||
public static SimplePropertyPreFilter getSimplePropertyPreFilter(Class<?> clazz, Set<String> fields) {
|
||||
if (CollectionUtils.isEmpty(fields)) {
|
||||
return null;
|
||||
}
|
||||
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter(clazz);
|
||||
fields.forEach(field -> simplePropertyPreFilter.getExcludes().add(field));
|
||||
return simplePropertyPreFilter;
|
||||
}
|
||||
}
|
||||
@ -1,81 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* 日志工具类,用于需要打印日志的地方,可避免引入其它日志框架依赖
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class LogUtils {
|
||||
/**
|
||||
* 日志打印工具名称
|
||||
*/
|
||||
private final static String LOGGER_NAME = "easy-es";
|
||||
/**
|
||||
* logger
|
||||
*/
|
||||
private final static Logger log = Logger.getLogger(LOGGER_NAME);
|
||||
|
||||
/**
|
||||
* 打印info级别日志
|
||||
*
|
||||
* @param params 参数
|
||||
*/
|
||||
public static void info(String... params) {
|
||||
log.info(String.join(",", params));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印info级别日志
|
||||
*
|
||||
* @param format 带有占位符的日志
|
||||
* @param args 占位符替换的内容
|
||||
*/
|
||||
public static void formatInfo(String format, Object... args) {
|
||||
log.info(String.join(",", String.format(format, args)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印warn级别日志
|
||||
*
|
||||
* @param params 参数
|
||||
*/
|
||||
public static void warn(String... params) {
|
||||
log.warning(String.join(",", params));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印warn级别日志
|
||||
*
|
||||
* @param format 带有占位符的日志
|
||||
* @param args 占位符替换的内容
|
||||
*/
|
||||
public static void formatWarn(String format, Object... args) {
|
||||
log.warning(String.join(",", String.format(format, args)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印server(error)级别日志
|
||||
*
|
||||
* @param params 参数
|
||||
*/
|
||||
public static void error(String... params) {
|
||||
log.severe(String.join(",", params));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印server(error)级别日志
|
||||
*
|
||||
* @param format 带有占位符的日志
|
||||
* @param args 占位符替换的内容
|
||||
*/
|
||||
public static void formatError(String format, Object... args) {
|
||||
log.severe(String.join(",", String.format(format, args)));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,96 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 对JDK提供的Optional的自定义增强
|
||||
* 可在一定程度上减少代码中出现的if-else 提升代码优雅
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public final class MyOptional<T> {
|
||||
private static final MyOptional<?> EMPTY = new MyOptional<>();
|
||||
|
||||
private final T value;
|
||||
|
||||
private MyOptional() {
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
public static <T> MyOptional<T> empty() {
|
||||
@SuppressWarnings("unchecked")
|
||||
MyOptional<T> t = (MyOptional<T>) EMPTY;
|
||||
return t;
|
||||
}
|
||||
|
||||
private MyOptional(T value) {
|
||||
this.value = Objects.requireNonNull(value);
|
||||
}
|
||||
|
||||
public static <T> MyOptional<T> of(T value) {
|
||||
return new MyOptional<>(value);
|
||||
}
|
||||
|
||||
public static <T> MyOptional<T> ofNullable(T value) {
|
||||
return value == null ? empty() : of(value);
|
||||
}
|
||||
|
||||
public boolean isPresent() {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
public void ifTrue(Consumer<? super T> consumer) {
|
||||
if (value != null && value instanceof Boolean) {
|
||||
boolean condition = (boolean) (Object) value;
|
||||
if (condition) {
|
||||
consumer.accept(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ifPresent(Consumer<? super T> present, Supplier<?> other) {
|
||||
if (value != null) {
|
||||
present.accept(value);
|
||||
} else {
|
||||
other.get();
|
||||
}
|
||||
}
|
||||
|
||||
public <U> MyOptional<U> ifPresent(Function<? super T, ? extends U> present, T otherValue) {
|
||||
Objects.requireNonNull(present);
|
||||
if (isPresent())
|
||||
return MyOptional.ofNullable(present.apply(value));
|
||||
else {
|
||||
return MyOptional.ofNullable(present.apply(otherValue));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof MyOptional)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MyOptional<?> other = (MyOptional<?>) obj;
|
||||
return Objects.equals(value, other.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value != null
|
||||
? String.format("MyOptional[%s]", value)
|
||||
: "MyOptional.empty";
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/**
|
||||
* 数字工具类
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class NumericUtils {
|
||||
/**
|
||||
* 设置保留小数位, 四舍五入
|
||||
*
|
||||
* @param origin 原始值
|
||||
* @param decimalPlaces 保留位数
|
||||
* @return 目标值
|
||||
*/
|
||||
public static float setDecimalPlaces(float origin, int decimalPlaces) {
|
||||
return BigDecimal.valueOf(origin)
|
||||
.setScale(decimalPlaces, RoundingMode.HALF_UP)
|
||||
.floatValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置保留小数位, 四舍五入
|
||||
*
|
||||
* @param origin 原始值
|
||||
* @param decimalPlaces 保留位数
|
||||
* @return 目标值
|
||||
*/
|
||||
public static double setDecimalPlaces(double origin, int decimalPlaces) {
|
||||
return BigDecimal.valueOf(origin)
|
||||
.setScale(decimalPlaces, RoundingMode.HALF_UP)
|
||||
.doubleValue();
|
||||
}
|
||||
}
|
||||
@ -1,94 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.function.Function.identity;
|
||||
import static java.util.stream.Collectors.toCollection;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
/**
|
||||
* 反射工具类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class ReflectionKit {
|
||||
|
||||
private static final Map<Class, List<Field>> classFieldCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 获取该类的所有属性列表
|
||||
* @param clazz 类
|
||||
* @return 所有属性列表
|
||||
*/
|
||||
public static List<Field> getFieldList(Class<?> clazz) {
|
||||
if (Objects.isNull(clazz)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Field> fields = classFieldCache.get(clazz);
|
||||
if (CollectionUtils.isEmpty(fields)) {
|
||||
synchronized (classFieldCache) {
|
||||
fields = doGetFieldList(clazz);
|
||||
classFieldCache.put(clazz, fields);
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
public static List<Field> doGetFieldList(Class<?> clazz) {
|
||||
if (clazz.getSuperclass() != null) {
|
||||
List<Field> fieldList = Stream.of(clazz.getDeclaredFields())
|
||||
/* 过滤静态属性 */
|
||||
.filter(field -> !Modifier.isStatic(field.getModifiers()))
|
||||
/* 过滤 transient关键字修饰的属性 */
|
||||
.filter(field -> !Modifier.isTransient(field.getModifiers()))
|
||||
.collect(toCollection(LinkedList::new));
|
||||
/* 处理父类字段 */
|
||||
Class<?> superClass = clazz.getSuperclass();
|
||||
/* 排除重载属性 */
|
||||
return excludeOverrideSuperField(fieldList, getFieldList(superClass));
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Field> excludeOverrideSuperField(List<Field> fieldList, List<Field> superFieldList) {
|
||||
// 子类属性
|
||||
Map<String, Field> fieldMap = fieldList.stream().collect(toMap(Field::getName, identity()));
|
||||
superFieldList.stream().filter(field -> !fieldMap.containsKey(field.getName())).forEach(fieldList::add);
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> cls, Field field) {
|
||||
try {
|
||||
return cls.getDeclaredMethod(ReflectionKit.getMethodCapitalize(field, field.getName()));
|
||||
} catch (NoSuchMethodException e) {
|
||||
String msg = String.format("Error: NoSuchMethod in %s. Cause: %s", cls.getName(), e);
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMethodCapitalize(Field field, final String str) {
|
||||
Class<?> fieldType = field.getType();
|
||||
// fix #176
|
||||
return StringUtils.concatCapitalize(boolean.class.equals(fieldType) ? "is" : "get", str);
|
||||
}
|
||||
|
||||
public static <T> T getVal(String val, Class<T> type) {
|
||||
// 把val转换成type类型返回
|
||||
T value = null;
|
||||
try {
|
||||
Constructor<T> constructor = type.getConstructor(String.class);
|
||||
constructor.setAccessible(true);
|
||||
value = constructor.newInstance(val);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
import static cn.easyes.common.constants.BaseEsConstants.UNKNOWN;
|
||||
|
||||
/**
|
||||
* elasticsearch 构造器
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class RestHighLevelClientBuilder {
|
||||
/**
|
||||
* 支持的版本 目前支持版本为7.14.0 稳定无漏洞版
|
||||
*/
|
||||
private final static String SUPPORTED_JAR_VERSION = "7.14.0";
|
||||
/**
|
||||
* 支持的客户端版本 目前支持7.xx 推荐7.14.0
|
||||
*/
|
||||
private final static String SUPPORTED_CLIENT_VERSION = "7";
|
||||
|
||||
/**
|
||||
* 构建RestHighLevelClient
|
||||
*
|
||||
* @param builder 构建连接对象
|
||||
* @return es高级客户端
|
||||
*/
|
||||
public static RestHighLevelClient build(RestClientBuilder builder) {
|
||||
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
|
||||
// 检验es版本是否对应
|
||||
verify(restHighLevelClient);
|
||||
return restHighLevelClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验es client版本及jar包版本
|
||||
*
|
||||
* @param restHighLevelClient es高级客户端
|
||||
*/
|
||||
private static void verify(RestHighLevelClient restHighLevelClient) {
|
||||
// 校验jar包版本是否为推荐使用版本
|
||||
String jarVersion = EEVersionUtils.getJarVersion(restHighLevelClient.getClass());
|
||||
LogUtils.formatInfo("Elasticsearch jar version:%s", jarVersion);
|
||||
if (!jarVersion.equals(SUPPORTED_JAR_VERSION) && !UNKNOWN.equals(jarVersion)) {
|
||||
LogUtils.formatError("Easy-Es supported elasticsearch and restHighLevelClient jar version is:%s ,Please resolve the dependency conflict!", SUPPORTED_JAR_VERSION);
|
||||
}
|
||||
String clientVersion = EEVersionUtils.getClientVersion(restHighLevelClient);
|
||||
LogUtils.formatInfo("Elasticsearch client version:%s", clientVersion);
|
||||
if (!clientVersion.startsWith(SUPPORTED_CLIENT_VERSION)) {
|
||||
// 这里校验客户端为非强制,客户端版本非推荐版本对应提醒即可,es会报错提醒
|
||||
LogUtils.formatWarn("Easy-Es supported elasticsearch client version is:%s.xx", SUPPORTED_CLIENT_VERSION);
|
||||
}
|
||||
if (!jarVersion.equals(clientVersion)) {
|
||||
// 提示jar包与客户端版本不对应,es官方推荐jar包版本对应客户端版本
|
||||
LogUtils.formatWarn("Elasticsearch clientVersion:%s not equals jarVersion:%s, It does not affect your use, but we still recommend keeping it consistent!", clientVersion, jarVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,130 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
/**
|
||||
* 字符串工具类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class StringUtils {
|
||||
public static final String EMPTY = "";
|
||||
/**
|
||||
* 下划线字符
|
||||
*/
|
||||
public static final char UNDERLINE = '_';
|
||||
|
||||
private StringUtils() {
|
||||
}
|
||||
|
||||
|
||||
public static String concatCapitalize(String concatStr, final String str) {
|
||||
if (isEmpty(concatStr)) {
|
||||
concatStr = EMPTY;
|
||||
}
|
||||
if (str == null || str.length() == 0) {
|
||||
return str;
|
||||
}
|
||||
|
||||
final char firstChar = str.charAt(0);
|
||||
if (Character.isTitleCase(firstChar)) {
|
||||
// already capitalized
|
||||
return str;
|
||||
}
|
||||
|
||||
return concatStr + Character.toTitleCase(firstChar) + str.substring(1);
|
||||
}
|
||||
|
||||
public static boolean isEmpty(final CharSequence cs) {
|
||||
int strLen;
|
||||
if (cs == null || (strLen = cs.length()) == 0) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
if (!Character.isWhitespace(cs.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(final CharSequence cs) {
|
||||
return !isEmpty(cs);
|
||||
}
|
||||
|
||||
public static boolean isBlank(CharSequence cs) {
|
||||
if (cs != null) {
|
||||
int length = cs.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (!Character.isWhitespace(cs.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isNotBlank(CharSequence cs) {
|
||||
return !isBlank(cs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串下划线转驼峰格式
|
||||
*
|
||||
* @param param 需要转换的字符串
|
||||
* @return 转换好的字符串
|
||||
*/
|
||||
public static String underlineToCamel(String param) {
|
||||
if (isBlank(param)) {
|
||||
return EMPTY;
|
||||
}
|
||||
String temp = param.toLowerCase();
|
||||
int len = temp.length();
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
char c = temp.charAt(i);
|
||||
if (c == UNDERLINE) {
|
||||
if (++i < len) {
|
||||
sb.append(Character.toUpperCase(temp.charAt(i)));
|
||||
}
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串驼峰转下划线格式
|
||||
*
|
||||
* @param param 需要转换的字符串
|
||||
* @return 转换好的字符串
|
||||
*/
|
||||
public static String camelToUnderline(String param) {
|
||||
if (isBlank(param)) {
|
||||
return EMPTY;
|
||||
}
|
||||
int len = param.length();
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
char c = param.charAt(i);
|
||||
if (Character.isUpperCase(c) && i > 0) {
|
||||
sb.append(UNDERLINE);
|
||||
}
|
||||
sb.append(Character.toLowerCase(c));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断对象是否为空
|
||||
*
|
||||
* @param object ignore
|
||||
* @return ignore
|
||||
*/
|
||||
public static boolean checkValNotNull(Object object) {
|
||||
if (object instanceof CharSequence) {
|
||||
return isNotEmpty((CharSequence) object);
|
||||
}
|
||||
return object != null;
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* 核心 泛型工具类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class TypeUtils {
|
||||
/**
|
||||
* 获取接口上的泛型T
|
||||
*
|
||||
* @param o 类
|
||||
* @param index 下标
|
||||
* @return 类的类型
|
||||
*/
|
||||
public static Class<?> getInterfaceT(Class o, int index) {
|
||||
Type[] types = o.getGenericInterfaces();
|
||||
ParameterizedType parameterizedType = (ParameterizedType) types[index];
|
||||
Type type = parameterizedType.getActualTypeArguments()[index];
|
||||
return checkType(type, index);
|
||||
|
||||
}
|
||||
|
||||
private static Class<?> checkType(Type type, int index) {
|
||||
if (type instanceof Class<?>) {
|
||||
return (Class<?>) type;
|
||||
} else if (type instanceof ParameterizedType) {
|
||||
ParameterizedType pt = (ParameterizedType) type;
|
||||
Type t = pt.getActualTypeArguments()[index];
|
||||
return checkType(t, index);
|
||||
} else {
|
||||
String className = type == null ? "null" : type.getClass().getName();
|
||||
throw new IllegalArgumentException("Expected a Class, ParameterizedType"
|
||||
+ ", but <" + type + "> is of type " + className);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<groupId>org.dromara.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>2.0.0-beta2</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<groupId>org.dromara.easy-es</groupId>
|
||||
<artifactId>easy-es-extension</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.common.enums.AggregationTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 聚合参数
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
public class AggregationParam {
|
||||
/**
|
||||
* 是否开启管道聚合
|
||||
*/
|
||||
private boolean enablePipeline;
|
||||
/**
|
||||
* 返回字段名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 聚合字段
|
||||
*/
|
||||
private String field;
|
||||
/**
|
||||
* 聚合类型
|
||||
*/
|
||||
private AggregationTypeEnum aggregationType;
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.common.enums.OrderTypeEnum;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.elasticsearch.common.geo.GeoDistance;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.unit.DistanceUnit;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
|
||||
/**
|
||||
* 排序基本参数
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
@Builder
|
||||
public class BaseSortParam {
|
||||
/**
|
||||
* 排序规则
|
||||
*/
|
||||
private SortOrder sortOrder;
|
||||
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private String sortField;
|
||||
|
||||
/**
|
||||
* 用户自定义的原生语法排序器
|
||||
*/
|
||||
private SortBuilder<?> sortBuilder;
|
||||
|
||||
/**
|
||||
* 排序类型
|
||||
*/
|
||||
private OrderTypeEnum orderTypeEnum;
|
||||
|
||||
/**
|
||||
* 计算方式 ARC PLANE 默认PLANE
|
||||
*/
|
||||
private GeoDistance geoDistance;
|
||||
/**
|
||||
* 距离单位 默认为km
|
||||
*/
|
||||
private DistanceUnit unit;
|
||||
/**
|
||||
* 排序坐标点
|
||||
*/
|
||||
private GeoPoint[] geoPoints;
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 创建索引参数
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
public class CreateIndexParam {
|
||||
/**
|
||||
* 实体类
|
||||
*/
|
||||
private Class<?> entityClass;
|
||||
/**
|
||||
* 索引名
|
||||
*/
|
||||
private String indexName;
|
||||
/**
|
||||
* 别名
|
||||
*/
|
||||
private String aliasName;
|
||||
/**
|
||||
* 分片数
|
||||
*/
|
||||
private Integer shardsNum;
|
||||
/**
|
||||
* 副本数
|
||||
*/
|
||||
private Integer replicasNum;
|
||||
/**
|
||||
* 最大返回数
|
||||
*/
|
||||
private Integer maxResultWindow;
|
||||
/**
|
||||
* 索引字段及类型分词器等信息
|
||||
*/
|
||||
private List<EsIndexParam> esIndexParamList;
|
||||
/**
|
||||
* 用户手动指定的mapping信息,优先级最高
|
||||
*/
|
||||
private Map<String, Object> mapping;
|
||||
/**
|
||||
* 用户手动指定的settings信息,优先级最高
|
||||
*/
|
||||
private Settings settings;
|
||||
}
|
||||
@ -1,118 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.annotation.rely.FieldStrategy;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.core.config.GlobalConfig;
|
||||
import com.alibaba.fastjson.serializer.NameFilter;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* es实体字段信息
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
public class EntityFieldInfo {
|
||||
/**
|
||||
* 忽略的字段
|
||||
*/
|
||||
private String ignoreColumn;
|
||||
/**
|
||||
* 实体类字段名
|
||||
*/
|
||||
private String column;
|
||||
/**
|
||||
* 字段类型,如Integer
|
||||
*/
|
||||
private String columnType;
|
||||
/**
|
||||
* es中的字段名
|
||||
*/
|
||||
private String mappingColumn;
|
||||
/**
|
||||
* 字段在es中的存储类型
|
||||
*/
|
||||
private FieldType fieldType;
|
||||
/**
|
||||
* 设置text、keyword_text 可以进行聚合操作
|
||||
*/
|
||||
private boolean fieldData;
|
||||
/**
|
||||
* 字段是否忽略大小写,默认不忽略 为true时则忽略大小写
|
||||
*/
|
||||
private boolean ignoreCase;
|
||||
/**
|
||||
* 分词器
|
||||
*/
|
||||
private String analyzer;
|
||||
/**
|
||||
* 查询分词器
|
||||
*/
|
||||
private String searchAnalyzer;
|
||||
/**
|
||||
* 用户配置的日期格式 例如yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
private String dateFormat;
|
||||
/**
|
||||
* 字段策略 默认,自判断 null
|
||||
*/
|
||||
private final FieldStrategy fieldStrategy;
|
||||
/**
|
||||
* 父名称
|
||||
*/
|
||||
private String parentName;
|
||||
/**
|
||||
* 子名称
|
||||
*/
|
||||
private String childName;
|
||||
|
||||
/**
|
||||
* 缓存包含主键及字段的 sql select
|
||||
*/
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Getter(AccessLevel.NONE)
|
||||
private String allSqlSelect;
|
||||
/**
|
||||
* 缓存主键字段的 sql select
|
||||
*/
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Getter(AccessLevel.NONE)
|
||||
private String sqlSelect;
|
||||
private NameFilter nameFilter;
|
||||
|
||||
/**
|
||||
* 存在 TableField 注解时, 使用的构造函数
|
||||
*
|
||||
* @param dbConfig 索引配置
|
||||
* @param field 字段
|
||||
* @param tableField 字段注解
|
||||
*/
|
||||
public EntityFieldInfo(GlobalConfig.DbConfig dbConfig, Field field, IndexField tableField) {
|
||||
this.column = field.getName();
|
||||
|
||||
// 优先使用单个字段注解,否则使用全局配置
|
||||
if (tableField.strategy() == FieldStrategy.DEFAULT) {
|
||||
this.fieldStrategy = dbConfig.getFieldStrategy();
|
||||
} else {
|
||||
this.fieldStrategy = tableField.strategy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 不存在 TableField 注解时, 使用的构造函数
|
||||
*
|
||||
* @param dbConfig 索引配置
|
||||
* @param field 字段
|
||||
*/
|
||||
public EntityFieldInfo(GlobalConfig.DbConfig dbConfig, Field field) {
|
||||
this.fieldStrategy = dbConfig.getFieldStrategy();
|
||||
this.column = field.getName();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,226 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.annotation.rely.IdType;
|
||||
import cn.easyes.annotation.rely.JoinField;
|
||||
import cn.easyes.common.constants.BaseEsConstants;
|
||||
import com.alibaba.fastjson.PropertyNamingStrategy;
|
||||
import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
|
||||
import com.alibaba.fastjson.serializer.SerializeFilter;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.easyes.annotation.rely.AnnotationConstants.DEFAULT_MAX_RESULT_WINDOW;
|
||||
|
||||
/**
|
||||
* 实体类信息
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class EntityInfo {
|
||||
/**
|
||||
* 表主键ID 类型
|
||||
*/
|
||||
private IdType idType = IdType.NONE;
|
||||
/**
|
||||
* id数据类型 如Long.class String.class
|
||||
*/
|
||||
private Class<?> idClass;
|
||||
/**
|
||||
* 索引名称(原索引名)
|
||||
*/
|
||||
private String indexName;
|
||||
/**
|
||||
* 配置的路由
|
||||
*/
|
||||
private String routing;
|
||||
/**
|
||||
* 新索引名(由EE在更新索引时自动创建)
|
||||
*/
|
||||
private String releaseIndexName;
|
||||
/***
|
||||
* 重试成功的索引名
|
||||
*/
|
||||
private String retrySuccessIndexName;
|
||||
/**
|
||||
* 最大返回数
|
||||
*/
|
||||
private Integer maxResultWindow = DEFAULT_MAX_RESULT_WINDOW;
|
||||
/**
|
||||
* 表映射结果集
|
||||
*/
|
||||
private String resultMap;
|
||||
/**
|
||||
* 主键字段
|
||||
*/
|
||||
private Field keyField;
|
||||
/**
|
||||
* 表主键ID 属性名
|
||||
*/
|
||||
private String keyProperty;
|
||||
/**
|
||||
* 分片数 默认为1
|
||||
*/
|
||||
private Integer shardsNum = BaseEsConstants.ONE;
|
||||
/**
|
||||
* 副本数 默认为1
|
||||
*/
|
||||
private Integer replicasNum = BaseEsConstants.ONE;
|
||||
/**
|
||||
* 索引别名
|
||||
*/
|
||||
private String aliasName;
|
||||
/**
|
||||
* 得分字段名
|
||||
*/
|
||||
private String scoreField;
|
||||
/**
|
||||
* 得分保留小数位,默认不处理,保持es返回值,效率更高
|
||||
*/
|
||||
private int scoreDecimalPlaces = 0;
|
||||
/**
|
||||
* 距离字段名列表
|
||||
*/
|
||||
private List<String> distanceFields = new ArrayList<>();
|
||||
/**
|
||||
* 距离保留小数位 每个排序器可自定义其保留位数,默认不处理,保持es返回值,效率更高
|
||||
*/
|
||||
private List<Integer> distanceDecimalPlaces = new ArrayList<>();
|
||||
/**
|
||||
* join字段名称
|
||||
*/
|
||||
private String joinFieldName;
|
||||
/**
|
||||
* join关系字段类 默认为JoinField.class
|
||||
*/
|
||||
private Class<?> joinFieldClass = JoinField.class;
|
||||
/**
|
||||
* 嵌套类的字段信息列表
|
||||
*/
|
||||
private Map<Class<?>, List<EntityFieldInfo>> nestedFieldListMap = new HashMap<>();
|
||||
/**
|
||||
* 表字段信息列表
|
||||
*/
|
||||
private List<EntityFieldInfo> fieldList;
|
||||
/**
|
||||
* 标记id字段属于哪个类
|
||||
*/
|
||||
private Class<?> clazz;
|
||||
/**
|
||||
* 父子类型,子类
|
||||
*/
|
||||
private Class<?> childClass;
|
||||
/**
|
||||
* 父子类型-是否子文档 默认为否
|
||||
*/
|
||||
private boolean child = false;
|
||||
/**
|
||||
* 当前主类的高亮字段列表
|
||||
*/
|
||||
private List<HighLightParam> highLightParams = new ArrayList<>();
|
||||
/**
|
||||
* fastjson 字段命名策略
|
||||
*/
|
||||
private PropertyNamingStrategy propertyNamingStrategy;
|
||||
/**
|
||||
* fastjson 实体中不存在的字段处理器
|
||||
*/
|
||||
private ExtraProcessor extraProcessor;
|
||||
/**
|
||||
* 实体字段->高亮返回结果 键值对
|
||||
*/
|
||||
private final Map<String, String> highlightFieldMap = new HashMap<>();
|
||||
/**
|
||||
* 实体字段名->es字段类型
|
||||
*/
|
||||
private final Map<String, String> fieldTypeMap = new HashMap<>();
|
||||
/**
|
||||
* 实体字段->es实际字段映射
|
||||
*/
|
||||
private final Map<String, String> mappingColumnMap = new HashMap<>();
|
||||
/**
|
||||
* es实际字段映射->实体字段 (仅包含被重命名字段)
|
||||
*/
|
||||
private final Map<String, String> columnMappingMap = new HashMap<>();
|
||||
/**
|
||||
* 不需要序列化JSON的字段 不存在字段,高亮字段等
|
||||
*/
|
||||
private final Set<String> notSerializeField = new HashSet<>();
|
||||
/**
|
||||
* 嵌套类不需要序列化JSON的字段 不存在字段,高亮字段等
|
||||
*/
|
||||
private final Map<Class<?>, Set<String>> nestedNotSerializeField = new HashMap<>();
|
||||
/**
|
||||
* 嵌套类型 path和class对应关系
|
||||
*/
|
||||
private final Map<String, Class<?>> pathClassMap = new HashMap<>();
|
||||
/**
|
||||
* 嵌套类型 实体字段名->字段类型
|
||||
*/
|
||||
private final Map<Class<?>, Map<String, String>> nestedClassFieldTypeMap = new HashMap<>();
|
||||
/**
|
||||
* 嵌套类型 实体字段->es实际字段映射
|
||||
*/
|
||||
private final Map<Class<?>, Map<String, String>> nestedClassMappingColumnMap = new HashMap<>();
|
||||
/**
|
||||
* 嵌套类型 es实际字段映射->实体字段 (仅包含被重命名字段)
|
||||
*/
|
||||
private final Map<Class<?>, Map<String, String>> nestedClassColumnMappingMap = new HashMap<>();
|
||||
/**
|
||||
* fastjson 过滤器
|
||||
*/
|
||||
private final Map<Class<?>, List<SerializeFilter>> classSimplePropertyPreFilterMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 获取需要进行查询的字段列表
|
||||
*
|
||||
* @param predicate 预言
|
||||
* @return 查询字段列表
|
||||
*/
|
||||
public List<String> chooseSelect(Predicate<EntityFieldInfo> predicate) {
|
||||
return fieldList.stream()
|
||||
.filter(predicate)
|
||||
.map(EntityFieldInfo::getColumn)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实体字段映射es中的字段名
|
||||
*
|
||||
* @param column 字段名
|
||||
* @return es中的字段名
|
||||
*/
|
||||
public String getMappingColumn(String column) {
|
||||
return Optional.ofNullable(mappingColumnMap.get(column))
|
||||
.orElse(column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部嵌套类
|
||||
*
|
||||
* @return 嵌套类集合
|
||||
*/
|
||||
public Set<Class<?>> getAllNestedClass() {
|
||||
return nestedClassColumnMappingMap.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据path获取嵌套类字段关系map
|
||||
*
|
||||
* @param path 路径
|
||||
* @return 字段关系map
|
||||
*/
|
||||
public Map<String, String> getNestedMappingColumnMapByPath(String path) {
|
||||
return Optional.ofNullable(pathClassMap.get(path))
|
||||
.map(nestedClassMappingColumnMap::get)
|
||||
.orElse(new HashMap<>(0));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* es索引信息
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class EsIndexInfo {
|
||||
/**
|
||||
* 是否存在默认别名
|
||||
*/
|
||||
private Boolean hasDefaultAlias;
|
||||
/**
|
||||
* 分片数
|
||||
*/
|
||||
private Integer shardsNum;
|
||||
/**
|
||||
* 副本数
|
||||
*/
|
||||
private Integer replicasNum;
|
||||
/**
|
||||
* 最大返回数
|
||||
*/
|
||||
private Integer maxResultWindow;
|
||||
/**
|
||||
* 索引字段信息
|
||||
*/
|
||||
private Map<String, Object> mapping;
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 索引相关参数
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
public class EsIndexParam {
|
||||
/**
|
||||
* 当前嵌套类
|
||||
*/
|
||||
private Class<?> nestedClass;
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
private String fieldName;
|
||||
/**
|
||||
* 字段类型
|
||||
*/
|
||||
private String fieldType;
|
||||
/**
|
||||
* 对 text 字段进行聚合处理
|
||||
*/
|
||||
private Boolean fieldData;
|
||||
/**
|
||||
* 分词器
|
||||
*/
|
||||
private String analyzer;
|
||||
/**
|
||||
* 索引权重
|
||||
*/
|
||||
private Float boost;
|
||||
/**
|
||||
* 查询分词器
|
||||
*/
|
||||
private String searchAnalyzer;
|
||||
/**
|
||||
* 日期格式化 如yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
private String dateFormat;
|
||||
/**
|
||||
* 字段是否忽略大小写,默认不忽略 为true时则忽略大小写
|
||||
*/
|
||||
private boolean ignoreCase;
|
||||
/**
|
||||
* 父名称
|
||||
*/
|
||||
private String parentName;
|
||||
/**
|
||||
* 子名称
|
||||
*/
|
||||
private String childName;
|
||||
}
|
||||
@ -1,206 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页参数 来源:https://github.com/pagehelper/Mybatis-PageHelper
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class EsPageInfo<T> extends PageSerializable<T> {
|
||||
/**
|
||||
* 当前页
|
||||
*/
|
||||
private int pageNum;
|
||||
/**
|
||||
* 每页的数量
|
||||
*/
|
||||
private int pageSize;
|
||||
/**
|
||||
* 当前页的数量
|
||||
*/
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* 当前页面第一个元素在数据库中的行号
|
||||
*/
|
||||
private int startRow;
|
||||
/**
|
||||
* 当前页面最后一个元素在数据库中的行号
|
||||
*/
|
||||
private int endRow;
|
||||
/**
|
||||
* 总页数
|
||||
*/
|
||||
private int pages;
|
||||
|
||||
/**
|
||||
* 前一页
|
||||
*/
|
||||
private int prePage;
|
||||
/**
|
||||
* 下一页
|
||||
*/
|
||||
private int nextPage;
|
||||
|
||||
/**
|
||||
* 是否为第一页
|
||||
*/
|
||||
private boolean isFirstPage = false;
|
||||
/**
|
||||
* 是否为最后一页
|
||||
*/
|
||||
private boolean isLastPage = false;
|
||||
/**
|
||||
* 是否有前一页
|
||||
*/
|
||||
private boolean hasPreviousPage = false;
|
||||
/**
|
||||
* 是否有下一页
|
||||
*/
|
||||
private boolean hasNextPage = false;
|
||||
/**
|
||||
* 导航页码数
|
||||
*/
|
||||
private int navigatePages;
|
||||
/**
|
||||
* 所有导航页号
|
||||
*/
|
||||
private int[] navigatePageNums;
|
||||
/**
|
||||
* 导航条上的第一页
|
||||
*/
|
||||
private int navigateFirstPage;
|
||||
/**
|
||||
* 导航条上的最后一页
|
||||
*/
|
||||
private int navigateLastPage;
|
||||
|
||||
/**
|
||||
* 包装Page对象
|
||||
*
|
||||
* @param list 数据
|
||||
*/
|
||||
public EsPageInfo(List<T> list) {
|
||||
this(list, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 包装Page对象
|
||||
*
|
||||
* @param list 数据
|
||||
* @param navigatePages 导航页
|
||||
*/
|
||||
public EsPageInfo(List<T> list, int navigatePages) {
|
||||
super(list);
|
||||
this.pageNum = 1;
|
||||
this.pageSize = list.size();
|
||||
|
||||
this.pages = this.pageSize > 0 ? 1 : 0;
|
||||
this.size = list.size();
|
||||
this.startRow = 0;
|
||||
this.endRow = list.size() > 0 ? list.size() - 1 : 0;
|
||||
|
||||
this.navigatePages = navigatePages;
|
||||
}
|
||||
|
||||
public static <T> EsPageInfo<T> of(List<T> list) {
|
||||
return new EsPageInfo<T>(list);
|
||||
}
|
||||
|
||||
public static <T> EsPageInfo<T> of(List<T> list, int navigatePages) {
|
||||
return new EsPageInfo<T>(list, navigatePages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算导航页
|
||||
*/
|
||||
public void calcNavigatePageNums() {
|
||||
//当总页数小于或等于导航页码数时
|
||||
if (pages <= navigatePages) {
|
||||
navigatePageNums = new int[pages];
|
||||
for (int i = 0; i < pages; i++) {
|
||||
navigatePageNums[i] = i + 1;
|
||||
}
|
||||
} else { //当总页数大于导航页码数时
|
||||
navigatePageNums = new int[navigatePages];
|
||||
int startNum = pageNum - navigatePages / 2;
|
||||
int endNum = pageNum + navigatePages / 2;
|
||||
|
||||
if (startNum < 1) {
|
||||
startNum = 1;
|
||||
//(最前navigatePages页
|
||||
for (int i = 0; i < navigatePages; i++) {
|
||||
navigatePageNums[i] = startNum++;
|
||||
}
|
||||
} else if (endNum > pages) {
|
||||
endNum = pages;
|
||||
//最后navigatePages页
|
||||
for (int i = navigatePages - 1; i >= 0; i--) {
|
||||
navigatePageNums[i] = endNum--;
|
||||
}
|
||||
} else {
|
||||
//所有中间页
|
||||
for (int i = 0; i < navigatePages; i++) {
|
||||
navigatePageNums[i] = startNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算前后页,第一页,最后一页
|
||||
*/
|
||||
public void calcPage() {
|
||||
if (navigatePageNums != null && navigatePageNums.length > 0) {
|
||||
navigateFirstPage = navigatePageNums[0];
|
||||
navigateLastPage = navigatePageNums[navigatePageNums.length - 1];
|
||||
if (pageNum > 1) {
|
||||
prePage = pageNum - 1;
|
||||
}
|
||||
if (pageNum < pages) {
|
||||
nextPage = pageNum + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判定页面边界
|
||||
*/
|
||||
public void judgePageBoundary() {
|
||||
isFirstPage = pageNum == 1;
|
||||
isLastPage = pageNum == pages || pages == 0;
|
||||
hasPreviousPage = pageNum > 1;
|
||||
hasNextPage = pageNum < pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PageInfo{" +
|
||||
"pageNum=" + pageNum +
|
||||
", pageSize=" + pageSize +
|
||||
", size=" + size +
|
||||
", startRow=" + startRow +
|
||||
", endRow=" + endRow +
|
||||
", pages=" + pages +
|
||||
", prePage=" + prePage +
|
||||
", nextPage=" + nextPage +
|
||||
", isFirstPage=" + isFirstPage +
|
||||
", isLastPage=" + isLastPage +
|
||||
", hasPreviousPage=" + hasPreviousPage +
|
||||
", hasNextPage=" + hasNextPage +
|
||||
", navigatePages=" + navigatePages +
|
||||
", navigatepageNums=" + Arrays.toString(navigatePageNums) +
|
||||
", navigateFirstPage=" + navigateFirstPage +
|
||||
", navigateLastPage=" + navigateLastPage +
|
||||
", total=" + total +
|
||||
", list=" + list +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新参数
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
public class EsUpdateParam {
|
||||
/**
|
||||
* 字段
|
||||
*/
|
||||
private String field;
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
private Object value;
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.annotation.rely.HighLightTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 高亮参数
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class HighLightParam {
|
||||
/**
|
||||
* 高亮字段截取长度,默认为100
|
||||
*/
|
||||
private int fragmentSize;
|
||||
/**
|
||||
* 前置标签
|
||||
*/
|
||||
private String preTag;
|
||||
/**
|
||||
* 后置标签
|
||||
*/
|
||||
private String postTag;
|
||||
/**
|
||||
* 高亮字段列表
|
||||
*/
|
||||
private String highLightField;
|
||||
/**
|
||||
* 高亮字段类型
|
||||
*/
|
||||
private HighLightTypeEnum highLightType;
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 自定义排序参数 通常由前端传入
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
public class OrderByParam {
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private String order;
|
||||
/**
|
||||
* 排序规则 ASC:升序 DESC:降序
|
||||
*/
|
||||
private String sort;
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页参数 来源:https://github.com/pagehelper/Mybatis-PageHelper
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class PageSerializable<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
protected long total;
|
||||
/**
|
||||
* 结果集
|
||||
*/
|
||||
protected List<T> list;
|
||||
|
||||
public PageSerializable(List<T> list) {
|
||||
this.list = list;
|
||||
this.total = list.size();
|
||||
}
|
||||
|
||||
public static <T> PageSerializable<T> of(List<T> list) {
|
||||
return new PageSerializable<T>(list);
|
||||
}
|
||||
}
|
||||
@ -1,66 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.common.enums.EsQueryTypeEnum;
|
||||
import cn.easyes.core.toolkit.Tree;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 查询参数树
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
public class Param extends Tree {
|
||||
/**
|
||||
* 上一节点类型
|
||||
*/
|
||||
private EsQueryTypeEnum prevQueryType;
|
||||
/**
|
||||
* 节点类型
|
||||
*/
|
||||
private EsQueryTypeEnum queryTypeEnum;
|
||||
/**
|
||||
* 是否nested嵌套查询类型
|
||||
*/
|
||||
private boolean nested;
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
private String column;
|
||||
/**
|
||||
* 字段值
|
||||
*/
|
||||
private Object val;
|
||||
/**
|
||||
* 权重
|
||||
*/
|
||||
private Float boost;
|
||||
|
||||
/**
|
||||
* 多用途拓展字段1
|
||||
*/
|
||||
private Object ext1;
|
||||
|
||||
/**
|
||||
* 多用途拓展字段2
|
||||
*/
|
||||
private Object ext2;
|
||||
/**
|
||||
* 多用途拓展字段3
|
||||
*/
|
||||
private Object ext3;
|
||||
/**
|
||||
* 多用途拓展字段4
|
||||
*/
|
||||
private Object ext4;
|
||||
|
||||
/**
|
||||
* 多字段名称
|
||||
*/
|
||||
private String[] columns;
|
||||
|
||||
/**
|
||||
* 字段是否需要拼接.keyword后缀 默认不需要
|
||||
*/
|
||||
private boolean needAddKeywordSuffix;
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* searchAfter 分页参数
|
||||
**/
|
||||
@Data
|
||||
public class SAPageInfo<T> extends PageSerializable<T> {
|
||||
/**
|
||||
* 当前sort
|
||||
*/
|
||||
private List<Object> searchAfter;
|
||||
/**
|
||||
* 每页的数量
|
||||
*/
|
||||
private int pageSize;
|
||||
/**
|
||||
* 总页数
|
||||
*/
|
||||
private int pages;
|
||||
/**
|
||||
* 下一页sort
|
||||
*/
|
||||
private List<Object> nextSearchAfter;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SAPageInfo{" +
|
||||
"searchAfter=" + searchAfter +
|
||||
", pageSize=" + pageSize +
|
||||
", pages=" + pages +
|
||||
", nextSearchAfter=" + nextSearchAfter +
|
||||
", total=" + total +
|
||||
", list=" + list +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,129 +0,0 @@
|
||||
package cn.easyes.core.cache;
|
||||
|
||||
import cn.easyes.common.constants.BaseEsConstants;
|
||||
import cn.easyes.common.utils.CollectionUtils;
|
||||
import cn.easyes.common.utils.ExceptionUtils;
|
||||
import cn.easyes.core.biz.EntityInfo;
|
||||
import cn.easyes.core.core.BaseEsMapperImpl;
|
||||
import cn.easyes.core.toolkit.EntityInfoHelper;
|
||||
import cn.easyes.core.toolkit.FieldUtils;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 基本缓存
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class BaseCache {
|
||||
/**
|
||||
* 用于存放BaseEsMapper的所有实例
|
||||
*/
|
||||
private static final Map<Class<?>, BaseEsMapperImpl<?>> baseEsMapperInstanceMap = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* 用于存放Es entity 中的字段的get/is方法
|
||||
*/
|
||||
private static final Map<Class<?>, Map<String, Method>> baseEsEntityMethodMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 初始化缓存
|
||||
*
|
||||
* @param mapperInterface mapper接口
|
||||
* @param client es客户端
|
||||
* @param entityClass 实体类
|
||||
*/
|
||||
public static void initCache(Class<?> mapperInterface, Class<?> entityClass, RestHighLevelClient client) {
|
||||
// 初始化baseEsMapper的所有实现类实例
|
||||
BaseEsMapperImpl baseEsMapper = new BaseEsMapperImpl();
|
||||
baseEsMapper.setClient(client);
|
||||
|
||||
baseEsMapper.setEntityClass(entityClass);
|
||||
baseEsMapperInstanceMap.put(mapperInterface, baseEsMapper);
|
||||
|
||||
// 初始化entity中所有字段(注解策略生效)
|
||||
Map<String, Method> invokeMethodsMap = initInvokeMethodsMap(entityClass);
|
||||
baseEsEntityMethodMap.putIfAbsent(entityClass, invokeMethodsMap);
|
||||
|
||||
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
||||
// 初始化嵌套类中的所有方法
|
||||
Set<Class<?>> allNestedClass = entityInfo.getAllNestedClass();
|
||||
if (CollectionUtils.isNotEmpty(allNestedClass)) {
|
||||
allNestedClass.forEach(nestedClass -> {
|
||||
Map<String, Method> nestedInvokeMethodsMap = initInvokeMethodsMap(nestedClass);
|
||||
baseEsEntityMethodMap.putIfAbsent(nestedClass, nestedInvokeMethodsMap);
|
||||
});
|
||||
}
|
||||
|
||||
// 初始化父子类型JoinField中的所有方法
|
||||
Map<String, Method> joinInvokeMethodsMap = initInvokeMethodsMap(entityInfo.getJoinFieldClass());
|
||||
BaseCache.baseEsEntityMethodMap.putIfAbsent(entityInfo.getJoinFieldClass(), joinInvokeMethodsMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化get及set方法容器
|
||||
*
|
||||
* @param clazz 类
|
||||
* @return 指定类的get及set方法容器
|
||||
*/
|
||||
private static Map<String, Method> initInvokeMethodsMap(Class<?> clazz) {
|
||||
Method[] methods = clazz.getMethods();
|
||||
Map<String, Method> invokeMethodsMap = new ConcurrentHashMap<>(methods.length);
|
||||
Arrays.stream(methods)
|
||||
.forEach(entityMethod -> {
|
||||
String methodName = entityMethod.getName();
|
||||
if (methodName.startsWith(BaseEsConstants.GET_FUNC_PREFIX) || methodName.startsWith(BaseEsConstants.IS_FUNC_PREFIX)
|
||||
|| methodName.startsWith(BaseEsConstants.SET_FUNC_PREFIX)) {
|
||||
invokeMethodsMap.put(methodName, entityMethod);
|
||||
}
|
||||
});
|
||||
return invokeMethodsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存中对应的BaseEsMapperImpl
|
||||
*
|
||||
* @param mapperInterface mapper接口
|
||||
* @return 实现类
|
||||
*/
|
||||
public static BaseEsMapperImpl<?> getBaseEsMapperInstance(Class<?> mapperInterface) {
|
||||
return Optional.ofNullable(baseEsMapperInstanceMap.get(mapperInterface))
|
||||
.orElseThrow(() -> ExceptionUtils.eee("no such instance", mapperInterface));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存中对应entity和methodName的getter方法
|
||||
*
|
||||
* @param entityClass 实体
|
||||
* @param methodName 方法名
|
||||
* @return 执行方法
|
||||
*/
|
||||
public static Method getterMethod(Class<?> entityClass, String methodName) {
|
||||
return Optional.ofNullable(BaseCache.baseEsEntityMethodMap.get(entityClass))
|
||||
.map(b -> {
|
||||
Method method = b.get(BaseEsConstants.GET_FUNC_PREFIX + FieldUtils.firstToUpperCase(methodName));
|
||||
if (Objects.isNull(method)) {
|
||||
// 兼容基本数据类型boolean
|
||||
method = b.get(BaseEsConstants.IS_FUNC_PREFIX + FieldUtils.firstToUpperCase(methodName));
|
||||
}
|
||||
return method;
|
||||
})
|
||||
.orElseThrow(() -> ExceptionUtils.eee("no such method:", entityClass, methodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存中对应entity和methodName的setter方法
|
||||
*
|
||||
* @param entityClass 实体
|
||||
* @param methodName 方法名
|
||||
* @return 执行方法
|
||||
*/
|
||||
public static Method setterMethod(Class<?> entityClass, String methodName) {
|
||||
return Optional.ofNullable(baseEsEntityMethodMap.get(entityClass))
|
||||
.map(b -> b.get(BaseEsConstants.SET_FUNC_PREFIX + FieldUtils.firstToUpperCase(methodName)))
|
||||
.orElseThrow(() -> ExceptionUtils.eee("no such method:", entityClass, methodName));
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package cn.easyes.core.cache;
|
||||
|
||||
import cn.easyes.core.config.GlobalConfig;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 全局配置缓存
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class GlobalConfigCache {
|
||||
|
||||
private static final Map<Class<?>, GlobalConfig> globalConfigMap = new ConcurrentHashMap<>(1);
|
||||
|
||||
public static GlobalConfig getGlobalConfig() {
|
||||
return Optional.ofNullable(globalConfigMap.get(GlobalConfig.class))
|
||||
.orElseGet(() -> {
|
||||
GlobalConfig globalConfig = new GlobalConfig();
|
||||
GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
|
||||
globalConfig.setDbConfig(dbConfig);
|
||||
return globalConfig;
|
||||
});
|
||||
}
|
||||
|
||||
public static void setGlobalConfig(GlobalConfig globalConfig) {
|
||||
globalConfigMap.putIfAbsent(GlobalConfig.class, globalConfig);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,307 +0,0 @@
|
||||
package cn.easyes.core.conditions.function;
|
||||
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.core.toolkit.FieldUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 索引相关
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface Index<Children, R> extends Serializable {
|
||||
/**
|
||||
* 设置索引名称
|
||||
*
|
||||
* @param indexNames 索引名称
|
||||
* @return wrapper
|
||||
*/
|
||||
Children indexName(String... indexNames);
|
||||
|
||||
/**
|
||||
* 设置最大返回数
|
||||
*
|
||||
* @param maxResultWindow 最大返回数
|
||||
* @return wrapper
|
||||
*/
|
||||
Children maxResultWindow(Integer maxResultWindow);
|
||||
|
||||
/**
|
||||
* 设置索引的分片数和副本数
|
||||
*
|
||||
* @param shards 分片数
|
||||
* @param replicas 副本数
|
||||
* @return wrapper
|
||||
*/
|
||||
Children settings(Integer shards, Integer replicas);
|
||||
|
||||
/**
|
||||
* 用户手动指定的settings
|
||||
*
|
||||
* @param settings settings
|
||||
* @return wrapper
|
||||
*/
|
||||
Children settings(Settings settings);
|
||||
|
||||
/**
|
||||
* 用户自行指定mapping
|
||||
*
|
||||
* @param mapping mapping信息
|
||||
* @return wrapper
|
||||
*/
|
||||
Children mapping(Map<String, Object> mapping);
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列
|
||||
* @param fieldType es中的索引类型
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(R column, FieldType fieldType) {
|
||||
return mapping(column, fieldType, null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列
|
||||
* @param fieldType es中的类型
|
||||
* @param fieldData 是否支持text字段聚合
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(R column, FieldType fieldType, Boolean fieldData) {
|
||||
return mapping(column, fieldType, null, null, null, fieldData, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column
|
||||
* @param fieldType es中的类型
|
||||
* @param boost 权重
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(R column, FieldType fieldType, Float boost) {
|
||||
return mapping(column, fieldType, null, null, null, null, boost);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列
|
||||
* @param fieldType es中的类型
|
||||
* @param fieldData 是否支持text字段聚合
|
||||
* @param boost 权重
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(R column, FieldType fieldType, Boolean fieldData, Float boost) {
|
||||
return mapping(column, fieldType, null, null, null, fieldData, boost);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列
|
||||
* @param fieldType es中的类型
|
||||
* @param dateFormat 日期格式
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(R column, FieldType fieldType, String dateFormat) {
|
||||
return mapping(column, fieldType, null, null, dateFormat, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列
|
||||
* @param fieldType es中的类型
|
||||
* @param analyzer 索引分词器
|
||||
* @param searchAnalyzer 查询分词器
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(R column, FieldType fieldType, String analyzer, String searchAnalyzer) {
|
||||
return mapping(column, fieldType, analyzer, searchAnalyzer, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列
|
||||
* @param fieldType es中的类型
|
||||
* @param analyzer 索引分词器
|
||||
* @param searchAnalyzer 查询分词器
|
||||
* @param dateFormat 日期格式
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(R column, FieldType fieldType, String analyzer, String searchAnalyzer, String dateFormat) {
|
||||
return mapping(column, fieldType, analyzer, searchAnalyzer, dateFormat, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列名
|
||||
* @param fieldType es中的类型
|
||||
* @param analyzer 索引分词器
|
||||
* @param searchAnalyzer 查询分词器
|
||||
* @param boost 权重
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(R column, FieldType fieldType, String analyzer, String searchAnalyzer, Float boost) {
|
||||
return mapping(column, fieldType, analyzer, searchAnalyzer, null, null, boost);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列
|
||||
* @param fieldType es中的类型
|
||||
* @param analyzer 分词器类型
|
||||
* @param searchAnalyzer 查询分词器类型
|
||||
* @param dateFormat 日期格式
|
||||
* @param fieldData 是否支持text字段聚合
|
||||
* @param boost 权重值
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(R column, FieldType fieldType, String analyzer, String searchAnalyzer, String dateFormat, Boolean fieldData, Float boost) {
|
||||
return mapping(FieldUtils.getFieldName(column), fieldType, analyzer, searchAnalyzer, dateFormat, fieldData, boost);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param fieldType es中的类型
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(String column, FieldType fieldType) {
|
||||
return mapping(column, fieldType, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param fieldType es中的类型
|
||||
* @param fieldData 是否支持text字段聚合
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(String column, FieldType fieldType, Boolean fieldData) {
|
||||
return mapping(column, fieldType, null, null, fieldData, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param fieldType es中的类型
|
||||
* @param boost 权重
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(String column, FieldType fieldType, Float boost) {
|
||||
return mapping(column, fieldType, null, null, null, boost);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param fieldType es中的类型
|
||||
* @param analyzer 索引分词器
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(String column, FieldType fieldType, String analyzer) {
|
||||
return mapping(column, fieldType, analyzer, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param fieldType es中的类型
|
||||
* @param analyzer 索引分词器
|
||||
* @param searchAnalyzer 查询分词器
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(String column, FieldType fieldType, String analyzer, String searchAnalyzer) {
|
||||
return mapping(column, fieldType, analyzer, searchAnalyzer, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param fieldType es中的类型
|
||||
* @param analyzer 索引分词器
|
||||
* @param searchAnalyzer 查询分词器
|
||||
* @param fieldData 是否支持text字段聚合
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(String column, FieldType fieldType, String analyzer, String searchAnalyzer, Boolean fieldData) {
|
||||
return mapping(column, fieldType, analyzer, searchAnalyzer, fieldData, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param fieldType es中的类型
|
||||
* @param analyzer 索引分词器类型
|
||||
* @param searchAnalyzer 查询分词器类型
|
||||
* @param fieldData 是否支持text字段聚合
|
||||
* @param boost 权重
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children mapping(String column, FieldType fieldType, String analyzer, String searchAnalyzer, Boolean fieldData, Float boost) {
|
||||
return mapping(column, fieldType, analyzer, searchAnalyzer, null, fieldData, boost);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置mapping信息
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param fieldType es中的类型
|
||||
* @param analyzer 索引分词器类型
|
||||
* @param searchAnalyzer 查询分词器类型
|
||||
* @param dateFormat 日期格式
|
||||
* @param fieldData 是否支持text字段聚合
|
||||
* @param boost 字段权重值
|
||||
* @return wrapper
|
||||
*/
|
||||
Children mapping(String column, FieldType fieldType, String analyzer, String searchAnalyzer, String dateFormat, Boolean fieldData, Float boost);
|
||||
|
||||
/**
|
||||
* 设置创建别名信息
|
||||
*
|
||||
* @param aliasName 别名
|
||||
* @return wrapper
|
||||
*/
|
||||
Children createAlias(String aliasName);
|
||||
|
||||
/**
|
||||
* 设置父子类型信息
|
||||
*
|
||||
* @param column 列
|
||||
* @param parentName 父名称
|
||||
* @param childName 子名称
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children join(R column, String parentName, String childName) {
|
||||
return join(FieldUtils.getFieldName(childName), parentName, childName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置父子类型信息
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param parentName 父名称
|
||||
* @param childName 子名称
|
||||
* @return wrapper
|
||||
*/
|
||||
Children join(String column, String parentName, String childName);
|
||||
}
|
||||
@ -1,61 +0,0 @@
|
||||
package cn.easyes.core.conditions.function;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 连接相关
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface Join<Children> extends Serializable {
|
||||
/**
|
||||
* 拼接filter
|
||||
*
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children filter() {
|
||||
return filter(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接filter
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @return wrapper
|
||||
*/
|
||||
Children filter(boolean condition);
|
||||
|
||||
/**
|
||||
* 拼接or
|
||||
*
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children or() {
|
||||
return or(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接 OR
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @return wrapper
|
||||
*/
|
||||
Children or(boolean condition);
|
||||
|
||||
/**
|
||||
* 拼接not
|
||||
*
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children not() {
|
||||
return not(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接not
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @return wrapper
|
||||
*/
|
||||
Children not(boolean condition);
|
||||
}
|
||||
@ -1,171 +0,0 @@
|
||||
package cn.easyes.core.conditions.function;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 嵌套关系
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface Nested<Param, Children> extends Serializable {
|
||||
/**
|
||||
* AND 嵌套 保留mp用户习惯
|
||||
*
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children and(Consumer<Param> consumer) {
|
||||
return and(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* AND 嵌套 保留mp用户习惯
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
Children and(boolean condition, Consumer<Param> consumer);
|
||||
|
||||
/**
|
||||
* OR 嵌套 保留mp用户习惯
|
||||
*
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children or(Consumer<Param> consumer) {
|
||||
return or(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* OR 嵌套 保留mp用户习惯
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
Children or(boolean condition, Consumer<Param> consumer);
|
||||
|
||||
/**
|
||||
* must 嵌套 等价于and
|
||||
*
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children must(Consumer<Param> consumer) {
|
||||
return must(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* must 嵌套 等价于and
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
Children must(boolean condition, Consumer<Param> consumer);
|
||||
|
||||
/**
|
||||
* should 嵌套 等价于or
|
||||
*
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children should(Consumer<Param> consumer) {
|
||||
return should(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* should 嵌套 等价于or
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
Children should(boolean condition, Consumer<Param> consumer);
|
||||
|
||||
/**
|
||||
* filter 嵌套 和and及must功能基本一致,但filter不返回得分,效率更高
|
||||
*
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children filter(Consumer<Param> consumer) {
|
||||
return filter(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* filter 嵌套 和and及must功能基本一致,但filter不返回得分,效率更高
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param consumer 条件函数
|
||||
* @return 泛型
|
||||
*/
|
||||
Children filter(boolean condition, Consumer<Param> consumer);
|
||||
|
||||
/**
|
||||
* must not 嵌套 等价于 must条件取反,即 非must
|
||||
*
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children not(Consumer<Param> consumer) {
|
||||
return not(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* must not 嵌套 等价于 must条件取反,即 非must
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
Children not(boolean condition, Consumer<Param> consumer);
|
||||
|
||||
/**
|
||||
* @param path 上级路径
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children nested(String path, Consumer<Param> consumer) {
|
||||
return nested(true, path, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 嵌套类型查询
|
||||
*
|
||||
* @param path 上级路径
|
||||
* @param consumer 嵌套条件函数
|
||||
* @param scoreMode 得分模式
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children nested(String path, Consumer<Param> consumer, ScoreMode scoreMode) {
|
||||
return nested(true, path, consumer, scoreMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 嵌套类型查询
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param path 上级路径
|
||||
* @param consumer 嵌套条件函数
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children nested(boolean condition, String path, Consumer<Param> consumer) {
|
||||
return nested(condition, path, consumer, ScoreMode.None);
|
||||
}
|
||||
|
||||
/**
|
||||
* 嵌套类型查询
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param path 上级路径
|
||||
* @param consumer 嵌套条件函数
|
||||
* @param scoreMode 得分模式
|
||||
* @return wrapper
|
||||
*/
|
||||
Children nested(boolean condition, String path, Consumer<Param> consumer, ScoreMode scoreMode);
|
||||
}
|
||||
@ -1,119 +0,0 @@
|
||||
package cn.easyes.core.conditions.function;
|
||||
|
||||
import cn.easyes.core.biz.EntityFieldInfo;
|
||||
import cn.easyes.core.toolkit.FieldUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* 查询相关
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface Query<Children, T, R> extends Serializable {
|
||||
/**
|
||||
* 设置查询字段
|
||||
*
|
||||
* @param column 查询列
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children select(R column) {
|
||||
return select(FieldUtils.getFieldNameNotConvertId(column));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询字段
|
||||
*
|
||||
* @param columns 查询列
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children select(R... columns) {
|
||||
return select(Arrays.stream(columns).map(FieldUtils::getFieldNameNotConvertId).toArray(String[]::new));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置查询字段
|
||||
*
|
||||
* @param columns 查询列,支持多字段
|
||||
* @return wrapper
|
||||
*/
|
||||
Children select(String... columns);
|
||||
|
||||
/**
|
||||
* 查询字段
|
||||
*
|
||||
* @param predicate 预言
|
||||
* @return wrapper
|
||||
*/
|
||||
Children select(Predicate<EntityFieldInfo> predicate);
|
||||
|
||||
/**
|
||||
* 过滤查询的字段信息(主键除外!)
|
||||
*
|
||||
* @param entityClass 实体类
|
||||
* @param predicate 预言
|
||||
* @return wrapper
|
||||
*/
|
||||
Children select(Class<T> entityClass, Predicate<EntityFieldInfo> predicate);
|
||||
|
||||
/**
|
||||
* 设置不查询字段
|
||||
*
|
||||
* @param column 不查询列
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children notSelect(R column) {
|
||||
return notSelect(FieldUtils.getFieldNameNotConvertId(column));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置不查询字段
|
||||
*
|
||||
* @param columns 不查询列
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children notSelect(R... columns) {
|
||||
return notSelect(Arrays.stream(columns).map(FieldUtils::getFieldNameNotConvertId).toArray(String[]::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置不查询字段
|
||||
*
|
||||
* @param columns 不查询字段,支持多字段
|
||||
* @return wrapper
|
||||
*/
|
||||
Children notSelect(String... columns);
|
||||
|
||||
/**
|
||||
* 设置当前操作的索引名称
|
||||
*
|
||||
* @param indexName 索引名
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children index(String indexName) {
|
||||
return index(true, indexName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前操作的索引名称
|
||||
*
|
||||
* @param indexNames 索引名
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children index(String... indexNames) {
|
||||
return index(true, indexNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前操作的索引名称
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param indexNames 索引名
|
||||
* @return wrapper
|
||||
*/
|
||||
Children index(boolean condition, String... indexNames);
|
||||
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
package cn.easyes.core.conditions.function;
|
||||
|
||||
import cn.easyes.core.toolkit.FieldUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 更新相关
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface Update<Children, R> extends Serializable {
|
||||
/**
|
||||
* 设置 更新 字段 的 SET 片段
|
||||
*
|
||||
* @param column 列
|
||||
* @param val 值
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children set(R column, Object val) {
|
||||
return set(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 更新 字段 的 SET 片段
|
||||
*
|
||||
* @param column 列名 字符串
|
||||
* @param val 值
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children set(String column, Object val) {
|
||||
return set(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 更新 字段 的 SET 片段
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 列
|
||||
* @param val 值
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children set(boolean condition, R column, Object val) {
|
||||
return set(condition, FieldUtils.getFieldName(column), val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 更新 字段 的 SET 片段
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param column 列
|
||||
* @param val 值
|
||||
* @return wrapper
|
||||
*/
|
||||
Children set(boolean condition, String column, Object val);
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package cn.easyes.core.conditions.index;
|
||||
|
||||
import cn.easyes.common.params.SFunction;
|
||||
import cn.easyes.core.core.AbstractWrapper;
|
||||
|
||||
/**
|
||||
* 抽象Lambda表达式父类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public abstract class AbstractLambdaIndexWrapper<T, Children extends AbstractLambdaIndexWrapper<T, Children>>
|
||||
extends AbstractWrapper<T, SFunction<T, ?>, Children> {
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
package cn.easyes.core.conditions.index;
|
||||
|
||||
import cn.easyes.core.core.EsChainWrapper;
|
||||
|
||||
/**
|
||||
* 链式更新方法
|
||||
* <p>
|
||||
* Copyright © 2023 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface EsChainIndex<T> extends EsChainWrapper<T> {
|
||||
|
||||
/**
|
||||
* 创建索引 手动挡自定义模式 灵活度最高 使用难度稍高
|
||||
*
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
default Boolean createIndex() {
|
||||
return getBaseEsMapper().createIndex(getWrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新索引 手动挡
|
||||
*
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
default Boolean updateIndex() {
|
||||
return getBaseEsMapper().updateIndex(getWrapper());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
package cn.easyes.core.conditions.index;
|
||||
|
||||
|
||||
import cn.easyes.common.params.SFunction;
|
||||
import cn.easyes.core.core.AbstractChainWrapper;
|
||||
import cn.easyes.core.core.BaseEsMapper;
|
||||
|
||||
/**
|
||||
* 链式索引条件构造器
|
||||
* <p>
|
||||
* Copyright © 2023 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@SuppressWarnings({"serial"})
|
||||
public class LambdaEsIndexChainWrapper<T> extends AbstractChainWrapper<T, SFunction<T, ?>, LambdaEsIndexChainWrapper<T>, LambdaEsIndexWrapper<T>>
|
||||
implements EsChainIndex<T> {
|
||||
|
||||
private final BaseEsMapper<T> baseEsMapper;
|
||||
|
||||
public LambdaEsIndexChainWrapper(BaseEsMapper<T> baseEsMapper) {
|
||||
super();
|
||||
this.baseEsMapper = baseEsMapper;
|
||||
super.wrapperChildren = new LambdaEsIndexWrapper<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseEsMapper<T> getBaseEsMapper() {
|
||||
return baseEsMapper;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
package cn.easyes.core.conditions.index;
|
||||
|
||||
|
||||
import cn.easyes.core.biz.EsIndexParam;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 索引Lambda表达式
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@SuppressWarnings("serial")
|
||||
public class LambdaEsIndexWrapper<T> extends AbstractLambdaIndexWrapper<T, LambdaEsIndexWrapper<T>> {
|
||||
/**
|
||||
* 不建议直接 new 该实例,使用 Wrappers.lambdaQuery(entity)
|
||||
*/
|
||||
public LambdaEsIndexWrapper() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public LambdaEsIndexWrapper(Class<T> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
esIndexParamList = new ArrayList<>();
|
||||
}
|
||||
|
||||
LambdaEsIndexWrapper(T entity, List<EsIndexParam> indexParamList) {
|
||||
super.setEntity(entity);
|
||||
this.esIndexParamList = indexParamList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LambdaEsIndexWrapper<T> instance() {
|
||||
return new LambdaEsIndexWrapper<>(entity, esIndexParamList);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package cn.easyes.core.conditions.select;
|
||||
|
||||
import cn.easyes.common.params.SFunction;
|
||||
import cn.easyes.core.core.AbstractWrapper;
|
||||
|
||||
/**
|
||||
* 抽象Lambda表达式父类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public abstract class AbstractLambdaQueryWrapper<T, Children extends AbstractLambdaQueryWrapper<T, Children>>
|
||||
extends AbstractWrapper<T, SFunction<T, ?>, Children> {
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
package cn.easyes.core.conditions.select;
|
||||
|
||||
|
||||
import cn.easyes.core.biz.EsPageInfo;
|
||||
import cn.easyes.core.biz.SAPageInfo;
|
||||
import cn.easyes.core.core.EsChainWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 链式查询方法
|
||||
* <p>
|
||||
* Copyright © 2023 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface EsChainQuery<T> extends EsChainWrapper<T> {
|
||||
|
||||
/**
|
||||
* 获取集合
|
||||
*
|
||||
* @return 集合
|
||||
*/
|
||||
default List<T> list() {
|
||||
return getBaseEsMapper().selectList(getWrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个
|
||||
*
|
||||
* @return 单个
|
||||
*/
|
||||
default T one() {
|
||||
return getBaseEsMapper().selectOne(getWrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个
|
||||
*
|
||||
* @return 单个
|
||||
*/
|
||||
default Optional<T> oneOpt() {
|
||||
return Optional.ofNullable(one());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 count
|
||||
*
|
||||
* @return count
|
||||
*/
|
||||
default Long count() {
|
||||
return (getBaseEsMapper().selectCount(getWrapper()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数据是否存在
|
||||
*
|
||||
* @return true 存在 false 不存在
|
||||
*/
|
||||
default boolean exists() {
|
||||
return this.count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分页数据
|
||||
*
|
||||
* @param pageNum 当前页
|
||||
* @param pageSize 每页条数
|
||||
* @return 分页数据
|
||||
*/
|
||||
default EsPageInfo<T> page(Integer pageNum, Integer pageSize) {
|
||||
return getBaseEsMapper().pageQuery(getWrapper(), pageNum, pageSize);
|
||||
}
|
||||
|
||||
default SAPageInfo<T> searchAfterPage(List<Object> searchAfter, Integer pageSize) {
|
||||
return getBaseEsMapper().searchAfterPage(getWrapper(), searchAfter, pageSize);
|
||||
}
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
package cn.easyes.core.conditions.select;
|
||||
|
||||
import cn.easyes.common.params.SFunction;
|
||||
import cn.easyes.core.core.AbstractChainWrapper;
|
||||
import cn.easyes.core.core.BaseEsMapper;
|
||||
import cn.easyes.core.conditions.function.Query;
|
||||
|
||||
/**
|
||||
* 链式调用Lambda表达式
|
||||
* <p>
|
||||
* Copyright © 2023 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@SuppressWarnings({"serial"})
|
||||
public class LambdaEsQueryChainWrapper<T> extends AbstractChainWrapper<T, SFunction<T, ?>, LambdaEsQueryChainWrapper<T>, LambdaEsQueryWrapper<T>>
|
||||
implements EsChainQuery<T>, Query<LambdaEsQueryChainWrapper<T>, T, SFunction<T, ?>> {
|
||||
|
||||
private final BaseEsMapper<T> baseEsMapper;
|
||||
|
||||
public LambdaEsQueryChainWrapper(BaseEsMapper<T> baseEsMapper) {
|
||||
super();
|
||||
this.baseEsMapper = baseEsMapper;
|
||||
super.wrapperChildren = new LambdaEsQueryWrapper<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseEsMapper<T> getBaseEsMapper() {
|
||||
return baseEsMapper;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
package cn.easyes.core.conditions.select;
|
||||
|
||||
import cn.easyes.common.enums.EsQueryTypeEnum;
|
||||
import cn.easyes.core.biz.AggregationParam;
|
||||
import cn.easyes.core.biz.BaseSortParam;
|
||||
import cn.easyes.core.biz.Param;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* 查询Lambda表达式
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@SuppressWarnings("serial")
|
||||
public class LambdaEsQueryWrapper<T> extends AbstractLambdaQueryWrapper<T, LambdaEsQueryWrapper<T>> {
|
||||
|
||||
/**
|
||||
* 不建议直接 new 该实例,使用 Wrappers.lambdaQuery(entity)
|
||||
*/
|
||||
public LambdaEsQueryWrapper() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public LambdaEsQueryWrapper(Class<T> entityClass) {
|
||||
super.initNeed();
|
||||
super.setEntityClass(entityClass);
|
||||
include = new String[]{};
|
||||
exclude = new String[]{};
|
||||
}
|
||||
|
||||
LambdaEsQueryWrapper(T entity, int level, String parentId, EsQueryTypeEnum pervQueryType, LinkedList<Param> paramList,
|
||||
Stack<String> parentIdStack, LinkedList<EsQueryTypeEnum> prevQueryTypeQueue,
|
||||
List<BaseSortParam> baseSortParams, List<AggregationParam> aggregationParamList) {
|
||||
super.setEntity(entity);
|
||||
this.level = level;
|
||||
this.parentId = parentId;
|
||||
this.prevQueryType = pervQueryType;
|
||||
this.paramQueue = paramList;
|
||||
this.parentIdStack = parentIdStack;
|
||||
this.prevQueryTypeQueue = prevQueryTypeQueue;
|
||||
this.baseSortParams = baseSortParams;
|
||||
this.aggregationParamList = aggregationParamList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LambdaEsQueryWrapper<T> instance() {
|
||||
return new LambdaEsQueryWrapper<>(entity, level, parentId, prevQueryType, paramQueue, parentIdStack, prevQueryTypeQueue, baseSortParams, aggregationParamList);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package cn.easyes.core.conditions.update;
|
||||
|
||||
import cn.easyes.common.params.SFunction;
|
||||
import cn.easyes.core.core.AbstractWrapper;
|
||||
|
||||
/**
|
||||
* 抽象Lambda表达式父类
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public abstract class AbstractLambdaUpdateWrapper<T, Children extends AbstractLambdaUpdateWrapper<T, Children>>
|
||||
extends AbstractWrapper<T, SFunction<T, ?>, Children> {
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package cn.easyes.core.conditions.update;
|
||||
|
||||
import cn.easyes.core.core.EsChainWrapper;
|
||||
|
||||
/**
|
||||
* 链式更新方法
|
||||
* <p>
|
||||
* Copyright © 2023 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface EsChainUpdate<T> extends EsChainWrapper<T> {
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
default Integer update() {
|
||||
return update(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param entity 实体类
|
||||
* @return 是否成功
|
||||
*/
|
||||
default Integer update(T entity) {
|
||||
return getBaseEsMapper().update(entity, getWrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
default Integer remove() {
|
||||
return getBaseEsMapper().delete(getWrapper());
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package cn.easyes.core.conditions.update;
|
||||
|
||||
|
||||
import cn.easyes.common.params.SFunction;
|
||||
import cn.easyes.core.core.AbstractChainWrapper;
|
||||
import cn.easyes.core.core.BaseEsMapper;
|
||||
|
||||
/**
|
||||
* 链式更新条件构造器
|
||||
* <p>
|
||||
* Copyright © 2023 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@SuppressWarnings({"serial"})
|
||||
public class LambdaEsUpdateChainWrapper<T> extends AbstractChainWrapper<T, SFunction<T, ?>, LambdaEsUpdateChainWrapper<T>, LambdaEsUpdateWrapper<T>>
|
||||
implements EsChainUpdate<T> {
|
||||
|
||||
private final BaseEsMapper<T> baseEsMapper;
|
||||
|
||||
public LambdaEsUpdateChainWrapper(BaseEsMapper<T> baseEsMapper) {
|
||||
super();
|
||||
this.baseEsMapper = baseEsMapper;
|
||||
super.wrapperChildren = new LambdaEsUpdateWrapper<>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BaseEsMapper<T> getBaseEsMapper() {
|
||||
return baseEsMapper;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
package cn.easyes.core.conditions.update;
|
||||
|
||||
import cn.easyes.common.enums.EsQueryTypeEnum;
|
||||
import cn.easyes.common.params.SFunction;
|
||||
import cn.easyes.core.biz.EsUpdateParam;
|
||||
import cn.easyes.core.biz.Param;
|
||||
import cn.easyes.core.conditions.function.Update;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* 更新Lambda表达式
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@SuppressWarnings("serial")
|
||||
public class LambdaEsUpdateWrapper<T> extends AbstractLambdaUpdateWrapper<T, LambdaEsUpdateWrapper<T>>
|
||||
implements Update<LambdaEsUpdateWrapper<T>, SFunction<T, ?>> {
|
||||
/**
|
||||
* 不建议直接 new 该实例,使用 EsWrappers.lambdaQuery(entity)
|
||||
*/
|
||||
public LambdaEsUpdateWrapper() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public LambdaEsUpdateWrapper(Class<T> entityClass) {
|
||||
super.initNeed();
|
||||
super.setEntityClass(entityClass);
|
||||
updateParamList = new ArrayList<>();
|
||||
paramQueue = new LinkedList<>();
|
||||
}
|
||||
|
||||
LambdaEsUpdateWrapper(T entity, int level, String parentId, EsQueryTypeEnum pervQueryType, LinkedList<Param> paramQueue,
|
||||
Stack<String> parentIdStack, LinkedList<EsQueryTypeEnum> prevQueryTypeQueue, List<EsUpdateParam> updateParamList) {
|
||||
super.setEntity(entity);
|
||||
this.level = level;
|
||||
this.parentId = parentId;
|
||||
this.prevQueryType = pervQueryType;
|
||||
this.paramQueue = paramQueue;
|
||||
this.parentIdStack = parentIdStack;
|
||||
this.prevQueryTypeQueue = prevQueryTypeQueue;
|
||||
this.updateParamList = updateParamList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LambdaEsUpdateWrapper<T> instance() {
|
||||
return new LambdaEsUpdateWrapper<>(entity, level, parentId, prevQueryType, paramQueue, parentIdStack, prevQueryTypeQueue, updateParamList);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user