feat: 删除fastjson

This commit is contained in:
jaime 2025-02-27 14:18:47 +08:00
parent d320aafb60
commit bdc279fe54
5 changed files with 21 additions and 63 deletions

View File

@ -43,11 +43,6 @@
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>

View File

@ -1,6 +1,5 @@
package org.dromara.easyes.core.biz;
import com.alibaba.fastjson.serializer.NameFilter;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
@ -97,7 +96,6 @@ public class EntityFieldInfo {
@Setter(AccessLevel.NONE)
@Getter(AccessLevel.NONE)
private String sqlSelect;
private NameFilter nameFilter;
/**
* 复制字段

View File

@ -26,7 +26,6 @@ import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.JsonpUtils;
import co.elastic.clients.transport.TransportOptions;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import com.alibaba.fastjson.JSON;
import lombok.Setter;
import lombok.SneakyThrows;
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.join.BaseJoin;
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.cache.BaseCache;
import org.dromara.easyes.core.cache.GlobalConfigCache;
@ -1342,7 +1342,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
invokeMethod.invoke(entity, distance);
} catch (Throwable e) {
// 遇到异常只提示, 不阻断流程 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))
.count();
} catch (IOException e) {
LogUtils.error("bulk request exception", JSON.toJSONString(e));
e.printStackTrace();
LogUtils.error("bulk request exception");
return 0;
}
}

View File

@ -1,8 +1,6 @@
package org.dromara.easyes.core.toolkit;
import co.elastic.clients.elasticsearch.indices.IndexSettings;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.ValueFilter;
import lombok.SneakyThrows;
import org.dromara.easyes.annotation.*;
import org.dromara.easyes.annotation.rely.*;
@ -195,38 +193,6 @@ public class EntityInfoHelper {
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;
}
/**
* 字段属性初始化
*

View File

@ -10,7 +10,7 @@ import co.elastic.clients.elasticsearch.core.*;
import co.elastic.clients.elasticsearch.indices.ExistsRequest;
import co.elastic.clients.elasticsearch.indices.*;
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.NoArgsConstructor;
import org.dromara.easyes.annotation.rely.Analyzer;
@ -1147,12 +1147,12 @@ public class IndexUtils {
* @param client ElasticsearchClient
*/
public static void saveReleaseIndex(String releaseIndexName, ElasticsearchClient client) {
JSONObject jsonObject = new JSONObject();
jsonObject.put(ACTIVE_INDEX_KEY, releaseIndexName);
jsonObject.put(GMT_MODIFIED, System.currentTimeMillis());
Map<String, Object> map = new HashMap<>();
map.put(ACTIVE_INDEX_KEY, releaseIndexName);
map.put(GMT_MODIFIED, System.currentTimeMillis());
IndexRequest<?> indexRequest = IndexRequest.of(x -> x
.index(LOCK_INDEX)
.document(jsonObject)
.document(map)
);
try {
client.index(indexRequest);
@ -1176,9 +1176,9 @@ public class IndexUtils {
.sort(b -> b.field(c -> c.field(GMT_MODIFIED).order(SortOrder.Desc)))
.size(ONE)
);
SearchResponse<JSONObject> response = null;
SearchResponse<Map<String, String>> response = null;
try {
response = client.search(searchRequest, JSONObject.class);
response = client.search(searchRequest, new TypeReference<Map<String, Object>>(){}.getType());
} catch (Throwable e) {
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())
.flatMap(hit -> Optional.ofNullable(hit.get(ACTIVE_INDEX_KEY)))
.ifPresent(indexName -> {
if (indexName instanceof String releaseIndexName) {
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
entityInfo.setIndexName(releaseIndexName);
entityInfo.setIndexName(indexName);
// 父子类型,须将所有子孙文档的索引也激活为最新索引
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)) {
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);
}
})));
// 达到最大重试次数仍未成功,则终止流程,避免浪费资源