mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
feat: 删除fastjson
This commit is contained in:
parent
d320aafb60
commit
bdc279fe54
@ -43,11 +43,6 @@
|
|||||||
<artifactId>jakarta.json-api</artifactId>
|
<artifactId>jakarta.json-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba</groupId>
|
|
||||||
<artifactId>fastjson</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package org.dromara.easyes.core.biz;
|
package org.dromara.easyes.core.biz;
|
||||||
|
|
||||||
import com.alibaba.fastjson.serializer.NameFilter;
|
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -97,7 +96,6 @@ public class EntityFieldInfo {
|
|||||||
@Setter(AccessLevel.NONE)
|
@Setter(AccessLevel.NONE)
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private String sqlSelect;
|
private String sqlSelect;
|
||||||
private NameFilter nameFilter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 复制字段
|
* 复制字段
|
||||||
|
|||||||
@ -26,7 +26,6 @@ import co.elastic.clients.json.JsonData;
|
|||||||
import co.elastic.clients.json.JsonpUtils;
|
import co.elastic.clients.json.JsonpUtils;
|
||||||
import co.elastic.clients.transport.TransportOptions;
|
import co.elastic.clients.transport.TransportOptions;
|
||||||
import co.elastic.clients.transport.rest_client.RestClientTransport;
|
import co.elastic.clients.transport.rest_client.RestClientTransport;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
@ -37,6 +36,7 @@ import org.dromara.easyes.common.enums.EsQueryTypeEnum;
|
|||||||
import org.dromara.easyes.common.enums.OrderTypeEnum;
|
import org.dromara.easyes.common.enums.OrderTypeEnum;
|
||||||
import org.dromara.easyes.common.join.BaseJoin;
|
import org.dromara.easyes.common.join.BaseJoin;
|
||||||
import org.dromara.easyes.common.utils.*;
|
import org.dromara.easyes.common.utils.*;
|
||||||
|
import org.dromara.easyes.common.utils.jackson.JsonUtils;
|
||||||
import org.dromara.easyes.core.biz.*;
|
import org.dromara.easyes.core.biz.*;
|
||||||
import org.dromara.easyes.core.cache.BaseCache;
|
import org.dromara.easyes.core.cache.BaseCache;
|
||||||
import org.dromara.easyes.core.cache.GlobalConfigCache;
|
import org.dromara.easyes.core.cache.GlobalConfigCache;
|
||||||
@ -1342,7 +1342,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
invokeMethod.invoke(entity, distance);
|
invokeMethod.invoke(entity, distance);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
// 遇到异常只提示, 不阻断流程 distance未设置不影核心业务
|
// 遇到异常只提示, 不阻断流程 distance未设置不影核心业务
|
||||||
LogUtils.formatError("set distance error, entity:%s,sortValues:%s,distanceField:%s,e:%s", entity, JSON.toJSONString(sortValues), distanceFields, e);
|
LogUtils.formatError("set distance error, entity:%s,sortValues:%s,distanceField:%s,e:%s", entity, JsonUtils.toJsonStr(sortValues), distanceFields, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1472,7 +1472,8 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
.filter(item -> Objects.equals(item.result(), successResult))
|
.filter(item -> Objects.equals(item.result(), successResult))
|
||||||
.count();
|
.count();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtils.error("bulk request exception", JSON.toJSONString(e));
|
e.printStackTrace();
|
||||||
|
LogUtils.error("bulk request exception");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
package org.dromara.easyes.core.toolkit;
|
package org.dromara.easyes.core.toolkit;
|
||||||
|
|
||||||
import co.elastic.clients.elasticsearch.indices.IndexSettings;
|
import co.elastic.clients.elasticsearch.indices.IndexSettings;
|
||||||
import com.alibaba.fastjson.serializer.SerializeFilter;
|
|
||||||
import com.alibaba.fastjson.serializer.ValueFilter;
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.dromara.easyes.annotation.*;
|
import org.dromara.easyes.annotation.*;
|
||||||
import org.dromara.easyes.annotation.rely.*;
|
import org.dromara.easyes.annotation.rely.*;
|
||||||
@ -195,38 +193,6 @@ public class EntityInfoHelper {
|
|||||||
entityInfo.setFieldList(fieldList);
|
entityInfo.setFieldList(fieldList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取fastjson 值过滤器 针对日期等需要格式化及转换字段处理
|
|
||||||
*
|
|
||||||
* @param entityInfo 实体信息缓存
|
|
||||||
* @param clazz 对应类
|
|
||||||
* @return 过滤器
|
|
||||||
*/
|
|
||||||
private static List<SerializeFilter> getValueFilter(EntityInfo entityInfo, Class<?> clazz) {
|
|
||||||
// 日期字段序列化过滤器
|
|
||||||
List<SerializeFilter> serializeFilters = new ArrayList<>();
|
|
||||||
Map<String, String> dateFormatMap = entityInfo.getClassDateFormatMap().get(clazz);
|
|
||||||
if (CollectionUtils.isEmpty(dateFormatMap)) {
|
|
||||||
return serializeFilters;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<Class<?>, Map<String, String>> nestedClassColumnMappingMap = entityInfo.getNestedOrObjectClassColumnMappingMap();
|
|
||||||
SerializeFilter serializeFilter = (ValueFilter) (object, name, value) -> {
|
|
||||||
Map<String, String> nestedColumnMappingMap = nestedClassColumnMappingMap.get(object.getClass());
|
|
||||||
if (nestedColumnMappingMap != null) {
|
|
||||||
Map<String, String> nestedDateFormatMap = entityInfo.getClassDateFormatMap().get(object.getClass());
|
|
||||||
if (CollectionUtils.isEmpty(nestedDateFormatMap)) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
return formatDate(name, value, nestedColumnMappingMap, nestedDateFormatMap);
|
|
||||||
} else {
|
|
||||||
return formatDate(name, value, entityInfo.getColumnMappingMap(), dateFormatMap);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
serializeFilters.add(serializeFilter);
|
|
||||||
return serializeFilters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段属性初始化
|
* 字段属性初始化
|
||||||
*
|
*
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import co.elastic.clients.elasticsearch.core.*;
|
|||||||
import co.elastic.clients.elasticsearch.indices.ExistsRequest;
|
import co.elastic.clients.elasticsearch.indices.ExistsRequest;
|
||||||
import co.elastic.clients.elasticsearch.indices.*;
|
import co.elastic.clients.elasticsearch.indices.*;
|
||||||
import co.elastic.clients.elasticsearch.indices.update_aliases.Action;
|
import co.elastic.clients.elasticsearch.indices.update_aliases.Action;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.dromara.easyes.annotation.rely.Analyzer;
|
import org.dromara.easyes.annotation.rely.Analyzer;
|
||||||
@ -1147,12 +1147,12 @@ public class IndexUtils {
|
|||||||
* @param client ElasticsearchClient
|
* @param client ElasticsearchClient
|
||||||
*/
|
*/
|
||||||
public static void saveReleaseIndex(String releaseIndexName, ElasticsearchClient client) {
|
public static void saveReleaseIndex(String releaseIndexName, ElasticsearchClient client) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
Map<String, Object> map = new HashMap<>();
|
||||||
jsonObject.put(ACTIVE_INDEX_KEY, releaseIndexName);
|
map.put(ACTIVE_INDEX_KEY, releaseIndexName);
|
||||||
jsonObject.put(GMT_MODIFIED, System.currentTimeMillis());
|
map.put(GMT_MODIFIED, System.currentTimeMillis());
|
||||||
IndexRequest<?> indexRequest = IndexRequest.of(x -> x
|
IndexRequest<?> indexRequest = IndexRequest.of(x -> x
|
||||||
.index(LOCK_INDEX)
|
.index(LOCK_INDEX)
|
||||||
.document(jsonObject)
|
.document(map)
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
client.index(indexRequest);
|
client.index(indexRequest);
|
||||||
@ -1176,9 +1176,9 @@ public class IndexUtils {
|
|||||||
.sort(b -> b.field(c -> c.field(GMT_MODIFIED).order(SortOrder.Desc)))
|
.sort(b -> b.field(c -> c.field(GMT_MODIFIED).order(SortOrder.Desc)))
|
||||||
.size(ONE)
|
.size(ONE)
|
||||||
);
|
);
|
||||||
SearchResponse<JSONObject> response = null;
|
SearchResponse<Map<String, String>> response = null;
|
||||||
try {
|
try {
|
||||||
response = client.search(searchRequest, JSONObject.class);
|
response = client.search(searchRequest, new TypeReference<Map<String, Object>>(){}.getType());
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
LogUtils.warn("Active failed, The machine that acquired lock is migrating, will try again later");
|
LogUtils.warn("Active failed, The machine that acquired lock is migrating, will try again later");
|
||||||
}
|
}
|
||||||
@ -1188,19 +1188,17 @@ public class IndexUtils {
|
|||||||
Optional.ofNullable(response).ifPresent(r -> r.hits().hits().forEach(searchHit -> Optional.ofNullable(searchHit.source())
|
Optional.ofNullable(response).ifPresent(r -> r.hits().hits().forEach(searchHit -> Optional.ofNullable(searchHit.source())
|
||||||
.flatMap(hit -> Optional.ofNullable(hit.get(ACTIVE_INDEX_KEY)))
|
.flatMap(hit -> Optional.ofNullable(hit.get(ACTIVE_INDEX_KEY)))
|
||||||
.ifPresent(indexName -> {
|
.ifPresent(indexName -> {
|
||||||
if (indexName instanceof String releaseIndexName) {
|
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
||||||
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
entityInfo.setIndexName(indexName);
|
||||||
entityInfo.setIndexName(releaseIndexName);
|
|
||||||
|
|
||||||
// 父子类型,须将所有子孙文档的索引也激活为最新索引
|
// 父子类型,须将所有子孙文档的索引也激活为最新索引
|
||||||
entityInfo.getRelationClassMap().forEach((k, v) -> {
|
entityInfo.getRelationClassMap().forEach((k, v) -> {
|
||||||
Optional.ofNullable(EntityInfoHelper.getEntityInfo(k)).ifPresent(i -> i.setIndexName(releaseIndexName));
|
Optional.ofNullable(EntityInfoHelper.getEntityInfo(k)).ifPresent(i -> i.setIndexName(indexName));
|
||||||
if (CollectionUtils.isNotEmpty(v)) {
|
if (CollectionUtils.isNotEmpty(v)) {
|
||||||
v.forEach(node -> Optional.ofNullable(EntityInfoHelper.getEntityInfo(node)).ifPresent(i -> i.setIndexName(releaseIndexName)));
|
v.forEach(node -> Optional.ofNullable(EntityInfoHelper.getEntityInfo(node)).ifPresent(i -> i.setIndexName(indexName)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
activated.set(Boolean.TRUE);
|
activated.set(Boolean.TRUE);
|
||||||
}
|
|
||||||
})));
|
})));
|
||||||
|
|
||||||
// 达到最大重试次数仍未成功,则终止流程,避免浪费资源
|
// 达到最大重试次数仍未成功,则终止流程,避免浪费资源
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user