This commit is contained in:
2025-06-17 17:08:14 +08:00
commit 71179324c8
1205 changed files with 798946 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ruoyi-common-elasticsearch</artifactId>
<description>
ruoyi-common-elasticsearch ES搜索引擎服务
</description>
<dependencies>
<dependency>
<groupId>org.dromara.easy-es</groupId>
<artifactId>easy-es-boot-starter</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,25 @@
package org.dromara.common.elasticsearch.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* 健康检查配置注入
*
* @author Lion Li
*/
public class ActuatorEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
System.setProperty("management.health.elasticsearch.enabled", "false");
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}

View File

@@ -0,0 +1,17 @@
package org.dromara.common.elasticsearch.config;
import org.dromara.easyes.spring.annotation.EsMapperScan;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
/**
* easy-es 配置
*
* @author Lion Li
*/
@AutoConfiguration
@ConditionalOnProperty(value = "easy-es.enable", havingValue = "true")
@EsMapperScan("org.dromara.**.esmapper")
public class EasyEsConfiguration {
}

View File

@@ -0,0 +1,84 @@
package org.dromara.easyes.spring.config;
import lombok.Setter;
import org.dromara.easyes.common.property.EasyEsDynamicProperties;
import org.dromara.easyes.common.property.EasyEsProperties;
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
import org.dromara.easyes.common.utils.RestHighLevelClientUtils;
import org.dromara.easyes.core.index.AutoProcessIndexNotSmoothlyStrategy;
import org.dromara.easyes.core.index.AutoProcessIndexSmoothlyStrategy;
import org.dromara.easyes.spring.factory.IndexStrategyFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;
import java.util.Map;
/**
* @author MoJie
* @since 2.0
*/
@Setter
@Configuration
@ConditionalOnProperty(value = "easy-es.enable", havingValue = "true")
public class EasyEsConfiguration implements InitializingBean {
private EasyEsProperties easyEsProperties;
private EasyEsDynamicProperties easyEsDynamicProperties;
@Autowired
public EasyEsConfiguration(EasyEsProperties easyEsProperties, EasyEsDynamicProperties easyEsDynamicProperties) {
this.easyEsProperties = easyEsProperties;
this.easyEsDynamicProperties = easyEsDynamicProperties;
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(this.easyEsProperties, "easyEsProperties must is A bean. easy-es配置类必须给配置一个bean");
}
@Bean
public IndexStrategyFactory indexStrategyFactory() {
return new IndexStrategyFactory();
}
@Bean
public RestHighLevelClientUtils restHighLevelClientUtils() {
RestHighLevelClientUtils restHighLevelClientUtils = new RestHighLevelClientUtils();
if (this.easyEsDynamicProperties == null) {
this.easyEsDynamicProperties = new EasyEsDynamicProperties();
}
Map<String, EasyEsProperties> datasourceMap = this.easyEsDynamicProperties.getDatasource();
if (datasourceMap.isEmpty()) {
// 设置默认数据源,兼容不使用多数据源配置场景的老用户使用习惯
datasourceMap.put(RestHighLevelClientUtils.DEFAULT_DS, this.easyEsProperties);
}
for (String key : datasourceMap.keySet()) {
EasyEsProperties easyEsConfigProperties = datasourceMap.get(key);
RestHighLevelClientUtils.registerRestHighLevelClient(key, RestHighLevelClientUtils
.restHighLevelClient(easyEsConfigProperties));
}
return restHighLevelClientUtils;
}
/**
* 索引策略注册
*
* @return {@link AutoProcessIndexStrategy}
* @author MoJie
*/
@Bean
public AutoProcessIndexStrategy autoProcessIndexSmoothlyStrategy() {
return new AutoProcessIndexSmoothlyStrategy();
}
@Bean
public AutoProcessIndexStrategy autoProcessIndexNotSmoothlyStrategy() {
return new AutoProcessIndexNotSmoothlyStrategy();
}
}

View File

@@ -0,0 +1,27 @@
package org.dromara.easyes.starter.config;
import org.dromara.easyes.core.config.GeneratorConfig;
import org.dromara.easyes.core.toolkit.Generator;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
/**
* 代码生成注册
* @author MoJie
* @since 2.0
*/
@Component
@ConditionalOnProperty(value = "easy-es.enable", havingValue = "true")
public class GeneratorConfiguration extends Generator {
@Autowired
private RestHighLevelClient client;
@Override
public Boolean generate(GeneratorConfig config) {
super.generateEntity(config, this.client);
return Boolean.TRUE;
}
}

View File

@@ -0,0 +1,2 @@
org.springframework.boot.env.EnvironmentPostProcessor=\
org.dromara.common.elasticsearch.config.ActuatorEnvironmentPostProcessor

View File

@@ -0,0 +1 @@
org.dromara.common.elasticsearch.config.EasyEsConfiguration