替换fastjson为jackson
This commit is contained in:
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.central.search.client.feign;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.search.client.feign.fallback.SearchServiceFallbackFactory;
|
||||
import com.central.search.model.SearchDto;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -19,5 +19,5 @@ public interface SearchService {
|
||||
* @param searchDto 搜索Dto
|
||||
*/
|
||||
@PostMapping(value = "/search/{indexName}")
|
||||
PageResult<JSONObject> strQuery(@PathVariable("indexName") String indexName, @RequestBody SearchDto searchDto);
|
||||
PageResult<JsonNode> strQuery(@PathVariable("indexName") String indexName, @RequestBody SearchDto searchDto);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.central.search.client.feign.fallback;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.search.client.feign.SearchService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SearchServiceFallbackFactory implements FallbackFactory<SearchServi
|
||||
public SearchService create(Throwable throwable) {
|
||||
return (indexName, searchDto) -> {
|
||||
log.error("通过索引{}搜索异常:{}", indexName, throwable);
|
||||
return PageResult.<JSONObject>builder().build();
|
||||
return PageResult.<JsonNode>builder().build();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package com.central.search.client.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.search.model.LogicDelDto;
|
||||
import com.central.search.model.SearchDto;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -19,7 +19,7 @@ public interface IQueryService {
|
||||
* @param indexName 索引名
|
||||
* @param searchDto 搜索Dto
|
||||
*/
|
||||
PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto);
|
||||
PageResult<JsonNode> strQuery(String indexName, SearchDto searchDto);
|
||||
|
||||
/**
|
||||
* 查询文档列表
|
||||
@@ -27,7 +27,7 @@ public interface IQueryService {
|
||||
* @param searchDto 搜索Dto
|
||||
* @param logicDelDto 逻辑删除Dto
|
||||
*/
|
||||
PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto, LogicDelDto logicDelDto);
|
||||
PageResult<JsonNode> strQuery(String indexName, SearchDto searchDto, LogicDelDto logicDelDto);
|
||||
|
||||
/**
|
||||
* 访问统计聚合查询
|
||||
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
package com.central.search.client.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.search.client.feign.AggregationService;
|
||||
import com.central.search.client.feign.SearchService;
|
||||
import com.central.search.client.service.IQueryService;
|
||||
import com.central.search.model.LogicDelDto;
|
||||
import com.central.search.model.SearchDto;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
@@ -26,12 +26,12 @@ public class QueryServiceImpl implements IQueryService {
|
||||
private AggregationService aggregationService;
|
||||
|
||||
@Override
|
||||
public PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto) {
|
||||
public PageResult<JsonNode> strQuery(String indexName, SearchDto searchDto) {
|
||||
return strQuery(indexName, searchDto, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto, LogicDelDto logicDelDto) {
|
||||
public PageResult<JsonNode> strQuery(String indexName, SearchDto searchDto, LogicDelDto logicDelDto) {
|
||||
setLogicDelQueryStr(searchDto, logicDelDto);
|
||||
return searchService.strQuery(indexName, searchDto);
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,10 +1,10 @@
|
||||
package com.central.admin.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.admin.model.IndexDto;
|
||||
import com.central.admin.service.IIndexService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.utils.JsonUtil;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
@@ -72,6 +72,9 @@ public class IndexServiceImpl implements IIndexService {
|
||||
|
||||
@Override
|
||||
public PageResult<Map<String, String>> list(String queryStr, String indices) throws IOException {
|
||||
if (StrUtil.isNotEmpty(queryStr)) {
|
||||
indices = queryStr;
|
||||
}
|
||||
Response response = elasticsearchRestTemplate.getClient().getLowLevelClient()
|
||||
.performRequest(new Request(
|
||||
"GET",
|
||||
@@ -99,7 +102,7 @@ public class IndexServiceImpl implements IIndexService {
|
||||
String settingsStr = getIndexResponse.getSettings().get(indexName).toString();
|
||||
Object settingsObj = null;
|
||||
if (StrUtil.isNotEmpty(settingsStr)) {
|
||||
settingsObj = JSONObject.parse(settingsStr);
|
||||
settingsObj = JsonUtil.parse(settingsStr);
|
||||
}
|
||||
Map<String, Object> result = new HashMap<>(1);
|
||||
Map<String, Object> indexMap = new HashMap<>(3);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.central.search.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.*;
|
||||
|
||||
import com.central.search.model.SearchDto;
|
||||
import com.central.search.service.ISearchService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -34,7 +34,7 @@ public class SearchController {
|
||||
* @param searchDto 搜索Dto
|
||||
*/
|
||||
@PostMapping("/{indexName}")
|
||||
public PageResult<JSONObject> strQuery(@PathVariable String indexName, @RequestBody(required = false) SearchDto searchDto) throws IOException {
|
||||
public PageResult<JsonNode> strQuery(@PathVariable String indexName, @RequestBody(required = false) SearchDto searchDto) throws IOException {
|
||||
if (searchDto == null) {
|
||||
searchDto = new SearchDto();
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.central.search.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.search.model.SearchDto;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -17,5 +17,5 @@ public interface ISearchService {
|
||||
* @param searchDto 搜索Dto
|
||||
* @return
|
||||
*/
|
||||
PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto) throws IOException;
|
||||
PageResult<JsonNode> strQuery(String indexName, SearchDto searchDto) throws IOException;
|
||||
}
|
||||
|
||||
+2
-2
@@ -150,7 +150,7 @@ public class AggregationServiceImpl implements IAggregationService {
|
||||
.fixedInterval(new DateHistogramInterval("90m"))
|
||||
.format(CommonConstant.DATETIME_FORMAT)
|
||||
//时区相差8小时
|
||||
.timeZone(ZoneId.of("GMT+8"))
|
||||
.timeZone(ZoneId.of(CommonConstant.TIME_ZONE_GMT8))
|
||||
.minDocCount(0L)
|
||||
.extendedBounds(new ExtendedBounds(
|
||||
curDateTime.minusDays(1).format(DateTimeFormatter.ofPattern(CommonConstant.DATETIME_FORMAT)),
|
||||
@@ -176,7 +176,7 @@ public class AggregationServiceImpl implements IAggregationService {
|
||||
.calendarInterval(DateHistogramInterval.DAY)
|
||||
.format(CommonConstant.DATE_FORMAT)
|
||||
//时区相差8小时
|
||||
.timeZone(ZoneId.of("GMT+8"))
|
||||
.timeZone(ZoneId.of(CommonConstant.TIME_ZONE_GMT8))
|
||||
.minDocCount(0L)
|
||||
.extendedBounds(new ExtendedBounds(
|
||||
localDate.minusDays(6).format(DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT)),
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.central.search.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.es.utils.SearchBuilder;
|
||||
import com.central.search.model.SearchDto;
|
||||
import com.central.search.service.ISearchService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -32,7 +32,7 @@ public class SearchServiceImpl implements ISearchService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto) throws IOException {
|
||||
public PageResult<JsonNode> strQuery(String indexName, SearchDto searchDto) throws IOException {
|
||||
return SearchBuilder.builder(elasticsearchRestTemplate, indexName)
|
||||
.setStringQuery(searchDto.getQueryStr())
|
||||
.addSort(searchDto.getSortCol(), SortOrder.DESC)
|
||||
|
||||
+2
-2
@@ -7,7 +7,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.annotation.LoginUser;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.model.*;
|
||||
@@ -18,6 +17,7 @@ import com.central.search.client.service.IQueryService;
|
||||
import com.central.search.model.LogicDelDto;
|
||||
import com.central.search.model.SearchDto;
|
||||
import com.central.user.model.SysUserExcel;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -280,7 +280,7 @@ public class SysUserController {
|
||||
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
|
||||
})
|
||||
@GetMapping("/users/search")
|
||||
public PageResult<JSONObject> search(SearchDto searchDto) {
|
||||
public PageResult<JsonNode> search(SearchDto searchDto) {
|
||||
searchDto.setIsHighlighter(true);
|
||||
searchDto.setSortCol("createTime");
|
||||
return queryService.strQuery("sys_user", searchDto, SEARCH_LOGIC_DEL_DTO);
|
||||
|
||||
Reference in New Issue
Block a user