mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2026-06-09 07:16:11 +00:00
add 新增 迁移cloud版本 ruoyi-common-elasticsearch 模块 可接入es开发
This commit is contained in:
20
pom.xml
20
pom.xml
@@ -52,6 +52,8 @@
|
||||
<warm-flow.version>1.8.7</warm-flow.version>
|
||||
<!-- mqtt客户端 -->
|
||||
<mica-mqtt.version>2.5.12</mica-mqtt.version>
|
||||
<easy-es.version>3.0.2</easy-es.version>
|
||||
<elasticsearch-client.version>7.17.28</elasticsearch-client.version>
|
||||
<!-- Spring AI 2.0 预览版,正式版发布后仅需调整此版本号 -->
|
||||
<spring-ai.version>2.0.0-M6</spring-ai.version>
|
||||
|
||||
@@ -325,6 +327,24 @@
|
||||
<version>${mica-mqtt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara.easy-es</groupId>
|
||||
<artifactId>easy-es-boot-starter</artifactId>
|
||||
<version>${easy-es.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>co.elastic.clients</groupId>
|
||||
<artifactId>elasticsearch-java</artifactId>
|
||||
<version>${elasticsearch-client.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-client</artifactId>
|
||||
<version>${elasticsearch-client.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JustAuth 的依赖配置-->
|
||||
<dependency>
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
|
||||
@@ -282,6 +282,52 @@ mqtt.client:
|
||||
truststore-path:
|
||||
truststore-pass:
|
||||
|
||||
--- # elasticsearch 功能配置
|
||||
# 文档地址: https://www.easy-es.cn/
|
||||
# 更改包名需要去 EasyEsConfiguration 修改包扫描(后续版本支持配置文件读取)
|
||||
easy-es:
|
||||
# 是否开启EE自动配置
|
||||
enable: false
|
||||
# 兼容模式
|
||||
compatible: true
|
||||
# es连接地址+端口 格式必须为ip:port,如果是集群则可用逗号隔开
|
||||
address: localhost:9200
|
||||
# 默认为http
|
||||
schema: http
|
||||
# 注意ES建议使用账号认证 不使用会报警告日志
|
||||
# 如果无账号密码则可不配置此行
|
||||
# username:
|
||||
# 如果无账号密码则可不配置此行
|
||||
# password:
|
||||
# 心跳策略时间 单位:ms
|
||||
keep-alive-millis: 18000
|
||||
# 连接超时时间 单位:ms
|
||||
connectTimeout: 5000
|
||||
# 通信超时时间 单位:ms
|
||||
socketTimeout: 5000
|
||||
# 连接请求超时时间 单位:ms
|
||||
connectionRequestTimeout: 5000
|
||||
# 最大连接数 单位:个
|
||||
maxConnTotal: 100
|
||||
# 最大连接路由数 单位:个
|
||||
maxConnPerRoute: 100
|
||||
global-config:
|
||||
# 开启控制台打印通过本框架生成的DSL语句,默认为开启,测试稳定后的生产环境建议关闭,以提升少量性能
|
||||
print-dsl: true
|
||||
# 异步处理索引是否阻塞主线程 默认阻塞 数据量过大时调整为非阻塞异步进行 项目启动更快
|
||||
asyncProcessIndexBlocking: true
|
||||
db-config:
|
||||
# 是否开启下划线转驼峰 默认为false
|
||||
map-underscore-to-camel-case: true
|
||||
# id生成策略 customize为自定义,id值由用户生成,比如取MySQL中的数据id,如缺省此项配置,则id默认策略为es自动生成
|
||||
id-type: customize
|
||||
# 字段更新策略 默认为not_null
|
||||
field-strategy: not_null
|
||||
# 默认开启,查询若指定了size超过1w条时也会自动开启,开启后查询所有匹配数据,若不开启,会导致无法获取数据总条数,其它功能不受影响.
|
||||
enable-track-total-hits: true
|
||||
# 数据刷新策略,默认为不刷新
|
||||
refresh-policy: immediate
|
||||
|
||||
--- # MCP 服务端配置
|
||||
spring.ai.mcp:
|
||||
server:
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
<module>ruoyi-common-satoken</module>
|
||||
<module>ruoyi-common-security</module>
|
||||
<module>ruoyi-common-sms</module>
|
||||
<module>ruoyi-common-elasticsearch</module>
|
||||
<module>ruoyi-common-web</module>
|
||||
<module>ruoyi-common-translation</module>
|
||||
<module>ruoyi-common-sensitive</module>
|
||||
|
||||
@@ -103,6 +103,13 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ES搜索引擎服务 -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-elasticsearch</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 授权认证 -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
|
||||
24
ruoyi-common/ruoyi-common-elasticsearch/pom.xml
Normal file
24
ruoyi-common/ruoyi-common-elasticsearch/pom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<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>
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.dromara.common.elasticsearch.config;
|
||||
|
||||
import org.springframework.boot.EnvironmentPostProcessor;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
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) {
|
||||
String enable = environment.getProperty("easy-es.enable", "false");
|
||||
System.setProperty("management.health.elasticsearch.enabled", enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.HIGHEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
org.dromara.common.elasticsearch.config.ActuatorEnvironmentPostProcessor
|
||||
@@ -0,0 +1 @@
|
||||
org.dromara.common.elasticsearch.config.EasyEsConfiguration
|
||||
@@ -88,6 +88,11 @@
|
||||
<artifactId>ruoyi-common-encrypt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-push</artifactId>
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package org.dromara.demo.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.demo.domain.Document;
|
||||
import org.dromara.demo.esmapper.DocumentMapper;
|
||||
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 搜索引擎 crud 演示案例
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@ConditionalOnProperty(value = "easy-es.enable", havingValue = "true")
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/es")
|
||||
public class EsCrudController {
|
||||
|
||||
private final DocumentMapper documentMapper;
|
||||
|
||||
/**
|
||||
* 查询(指定)
|
||||
*
|
||||
* @param title 标题
|
||||
*/
|
||||
@GetMapping("/select")
|
||||
public Document select(String title) {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.eq(Document::getTitle, title);
|
||||
return documentMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索(模糊)
|
||||
*
|
||||
* @param key 搜索关键字
|
||||
*/
|
||||
@GetMapping("/search")
|
||||
public List<Document> search(String key) {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.like(Document::getTitle, key);
|
||||
return documentMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入
|
||||
*/
|
||||
@PostMapping("/insert")
|
||||
public Integer insert(@RequestBody Document document) {
|
||||
return documentMapper.insert(document);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public R<Void> update(@RequestBody Document document) {
|
||||
// 测试更新 更新有两种情况 分别演示如下:
|
||||
// case1: 已知id, 根据id更新 (为了演示方便,此id是从上一步查询中复制过来的,实际业务可以自行查询)
|
||||
documentMapper.updateById(document);
|
||||
|
||||
// case2: id未知, 根据条件更新
|
||||
// LambdaEsUpdateWrapper<Document> wrapper = new LambdaEsUpdateWrapper<>();
|
||||
// wrapper.like(Document::getTitle, document.getTitle());
|
||||
// Document document2 = new Document();
|
||||
// document2.setTitle(document.getTitle());
|
||||
// document2.setContent(document.getContent());
|
||||
// documentMapper.update(document2, wrapper);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public R<Integer> delete(@PathVariable String id) {
|
||||
// 测试删除数据 删除有两种情况:根据id删或根据条件删
|
||||
return R.ok(documentMapper.deleteById(id));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.dromara.demo.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 文档实体
|
||||
*/
|
||||
@Data
|
||||
public class Document {
|
||||
|
||||
/**
|
||||
* es中的唯一id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 文档标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 文档内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.dromara.demo.esmapper;
|
||||
|
||||
import org.dromara.demo.domain.Document;
|
||||
import org.dromara.easyes.core.kernel.BaseEsMapper;
|
||||
|
||||
public interface DocumentMapper extends BaseEsMapper<Document> {
|
||||
}
|
||||
Reference in New Issue
Block a user