diff --git a/easy-es-common/pom.xml b/easy-es-common/pom.xml index 0f707f30..08dca084 100644 --- a/easy-es-common/pom.xml +++ b/easy-es-common/pom.xml @@ -43,11 +43,6 @@ jakarta.json-api - - com.alibaba - fastjson - - org.projectlombok lombok diff --git a/easy-es-core/src/main/java/org/dromara/easyes/core/biz/EntityFieldInfo.java b/easy-es-core/src/main/java/org/dromara/easyes/core/biz/EntityFieldInfo.java index 788051b9..8c9f319f 100644 --- a/easy-es-core/src/main/java/org/dromara/easyes/core/biz/EntityFieldInfo.java +++ b/easy-es-core/src/main/java/org/dromara/easyes/core/biz/EntityFieldInfo.java @@ -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; /** * 复制字段 diff --git a/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapperImpl.java b/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapperImpl.java index aadba10d..23c2d3d0 100644 --- a/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapperImpl.java +++ b/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapperImpl.java @@ -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 implements BaseEsMapper { 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 implements BaseEsMapper { .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; } } diff --git a/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/EntityInfoHelper.java b/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/EntityInfoHelper.java index b80d0612..e751b76b 100644 --- a/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/EntityInfoHelper.java +++ b/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/EntityInfoHelper.java @@ -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 getValueFilter(EntityInfo entityInfo, Class clazz) { - // 日期字段序列化过滤器 - List serializeFilters = new ArrayList<>(); - Map dateFormatMap = entityInfo.getClassDateFormatMap().get(clazz); - if (CollectionUtils.isEmpty(dateFormatMap)) { - return serializeFilters; - } - - Map, Map> nestedClassColumnMappingMap = entityInfo.getNestedOrObjectClassColumnMappingMap(); - SerializeFilter serializeFilter = (ValueFilter) (object, name, value) -> { - Map nestedColumnMappingMap = nestedClassColumnMappingMap.get(object.getClass()); - if (nestedColumnMappingMap != null) { - Map 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; - } - /** * 字段属性初始化 * diff --git a/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/IndexUtils.java b/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/IndexUtils.java index fcad386c..65ac60cd 100644 --- a/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/IndexUtils.java +++ b/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/IndexUtils.java @@ -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 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 response = null; + SearchResponse> response = null; try { - response = client.search(searchRequest, JSONObject.class); + response = client.search(searchRequest, new TypeReference>(){}.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 entityInfo = EntityInfoHelper.getEntityInfo(entityClass); + entityInfo.setIndexName(indexName); - // 父子类型,须将所有子孙文档的索引也激活为最新索引 - entityInfo.getRelationClassMap().forEach((k, v) -> { - Optional.ofNullable(EntityInfoHelper.getEntityInfo(k)).ifPresent(i -> i.setIndexName(releaseIndexName)); - if (CollectionUtils.isNotEmpty(v)) { - v.forEach(node -> Optional.ofNullable(EntityInfoHelper.getEntityInfo(node)).ifPresent(i -> i.setIndexName(releaseIndexName))); - } - }); - activated.set(Boolean.TRUE); - } + // 父子类型,须将所有子孙文档的索引也激活为最新索引 + entityInfo.getRelationClassMap().forEach((k, v) -> { + 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(indexName))); + } + }); + activated.set(Boolean.TRUE); }))); // 达到最大重试次数仍未成功,则终止流程,避免浪费资源