替换fastjson为jackson
This commit is contained in:
+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)
|
||||
|
||||
Reference in New Issue
Block a user