Merge branch 'feature-3.0' of https://gitee.com/dromara/easy-es into feature-3.0

 Conflicts:
	easy-es-springboot-test/src/test/resources/application.yml
This commit is contained in:
xpc 2025-04-13 21:16:13 +08:00
commit 3bc2a7a860
20 changed files with 384 additions and 136 deletions

View File

@ -12,6 +12,12 @@
"description": "是否开启easy-es LOGO BANNER的打印.", "description": "是否开启easy-es LOGO BANNER的打印.",
"type": "java.lang.Boolean" "type": "java.lang.Boolean"
}, },
{
"defaultValue": false,
"name": "easy-es.compatible",
"description": "是否开启兼容性(超低版本的es, 比如7.0.0开启该特性).",
"type": "java.lang.Boolean"
},
{ {
"defaultValue": "127.0.0.1:9200", "defaultValue": "127.0.0.1:9200",
"name": "easy-es.address", "name": "easy-es.address",

View File

@ -94,6 +94,15 @@ public interface BaseEsMapper<T> {
*/ */
Boolean deleteIndex(String... indexNames); Boolean deleteIndex(String... indexNames);
/**
* 删除当前mapper索引无需传递索引名
* @return {@link Boolean} 是否成功
* @author MoJie
*/
default Boolean deleteIndex() {
return this.deleteIndex(EntityInfoHelper.getIndexName(this.getEntityClass()));
}
/** /**
* 刷新索引 * 刷新索引
* *

View File

@ -102,9 +102,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
@Override @Override
public Boolean createIndex() { public Boolean createIndex() {
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass); return createIndex(EntityInfoHelper.getIndexName(entityClass));
CreateIndexParam createIndexParam = IndexUtils.getCreateIndexParam(entityInfo, entityClass);
return IndexUtils.createIndex(client, entityInfo, createIndexParam);
} }
@Override @Override
@ -164,8 +162,13 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
@Override @Override
@SneakyThrows @SneakyThrows
public String executeSQL(String sql) { public String executeSQL(String sql) {
// 如果是下划线转驼峰ee帮助处理
if (GlobalConfigCache.getGlobalConfig().getDbConfig().isMapUnderscoreToCamelCase()) {
sql = StringUtils.camelToUnderline(sql);
}
PrintUtils.printSql(sql); PrintUtils.printSql(sql);
QueryResponse response = client.sql().query(x -> x.query(sql).format("json")); String finalSql = sql;
QueryResponse response = client.sql().query(x -> x.query(finalSql).format("json"));
return JsonpUtils.toString(response, new StringBuilder()).toString(); return JsonpUtils.toString(response, new StringBuilder()).toString();
} }

View File

@ -627,8 +627,14 @@ public class WrapperProcessor {
// 设置以String形式指定的自定义排序字段及规则(此类排序通常由前端传入,满足部分用户个性化需求) // 设置以String形式指定的自定义排序字段及规则(此类排序通常由前端传入,满足部分用户个性化需求)
if (CollectionUtils.isNotEmpty(wrapper.orderByParams)) { if (CollectionUtils.isNotEmpty(wrapper.orderByParams)) {
wrapper.orderByParams.forEach(orderByParam -> { wrapper.orderByParams.forEach(orderByParam -> {
// 排序字段名
String orderColumn = orderByParam.getOrder();
// 获取配置是否开启了驼峰转换
if (GlobalConfigCache.getGlobalConfig().getDbConfig().isMapUnderscoreToCamelCase()) {
orderColumn = StringUtils.camelToUnderline(orderColumn);
}
// 设置排序字段 // 设置排序字段
FieldSort.Builder fieldSortBuilder = new FieldSort.Builder().field(orderByParam.getOrder()); FieldSort.Builder fieldSortBuilder = new FieldSort.Builder().field(orderColumn);
// 设置排序规则 // 设置排序规则
if (SortOrder.Asc.toString().equalsIgnoreCase(orderByParam.getSort())) { if (SortOrder.Asc.toString().equalsIgnoreCase(orderByParam.getSort())) {

View File

@ -374,6 +374,7 @@ public class EntityInfoHelper {
if (dbConfig.isMapUnderscoreToCamelCase()) { if (dbConfig.isMapUnderscoreToCamelCase()) {
realHighLightField = StringUtils.camelToUnderline(realHighLightField); realHighLightField = StringUtils.camelToUnderline(realHighLightField);
} }
// 如果字段没有参与条件查询则不进行高亮设置
addHighlightParam(entityInfo, nestedOrObjectClass, highLight, realHighLightField, mappingField); addHighlightParam(entityInfo, nestedOrObjectClass, highLight, realHighLightField, mappingField);
MultiIndexField multiIndexField = field.getAnnotation(MultiIndexField.class); MultiIndexField multiIndexField = field.getAnnotation(MultiIndexField.class);
@ -413,6 +414,11 @@ public class EntityInfoHelper {
.setHighLightField(realHighLightField) .setHighLightField(realHighLightField)
.setHighLightType(highLight.highLightType()) .setHighLightType(highLight.highLightType())
.setRequireFieldMatch(highLight.requireFieldMatch()); .setRequireFieldMatch(highLight.requireFieldMatch());
// 多级高亮 合并高亮结果时es8会尝试调用 first() 方法-降级不会影响es7的查询
// 如果是pinyin那么进行高亮降级否则会出现first() should not be called in this context异常
if (realHighLightField.endsWith(".pinyin")) {
highlightParam.setHighLightType(HighLightTypeEnum.PLAIN);
}
if (MINUS_ONE != highLight.numberOfFragments() && highLight.numberOfFragments() > ZERO) { if (MINUS_ONE != highLight.numberOfFragments() && highLight.numberOfFragments() > ZERO) {
highlightParam.setNumberOfFragments(highLight.numberOfFragments()); highlightParam.setNumberOfFragments(highLight.numberOfFragments());
} }
@ -694,6 +700,31 @@ public class EntityInfoHelper {
return ReflectionKit.getFieldList(ClassUtils.getUserClass(clazz)); return ReflectionKit.getFieldList(ClassUtils.getUserClass(clazz));
} }
/**
* 根据类获取索引名
* @param clazz 实体
* @return {@link String}
* @author MoJie
*/
public static String getIndexName(Class<?> clazz) {
String tablePrefix = GlobalConfigCache.getGlobalConfig().getDbConfig().getIndexPrefix();
IndexName table = clazz.getAnnotation(IndexName.class);
boolean tablePrefixEffect = true;
String indexName = clazz.getSimpleName().toLowerCase(Locale.ROOT);
if (table != null) {
if (StringUtils.isNotBlank(table.value())) {
indexName = table.value();
if (StringUtils.isNotBlank(tablePrefix) && !table.keepGlobalPrefix()) {
tablePrefixEffect = false;
}
}
}
if (StringUtils.isNotBlank(tablePrefix) && tablePrefixEffect) {
indexName = tablePrefix + indexName;
}
return indexName;
}
/** /**
* 初始化索引名等信息 * 初始化索引名等信息
* *

View File

@ -10,6 +10,7 @@ import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.json.JsonData; import co.elastic.clients.json.JsonData;
import co.elastic.clients.transport.rest_client.RestClientOptions; import co.elastic.clients.transport.rest_client.RestClientOptions;
import org.dromara.easyes.common.constants.BaseEsConstants;
import org.dromara.easyes.core.biz.EntityInfo; import org.dromara.easyes.core.biz.EntityInfo;
import org.dromara.easyes.core.biz.EsPageInfo; import org.dromara.easyes.core.biz.EsPageInfo;
import org.dromara.easyes.core.biz.OrderByParam; import org.dromara.easyes.core.biz.OrderByParam;
@ -939,41 +940,41 @@ public class AllTest {
Boolean success = documentMapper.setRequestOptions(new RestClientOptions(builder.build())); Boolean success = documentMapper.setRequestOptions(new RestClientOptions(builder.build()));
Assertions.assertTrue(success); Assertions.assertTrue(success);
} }
//
// // 4.删除 // 4.删除
// @Test @Test
// @Order(76) @Order(76)
// public void testDeleteById() { public void testDeleteById() {
// int count = documentMapper.deleteById("1"); int count = documentMapper.deleteById("1");
// Assertions.assertEquals(1, count); Assertions.assertEquals(1, count);
// } }
//
// @Test @Test
// @Order(77) @Order(77)
// public void testDeleteBatchIds() { public void testDeleteBatchIds() {
// List<String> idList = Arrays.asList("2", "3", "4"); List<String> idList = Arrays.asList("2", "3", "4");
// int count = documentMapper.deleteBatchIds(idList); int count = documentMapper.deleteBatchIds(idList);
// Assertions.assertEquals(3, count); Assertions.assertEquals(3, count);
// } }
//
// @Test @Test
// @Order(78) @Order(78)
// public void testDeleteByWrapper() { public void testDeleteByWrapper() {
// LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>(); LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
// wrapper.match(Document::getCreator, "老汉"); wrapper.match(Document::getCreator, "老汉");
//
// int count = documentMapper.delete(wrapper); int count = documentMapper.delete(wrapper);
// Assertions.assertEquals(18, count); Assertions.assertEquals(18, count);
// } }
//
// @Test @Test
// @Order(80) @Order(80)
// public void testDeleteIndex() { public void testDeleteIndex() {
// boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName()); boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName());
// boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX); boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX);
// Assertions.assertTrue(deleted); Assertions.assertTrue(deleted);
// Assertions.assertTrue(lockDeleted); Assertions.assertTrue(lockDeleted);
// } }
@Test @Test
@Order(79) @Order(79)

View File

@ -1,9 +1,9 @@
easy-es: easy-es:
# enable: true # enable: true
address: 127.0.0.1:9200 address: 192.168.0.18:9200
schema: https # schema: https
username: elastic # username: elastic
password: a2*HFkQU93mBnxOTaEAs # password: a2*HFkQU93mBnxOTaEAs
keep-alive-millis: 18000 keep-alive-millis: 18000
global-config: global-config:
i-kun-mode: false i-kun-mode: false
@ -11,7 +11,7 @@ easy-es:
async-process-index-blocking: true async-process-index-blocking: true
print-dsl: true print-dsl: true
db-config: db-config:
map-underscore-to-camel-case: false map-underscore-to-camel-case: true
id-type: customize id-type: customize
field-strategy: not_empty field-strategy: not_empty
refresh-policy: immediate refresh-policy: immediate

View File

@ -10,6 +10,7 @@ import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.json.JsonData; import co.elastic.clients.json.JsonData;
import co.elastic.clients.transport.rest_client.RestClientOptions; import co.elastic.clients.transport.rest_client.RestClientOptions;
import org.dromara.easyes.common.constants.BaseEsConstants;
import org.dromara.easyes.core.biz.EntityInfo; import org.dromara.easyes.core.biz.EntityInfo;
import org.dromara.easyes.core.biz.EsPageInfo; import org.dromara.easyes.core.biz.EsPageInfo;
import org.dromara.easyes.core.biz.OrderByParam; import org.dromara.easyes.core.biz.OrderByParam;
@ -675,7 +676,7 @@ public class XmlScannerAllTest {
wrapper.match(Document::getCreator, "老汉"); wrapper.match(Document::getCreator, "老汉");
List<OrderByParam> orderByParams = new ArrayList<>(); List<OrderByParam> orderByParams = new ArrayList<>();
OrderByParam orderByParam = new OrderByParam(); OrderByParam orderByParam = new OrderByParam();
orderByParam.setOrder("starNum"); orderByParam.setOrder("star_num");
orderByParam.setSort("DESC"); orderByParam.setSort("DESC");
orderByParams.add(orderByParam); orderByParams.add(orderByParam);
wrapper.orderBy(orderByParams); wrapper.orderBy(orderByParams);
@ -941,39 +942,39 @@ public class XmlScannerAllTest {
} }
// 4.删除 // 4.删除
// @Test @Test
// @Order(76) @Order(76)
// public void testDeleteById() { public void testDeleteById() {
// int count = documentMapper.deleteById("1"); int count = documentMapper.deleteById("1");
// Assertions.assertEquals(1, count); Assertions.assertEquals(1, count);
// } }
//
// @Test @Test
// @Order(77) @Order(77)
// public void testDeleteBatchIds() { public void testDeleteBatchIds() {
// List<String> idList = Arrays.asList("2", "3", "4"); List<String> idList = Arrays.asList("2", "3", "4");
// int count = documentMapper.deleteBatchIds(idList); int count = documentMapper.deleteBatchIds(idList);
// Assertions.assertEquals(3, count); Assertions.assertEquals(3, count);
// } }
//
// @Test @Test
// @Order(78) @Order(78)
// public void testDeleteByWrapper() { public void testDeleteByWrapper() {
// LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>(); LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
// wrapper.match(Document::getCreator, "老汉"); wrapper.match(Document::getCreator, "老汉");
//
// int count = documentMapper.delete(wrapper); int count = documentMapper.delete(wrapper);
// Assertions.assertEquals(18, count); Assertions.assertEquals(18, count);
// } }
//
// @Test @Test
// @Order(80) @Order(80)
// public void testDeleteIndex() { public void testDeleteIndex() {
// boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName()); boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName());
// boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX); boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX);
// Assertions.assertTrue(deleted); Assertions.assertTrue(deleted);
// Assertions.assertTrue(lockDeleted); Assertions.assertTrue(lockDeleted);
// } }
@Test @Test
@Order(79) @Order(79)

View File

@ -11,15 +11,13 @@
<bean id="easyEsProperties" class="org.dromara.easyes.common.property.EasyEsProperties"> <bean id="easyEsProperties" class="org.dromara.easyes.common.property.EasyEsProperties">
<property name="enable" value="true"/> <property name="enable" value="true"/>
<property name="address" value="192.168.1.16:30156"/> <property name="address" value="192.168.0.18:9200"/>
<property name="username" value="elastic"/>
<property name="password" value="mg123456"/>
<property name="keepAliveMillis" value="18000"/> <property name="keepAliveMillis" value="18000"/>
<property name="globalConfig.IKunMode" value="false"/> <property name="globalConfig.IKunMode" value="false"/>
<property name="globalConfig.processIndexMode" value="MANUAL"/> <property name="globalConfig.processIndexMode" value="MANUAL"/>
<property name="globalConfig.asyncProcessIndexBlocking" value="true"/> <property name="globalConfig.asyncProcessIndexBlocking" value="true"/>
<property name="globalConfig.printDsl" value="true"/> <property name="globalConfig.printDsl" value="true"/>
<property name="globalConfig.dbConfig.mapUnderscoreToCamelCase" value="false"/> <property name="globalConfig.dbConfig.mapUnderscoreToCamelCase" value="true"/>
<property name="globalConfig.dbConfig.idType" value="CUSTOMIZE"/> <property name="globalConfig.dbConfig.idType" value="CUSTOMIZE"/>
<property name="globalConfig.dbConfig.fieldStrategy" value="NOT_EMPTY"/> <property name="globalConfig.dbConfig.fieldStrategy" value="NOT_EMPTY"/>
<property name="globalConfig.dbConfig.refreshPolicy" value="IMMEDIATE"/> <property name="globalConfig.dbConfig.refreshPolicy" value="IMMEDIATE"/>
@ -32,6 +30,6 @@
<!-- easy-es配置 --> <!-- easy-es配置 -->
<bean id="mapperScannerConfigurer" class="org.dromara.easyes.spring.MapperScannerConfigurer"> <bean id="mapperScannerConfigurer" class="org.dromara.easyes.spring.MapperScannerConfigurer">
<property name="basePackage" value="org.dromara.easyes.test.mapper"/> <property name="basePackage" value="org.dromara.easyes.test.mapper,org.dromara.easyes.test.mapper2"/>
</bean> </bean>
</beans> </beans>

View File

@ -3,6 +3,7 @@ package org.dromara.easyes.spring;
import lombok.Setter; import lombok.Setter;
import org.dromara.easyes.common.utils.EEVersionUtils; import org.dromara.easyes.common.utils.EEVersionUtils;
import org.dromara.easyes.common.utils.LogUtils; import org.dromara.easyes.common.utils.LogUtils;
import org.dromara.easyes.common.utils.StringUtils;
import org.dromara.easyes.spring.config.ClassPathMapperScanner; import org.dromara.easyes.spring.config.ClassPathMapperScanner;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValue; import org.springframework.beans.PropertyValue;
@ -63,7 +64,10 @@ public class MapperScannerConfigurer
} }
PropertyValues values = mapperScannerBean.getPropertyValues(); PropertyValues values = mapperScannerBean.getPropertyValues();
// 如果在环境变量中取扫描的包需要从easy-es.mappers进行取值与mybatis配置mapper相似但这里不做配置推荐 // 如果在环境变量中取扫描的包需要从easy-es.mappers进行取值与mybatis配置mapper相似但这里不做配置推荐
this.basePackage = getPropertyValue("easy-es.mappers", values); String propertyValue = getPropertyValue("easy-es.mappers", values);
if (StringUtils.isNotBlank(propertyValue)) {
this.basePackage = propertyValue;
}
} }
// 取变量 // 取变量

View File

@ -1,5 +1,6 @@
package org.dromara.easyes.spring.annotation; package org.dromara.easyes.spring.annotation;
import org.dromara.easyes.common.constants.BaseEsConstants;
import org.dromara.easyes.common.utils.LogUtils; import org.dromara.easyes.common.utils.LogUtils;
import org.dromara.easyes.spring.MapperScannerConfigurer; import org.dromara.easyes.spring.MapperScannerConfigurer;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
@ -12,6 +13,7 @@ import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -36,9 +38,10 @@ public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, Env
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
AnnotationAttributes mapperScanAttrs = AnnotationAttributes AnnotationAttributes mapperScanAttrs = AnnotationAttributes
.fromMap(importingClassMetadata.getAnnotationAttributes(EsMapperScan.class.getName())); .fromMap(importingClassMetadata.getAnnotationAttributes(EsMapperScan.class.getName()));
List<String> basePackages = new ArrayList<>();
// 默认已注解标记为主如果没有则尝试寻找easy-es配置 scan // 默认已注解标记为主如果没有则尝试寻找easy-es配置 scan
if (mapperScanAttrs != null) { if (mapperScanAttrs != null) {
List<String> basePackages = Arrays.stream(mapperScanAttrs.getStringArray("value")) basePackages = Arrays.stream(mapperScanAttrs.getStringArray("value"))
.filter(StringUtils::hasText) .filter(StringUtils::hasText)
.map(map -> { .map(map -> {
// 判断是否需要处理${}变量 // 判断是否需要处理${}变量
@ -50,6 +53,15 @@ public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, Env
return map; return map;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
} else {
// 如果在环境变量中取扫描的包需要从easy-es.mappers进行取值与mybatis配置mapper相似但这里不做配置推荐
String propertyValue = this.environment.getProperty("easy-es.mappers", String.class, BaseEsConstants.EMPTY_STR);
if (org.dromara.easyes.common.utils.StringUtils.isNotBlank(propertyValue)) {
basePackages = Arrays.asList(propertyValue.split(COMMA));
}
}
// 如果扫描的包不为空则进行mapperInterface的注册
if (!basePackages.isEmpty()) {
// 注册bean // 注册bean
registerBeanDefinitions(registry, generateBaseBeanName(importingClassMetadata), registerBeanDefinitions(registry, generateBaseBeanName(importingClassMetadata),
StringUtils.toStringArray(basePackages)); StringUtils.toStringArray(basePackages));

View File

@ -1,4 +1,4 @@
package org.dromara.easyes.test.mapper; package org.dromara.easyes.test.mapper2;
import org.dromara.easyes.core.kernel.BaseEsMapper; import org.dromara.easyes.core.kernel.BaseEsMapper;

View File

@ -1,4 +1,4 @@
package org.dromara.easyes.test.mapper; package org.dromara.easyes.test.mapper3;
import org.dromara.easyes.core.kernel.BaseEsMapper; import org.dromara.easyes.core.kernel.BaseEsMapper;

View File

@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* Copyright © 2021 xpc1024 All Rights Reserved * Copyright © 2021 xpc1024 All Rights Reserved
**/ **/
@SpringBootApplication @SpringBootApplication
@EsMapperScan("org.dromara.easyes.test.mapper") @EsMapperScan({"org.dromara.easyes.test.mapper", "org.dromara.easyes.test.mapper2", "org.dromara.easyes.test.mapper3"})
public class TestEasyEsApplication { public class TestEasyEsApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(TestEasyEsApplication.class, args); SpringApplication.run(TestEasyEsApplication.class, args);

View File

@ -10,6 +10,7 @@ import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.json.JsonData; import co.elastic.clients.json.JsonData;
import co.elastic.clients.transport.rest_client.RestClientOptions; import co.elastic.clients.transport.rest_client.RestClientOptions;
import org.dromara.easyes.common.constants.BaseEsConstants;
import org.dromara.easyes.core.biz.EntityInfo; import org.dromara.easyes.core.biz.EntityInfo;
import org.dromara.easyes.core.biz.EsPageInfo; import org.dromara.easyes.core.biz.EsPageInfo;
import org.dromara.easyes.core.biz.OrderByParam; import org.dromara.easyes.core.biz.OrderByParam;
@ -942,40 +943,40 @@ public class AllTest {
Assertions.assertTrue(success); Assertions.assertTrue(success);
} }
// // 4.删除 // 4.删除
// @Test @Test
// @Order(76) @Order(76)
// public void testDeleteById() { public void testDeleteById() {
// int count = documentMapper.deleteById("1"); int count = documentMapper.deleteById("1");
// Assertions.assertEquals(1, count); Assertions.assertEquals(1, count);
// } }
//
// @Test @Test
// @Order(77) @Order(77)
// public void testDeleteBatchIds() { public void testDeleteBatchIds() {
// List<String> idList = Arrays.asList("2", "3", "4"); List<String> idList = Arrays.asList("2", "3", "4");
// int count = documentMapper.deleteBatchIds(idList); int count = documentMapper.deleteBatchIds(idList);
// Assertions.assertEquals(3, count); Assertions.assertEquals(3, count);
// } }
//
// @Test @Test
// @Order(78) @Order(78)
// public void testDeleteByWrapper() { public void testDeleteByWrapper() {
// LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>(); LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
// wrapper.match(Document::getCreator, "老汉"); wrapper.match(Document::getCreator, "老汉");
//
// int count = documentMapper.delete(wrapper); int count = documentMapper.delete(wrapper);
// Assertions.assertEquals(18, count); Assertions.assertEquals(18, count);
// } }
//
// @Test @Test
// @Order(80) @Order(80)
// public void testDeleteIndex() { public void testDeleteIndex() {
// boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName()); boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName());
// boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX); boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX);
// Assertions.assertTrue(deleted); Assertions.assertTrue(deleted);
// Assertions.assertTrue(lockDeleted); Assertions.assertTrue(lockDeleted);
// } }
@Test @Test
@Order(79) @Order(79)

View File

@ -10,8 +10,8 @@ import org.dromara.easyes.test.entity.Author;
import org.dromara.easyes.test.entity.Comment; import org.dromara.easyes.test.entity.Comment;
import org.dromara.easyes.test.entity.Contact; import org.dromara.easyes.test.entity.Contact;
import org.dromara.easyes.test.entity.Document; import org.dromara.easyes.test.entity.Document;
import org.dromara.easyes.test.mapper.AuthorMapper; import org.dromara.easyes.test.mapper2.AuthorMapper;
import org.dromara.easyes.test.mapper.CommentMapper; import org.dromara.easyes.test.mapper3.CommentMapper;
import org.dromara.easyes.test.mapper.ContactMapper; import org.dromara.easyes.test.mapper.ContactMapper;
import org.dromara.easyes.test.mapper.DocumentMapper; import org.dromara.easyes.test.mapper.DocumentMapper;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;

View File

@ -0,0 +1,18 @@
package org.dromara.easyes.test.mapper;
import org.dromara.easyes.spring.annotation.EsMapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* 启动类
* <p>
* Copyright © 2021 xpc1024 All Rights Reserved
**/
@SpringBootApplication
@EsMapperScan({"org.dromara.easyes.test.mapper", "org.dromara.easyes.test.mapper2", "org.dromara.easyes.test.mapper3"})
public class MapperScanEsApplication {
public static void main(String[] args) {
SpringApplication.run(MapperScanEsApplication.class, args);
}
}

View File

@ -0,0 +1,72 @@
package org.dromara.easyes.test.mapper;
import org.dromara.easyes.common.constants.BaseEsConstants;
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
import org.dromara.easyes.test.TestEasyEsApplication;
import org.dromara.easyes.test.entity.Document;
import org.dromara.easyes.test.mapper2.AuthorMapper;
import org.dromara.easyes.test.mapper3.CommentMapper;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
/**
* @author MoJie
* @since 2.0
*/
@DisplayName("easy-es多包扫描单元测试")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@SpringBootTest(classes = MapperScanEsApplication.class)
public class MapperScanTest {
@Resource
private ContactMapper contactMapper;
@Resource
private AuthorMapper authorMapper;
@Resource
private CommentMapper commentMapper;
@Test
@Order(0)
public void testCreateIndex1() {
boolean success = contactMapper.createIndex();
Assertions.assertTrue(success);
}
@Test
@Order(1)
public void testDeleteIndex1() {
boolean deleted = contactMapper.deleteIndex();
Assertions.assertTrue(deleted);
}
@Test
@Order(2)
public void testCreateIndex2() {
boolean success = authorMapper.createIndex();
Assertions.assertTrue(success);
}
@Test
@Order(3)
public void testDeleteIndex2() {
boolean success = authorMapper.deleteIndex();
Assertions.assertTrue(success);
}
@Test
@Order(4)
public void testCreateIndex3() {
boolean success = commentMapper.createIndex();
Assertions.assertTrue(success);
}
@Test
@Order(5)
public void testDeleteIndex3() {
boolean success = commentMapper.deleteIndex();
Assertions.assertTrue(success);
}
}

View File

@ -0,0 +1,68 @@
package org.dromara.easyes.test.mapper;
import org.dromara.easyes.test.mapper2.AuthorMapper;
import org.dromara.easyes.test.mapper3.CommentMapper;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
/**
* @author MoJie
* @since 2.0
*/
@DisplayName("easy-es多包扫描单元测试")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@SpringBootTest(classes = PattenScanEsApplication.class)
public class PattenMapperScanTest {
@Resource
private ContactMapper contactMapper;
@Resource
private AuthorMapper authorMapper;
@Resource
private CommentMapper commentMapper;
@Test
@Order(0)
public void testCreateIndex1() {
boolean success = contactMapper.createIndex();
Assertions.assertTrue(success);
}
@Test
@Order(1)
public void testDeleteIndex1() {
boolean deleted = contactMapper.deleteIndex();
Assertions.assertTrue(deleted);
}
@Test
@Order(2)
public void testCreateIndex2() {
boolean success = authorMapper.createIndex();
Assertions.assertTrue(success);
}
@Test
@Order(3)
public void testDeleteIndex2() {
boolean success = authorMapper.deleteIndex();
Assertions.assertTrue(success);
}
@Test
@Order(4)
public void testCreateIndex3() {
boolean success = commentMapper.createIndex();
Assertions.assertTrue(success);
}
@Test
@Order(5)
public void testDeleteIndex3() {
boolean success = commentMapper.deleteIndex();
Assertions.assertTrue(success);
}
}

View File

@ -0,0 +1,18 @@
package org.dromara.easyes.test.mapper;
import org.dromara.easyes.spring.annotation.EsMapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* 启动类
* <p>
* Copyright © 2021 xpc1024 All Rights Reserved
**/
@SpringBootApplication
@EsMapperScan({"org.dromara.easyes.test.*"})
public class PattenScanEsApplication {
public static void main(String[] args) {
SpringApplication.run(PattenScanEsApplication.class, args);
}
}