替换fastjson为jackson
This commit is contained in:
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
package com.central.search.client.feign;
|
package com.central.search.client.feign;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.constant.ServiceNameConstants;
|
import com.central.common.constant.ServiceNameConstants;
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.search.client.feign.fallback.SearchServiceFallbackFactory;
|
import com.central.search.client.feign.fallback.SearchServiceFallbackFactory;
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -19,5 +19,5 @@ public interface SearchService {
|
|||||||
* @param searchDto 搜索Dto
|
* @param searchDto 搜索Dto
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/search/{indexName}")
|
@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;
|
package com.central.search.client.feign.fallback;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.search.client.feign.SearchService;
|
import com.central.search.client.feign.SearchService;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import feign.hystrix.FallbackFactory;
|
import feign.hystrix.FallbackFactory;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ public class SearchServiceFallbackFactory implements FallbackFactory<SearchServi
|
|||||||
public SearchService create(Throwable throwable) {
|
public SearchService create(Throwable throwable) {
|
||||||
return (indexName, searchDto) -> {
|
return (indexName, searchDto) -> {
|
||||||
log.error("通过索引{}搜索异常:{}", indexName, throwable);
|
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;
|
package com.central.search.client.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.search.model.LogicDelDto;
|
import com.central.search.model.LogicDelDto;
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ public interface IQueryService {
|
|||||||
* @param indexName 索引名
|
* @param indexName 索引名
|
||||||
* @param searchDto 搜索Dto
|
* @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 searchDto 搜索Dto
|
||||||
* @param logicDelDto 逻辑删除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;
|
package com.central.search.client.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.search.client.feign.AggregationService;
|
import com.central.search.client.feign.AggregationService;
|
||||||
import com.central.search.client.feign.SearchService;
|
import com.central.search.client.feign.SearchService;
|
||||||
import com.central.search.client.service.IQueryService;
|
import com.central.search.client.service.IQueryService;
|
||||||
import com.central.search.model.LogicDelDto;
|
import com.central.search.model.LogicDelDto;
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -26,12 +26,12 @@ public class QueryServiceImpl implements IQueryService {
|
|||||||
private AggregationService aggregationService;
|
private AggregationService aggregationService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto) {
|
public PageResult<JsonNode> strQuery(String indexName, SearchDto searchDto) {
|
||||||
return strQuery(indexName, searchDto, null);
|
return strQuery(indexName, searchDto, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto, LogicDelDto logicDelDto) {
|
public PageResult<JsonNode> strQuery(String indexName, SearchDto searchDto, LogicDelDto logicDelDto) {
|
||||||
setLogicDelQueryStr(searchDto, logicDelDto);
|
setLogicDelQueryStr(searchDto, logicDelDto);
|
||||||
return searchService.strQuery(indexName, searchDto);
|
return searchService.strQuery(indexName, searchDto);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -1,10 +1,10 @@
|
|||||||
package com.central.admin.service.impl;
|
package com.central.admin.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.admin.model.IndexDto;
|
import com.central.admin.model.IndexDto;
|
||||||
import com.central.admin.service.IIndexService;
|
import com.central.admin.service.IIndexService;
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.utils.JsonUtil;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
@@ -72,6 +72,9 @@ public class IndexServiceImpl implements IIndexService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<Map<String, String>> list(String queryStr, String indices) throws IOException {
|
public PageResult<Map<String, String>> list(String queryStr, String indices) throws IOException {
|
||||||
|
if (StrUtil.isNotEmpty(queryStr)) {
|
||||||
|
indices = queryStr;
|
||||||
|
}
|
||||||
Response response = elasticsearchRestTemplate.getClient().getLowLevelClient()
|
Response response = elasticsearchRestTemplate.getClient().getLowLevelClient()
|
||||||
.performRequest(new Request(
|
.performRequest(new Request(
|
||||||
"GET",
|
"GET",
|
||||||
@@ -99,7 +102,7 @@ public class IndexServiceImpl implements IIndexService {
|
|||||||
String settingsStr = getIndexResponse.getSettings().get(indexName).toString();
|
String settingsStr = getIndexResponse.getSettings().get(indexName).toString();
|
||||||
Object settingsObj = null;
|
Object settingsObj = null;
|
||||||
if (StrUtil.isNotEmpty(settingsStr)) {
|
if (StrUtil.isNotEmpty(settingsStr)) {
|
||||||
settingsObj = JSONObject.parse(settingsStr);
|
settingsObj = JsonUtil.parse(settingsStr);
|
||||||
}
|
}
|
||||||
Map<String, Object> result = new HashMap<>(1);
|
Map<String, Object> result = new HashMap<>(1);
|
||||||
Map<String, Object> indexMap = new HashMap<>(3);
|
Map<String, Object> indexMap = new HashMap<>(3);
|
||||||
|
|||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
package com.central.search.controller;
|
package com.central.search.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.*;
|
import com.central.common.model.*;
|
||||||
|
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
import com.central.search.service.ISearchService;
|
import com.central.search.service.ISearchService;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -34,7 +34,7 @@ public class SearchController {
|
|||||||
* @param searchDto 搜索Dto
|
* @param searchDto 搜索Dto
|
||||||
*/
|
*/
|
||||||
@PostMapping("/{indexName}")
|
@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) {
|
if (searchDto == null) {
|
||||||
searchDto = new SearchDto();
|
searchDto = new SearchDto();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
package com.central.search.service;
|
package com.central.search.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -17,5 +17,5 @@ public interface ISearchService {
|
|||||||
* @param searchDto 搜索Dto
|
* @param searchDto 搜索Dto
|
||||||
* @return
|
* @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"))
|
.fixedInterval(new DateHistogramInterval("90m"))
|
||||||
.format(CommonConstant.DATETIME_FORMAT)
|
.format(CommonConstant.DATETIME_FORMAT)
|
||||||
//时区相差8小时
|
//时区相差8小时
|
||||||
.timeZone(ZoneId.of("GMT+8"))
|
.timeZone(ZoneId.of(CommonConstant.TIME_ZONE_GMT8))
|
||||||
.minDocCount(0L)
|
.minDocCount(0L)
|
||||||
.extendedBounds(new ExtendedBounds(
|
.extendedBounds(new ExtendedBounds(
|
||||||
curDateTime.minusDays(1).format(DateTimeFormatter.ofPattern(CommonConstant.DATETIME_FORMAT)),
|
curDateTime.minusDays(1).format(DateTimeFormatter.ofPattern(CommonConstant.DATETIME_FORMAT)),
|
||||||
@@ -176,7 +176,7 @@ public class AggregationServiceImpl implements IAggregationService {
|
|||||||
.calendarInterval(DateHistogramInterval.DAY)
|
.calendarInterval(DateHistogramInterval.DAY)
|
||||||
.format(CommonConstant.DATE_FORMAT)
|
.format(CommonConstant.DATE_FORMAT)
|
||||||
//时区相差8小时
|
//时区相差8小时
|
||||||
.timeZone(ZoneId.of("GMT+8"))
|
.timeZone(ZoneId.of(CommonConstant.TIME_ZONE_GMT8))
|
||||||
.minDocCount(0L)
|
.minDocCount(0L)
|
||||||
.extendedBounds(new ExtendedBounds(
|
.extendedBounds(new ExtendedBounds(
|
||||||
localDate.minusDays(6).format(DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT)),
|
localDate.minusDays(6).format(DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT)),
|
||||||
|
|||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
package com.central.search.service.impl;
|
package com.central.search.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.es.utils.SearchBuilder;
|
import com.central.es.utils.SearchBuilder;
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
import com.central.search.service.ISearchService;
|
import com.central.search.service.ISearchService;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -32,7 +32,7 @@ public class SearchServiceImpl implements ISearchService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@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)
|
return SearchBuilder.builder(elasticsearchRestTemplate, indexName)
|
||||||
.setStringQuery(searchDto.getQueryStr())
|
.setStringQuery(searchDto.getQueryStr())
|
||||||
.addSort(searchDto.getSortCol(), SortOrder.DESC)
|
.addSort(searchDto.getSortCol(), SortOrder.DESC)
|
||||||
|
|||||||
+2
-2
@@ -7,7 +7,6 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.annotation.LoginUser;
|
import com.central.common.annotation.LoginUser;
|
||||||
import com.central.common.constant.CommonConstant;
|
import com.central.common.constant.CommonConstant;
|
||||||
import com.central.common.model.*;
|
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.LogicDelDto;
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
import com.central.user.model.SysUserExcel;
|
import com.central.user.model.SysUserExcel;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
@@ -280,7 +280,7 @@ public class SysUserController {
|
|||||||
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
|
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
|
||||||
})
|
})
|
||||||
@GetMapping("/users/search")
|
@GetMapping("/users/search")
|
||||||
public PageResult<JSONObject> search(SearchDto searchDto) {
|
public PageResult<JsonNode> search(SearchDto searchDto) {
|
||||||
searchDto.setIsHighlighter(true);
|
searchDto.setIsHighlighter(true);
|
||||||
searchDto.setSortCol("createTime");
|
searchDto.setSortCol("createTime");
|
||||||
return queryService.strQuery("sys_user", searchDto, SEARCH_LOGIC_DEL_DTO);
|
return queryService.strQuery("sys_user", searchDto, SEARCH_LOGIC_DEL_DTO);
|
||||||
|
|||||||
+8
-7
@@ -1,8 +1,9 @@
|
|||||||
package com.central.oauth2.common.util;
|
package com.central.oauth2.common.util;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.constant.SecurityConstants;
|
import com.central.common.constant.SecurityConstants;
|
||||||
|
import com.central.common.utils.JsonUtil;
|
||||||
import com.central.common.utils.RsaUtils;
|
import com.central.common.utils.RsaUtils;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.security.jwt.Jwt;
|
import org.springframework.security.jwt.Jwt;
|
||||||
@@ -46,10 +47,10 @@ public class JwtUtils {
|
|||||||
* @param rsaPublicKey 公钥
|
* @param rsaPublicKey 公钥
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static JSONObject decodeAndVerify(String jwtToken, RSAPublicKey rsaPublicKey) {
|
public static JsonNode decodeAndVerify(String jwtToken, RSAPublicKey rsaPublicKey) {
|
||||||
SignatureVerifier rsaVerifier = new RsaVerifier(rsaPublicKey);
|
SignatureVerifier rsaVerifier = new RsaVerifier(rsaPublicKey);
|
||||||
Jwt jwt = JwtHelper.decodeAndVerify(jwtToken, rsaVerifier);
|
Jwt jwt = JwtHelper.decodeAndVerify(jwtToken, rsaVerifier);
|
||||||
return JSONObject.parseObject(jwt.getClaims());
|
return JsonUtil.parse(jwt.getClaims());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +58,7 @@ public class JwtUtils {
|
|||||||
* @param jwtToken token值
|
* @param jwtToken token值
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static JSONObject decodeAndVerify(String jwtToken) {
|
public static JsonNode decodeAndVerify(String jwtToken) {
|
||||||
return decodeAndVerify(jwtToken, getPubKeyObj());
|
return decodeAndVerify(jwtToken, getPubKeyObj());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,8 +68,8 @@ public class JwtUtils {
|
|||||||
* @param currTime 当前时间
|
* @param currTime 当前时间
|
||||||
* @return 未过期:true,已过期:false
|
* @return 未过期:true,已过期:false
|
||||||
*/
|
*/
|
||||||
public static boolean checkExp(JSONObject claims, long currTime) {
|
public static boolean checkExp(JsonNode claims, long currTime) {
|
||||||
long exp = claims.getLong("exp");
|
long exp = claims.get("exp").asLong();
|
||||||
if (exp < currTime) {
|
if (exp < currTime) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -80,7 +81,7 @@ public class JwtUtils {
|
|||||||
* @param claims jwt内容
|
* @param claims jwt内容
|
||||||
* @return 未过期:true,已过期:false
|
* @return 未过期:true,已过期:false
|
||||||
*/
|
*/
|
||||||
public static boolean checkExp(JSONObject claims) {
|
public static boolean checkExp(JsonNode claims) {
|
||||||
return checkExp(claims, System.currentTimeMillis());
|
return checkExp(claims, System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,5 +86,10 @@
|
|||||||
<artifactId>reactor-core</artifactId>
|
<artifactId>reactor-core</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
+1
@@ -98,6 +98,7 @@ public interface CommonConstant {
|
|||||||
String SIMPLE_MONTH_FORMAT = "yyyyMM";
|
String SIMPLE_MONTH_FORMAT = "yyyyMM";
|
||||||
String SIMPLE_DATE_FORMAT = "yyyyMMdd";
|
String SIMPLE_DATE_FORMAT = "yyyyMMdd";
|
||||||
String SIMPLE_DATETIME_FORMAT = "yyyyMMddHHmmss";
|
String SIMPLE_DATETIME_FORMAT = "yyyyMMddHHmmss";
|
||||||
|
String TIME_ZONE_GMT8 = "GMT+8";
|
||||||
|
|
||||||
String DEF_USER_PASSWORD = "123456";
|
String DEF_USER_PASSWORD = "123456";
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,179 @@
|
|||||||
|
package com.central.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import com.central.common.constant.CommonConstant;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.json.JsonReadFeature;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.*;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于 Jackson 的 json 工具类
|
||||||
|
*
|
||||||
|
* @author zlt
|
||||||
|
* @date 2020/10/8
|
||||||
|
* <p>
|
||||||
|
* Blog: https://zlt2000.gitee.io
|
||||||
|
* Github: https://github.com/zlt2000
|
||||||
|
*/
|
||||||
|
public class JsonUtil {
|
||||||
|
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
// 忽略在json字符串中存在,但是在java对象中不存在对应属性的情况
|
||||||
|
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
// 忽略空Bean转json的错误
|
||||||
|
MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
|
||||||
|
// 允许不带引号的字段名称
|
||||||
|
MAPPER.configure(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES.mappedFeature(), true);
|
||||||
|
// 允许单引号
|
||||||
|
MAPPER.configure(JsonReadFeature.ALLOW_SINGLE_QUOTES.mappedFeature(), true);
|
||||||
|
// allow int startWith 0
|
||||||
|
MAPPER.configure(JsonReadFeature.ALLOW_LEADING_ZEROS_FOR_NUMBERS.mappedFeature(), true);
|
||||||
|
// 允许字符串存在转义字符:\r \n \t
|
||||||
|
MAPPER.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
|
||||||
|
// 排除空值字段
|
||||||
|
MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
// 使用驼峰式
|
||||||
|
MAPPER.setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE);
|
||||||
|
// 使用bean名称
|
||||||
|
MAPPER.enable(MapperFeature.USE_STD_BEAN_NAMING);
|
||||||
|
// 所有日期格式都统一为固定格式
|
||||||
|
MAPPER.setDateFormat(new SimpleDateFormat(CommonConstant.DATETIME_FORMAT));
|
||||||
|
MAPPER.setTimeZone(TimeZone.getTimeZone(CommonConstant.TIME_ZONE_GMT8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象转换为json字符串
|
||||||
|
* @param o 要转换的对象
|
||||||
|
*/
|
||||||
|
public static String toJSONString(Object o) {
|
||||||
|
return toJSONString(o, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象转换为json字符串
|
||||||
|
* @param o 要转换的对象
|
||||||
|
* @param format 是否格式化json
|
||||||
|
*/
|
||||||
|
public static String toJSONString(Object o, boolean format) {
|
||||||
|
try {
|
||||||
|
if (o == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (o instanceof Number) {
|
||||||
|
return o.toString();
|
||||||
|
}
|
||||||
|
if (o instanceof String) {
|
||||||
|
return (String)o;
|
||||||
|
}
|
||||||
|
if (format) {
|
||||||
|
return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(o);
|
||||||
|
}
|
||||||
|
return MAPPER.writeValueAsString(o);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串转换为自定义对象
|
||||||
|
* @param json json字符串
|
||||||
|
* @param cls 目标对象
|
||||||
|
*/
|
||||||
|
public static <T> T toObject(String json, Class<T> cls) {
|
||||||
|
if(StringUtils.isBlank(json) || cls == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return MAPPER.readValue(json, cls);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串转换为自定义对象
|
||||||
|
* @param json json字符串
|
||||||
|
* @param typeReference 目标对象类型
|
||||||
|
*/
|
||||||
|
public static <T> T toObject(String json, TypeReference<T> typeReference) {
|
||||||
|
if(StringUtils.isBlank(json) || typeReference == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return MAPPER.readValue(json, typeReference);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串转换为JsonNode对象
|
||||||
|
* @param json json字符串
|
||||||
|
*/
|
||||||
|
public static JsonNode parse(String json) {
|
||||||
|
if (StringUtils.isBlank(json)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return MAPPER.readTree(json);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象转换为map对象
|
||||||
|
* @param o 要转换的对象
|
||||||
|
*/
|
||||||
|
public static <K, V> Map<K, V> toMap(Object o) {
|
||||||
|
if (o == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (o instanceof String) {
|
||||||
|
return toObject((String)o, Map.class);
|
||||||
|
}
|
||||||
|
return MAPPER.convertValue(o, Map.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串转换为list对象
|
||||||
|
* @param json json字符串
|
||||||
|
*/
|
||||||
|
public static <T> List<T> toList(String json) {
|
||||||
|
if (StringUtils.isBlank(json)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return MAPPER.readValue(json, List.class);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* json字符串转换为list
|
||||||
|
* @param json json字符串
|
||||||
|
* @param cls list的元素类型
|
||||||
|
*/
|
||||||
|
public static <T> List<T> toList(String json, Class<T> cls) {
|
||||||
|
if (StringUtils.isBlank(json)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, cls);
|
||||||
|
return MAPPER.readValue(json, javaType);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package com.central.common.utils;
|
package com.central.common.utils;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||||
@@ -49,7 +48,7 @@ public class WebfluxResponseUtil {
|
|||||||
response.setStatusCode(HttpStatus.valueOf(httpStatus));
|
response.setStatusCode(HttpStatus.valueOf(httpStatus));
|
||||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||||
DataBufferFactory dataBufferFactory = response.bufferFactory();
|
DataBufferFactory dataBufferFactory = response.bufferFactory();
|
||||||
DataBuffer buffer = dataBufferFactory.wrap(JSONObject.toJSONString(result).getBytes(Charset.defaultCharset()));
|
DataBuffer buffer = dataBufferFactory.wrap(JsonUtil.toJSONString(result).getBytes(Charset.defaultCharset()));
|
||||||
return response.writeWith(Mono.just(buffer)).doOnError((error) -> {
|
return response.writeWith(Mono.just(buffer)).doOnError((error) -> {
|
||||||
DataBufferUtils.release(buffer);
|
DataBufferUtils.release(buffer);
|
||||||
});
|
});
|
||||||
|
|||||||
+20
-14
@@ -3,9 +3,10 @@ package com.central.es.utils;
|
|||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.BooleanUtil;
|
import cn.hutool.core.util.BooleanUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.utils.JsonUtil;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.apache.commons.beanutils.PropertyUtils;
|
import org.apache.commons.beanutils.PropertyUtils;
|
||||||
@@ -200,16 +201,16 @@ public class SearchBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回列表结果 List<JSONObject>
|
* 返回列表结果 List<JsonNode>
|
||||||
*/
|
*/
|
||||||
public List<JSONObject> getList() throws IOException {
|
public List<JsonNode> getList() throws IOException {
|
||||||
return getList(this.get().getHits());
|
return getList(this.get().getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回分页结果 PageResult<JSONObject>
|
* 返回分页结果 PageResult<JSONObject>
|
||||||
*/
|
*/
|
||||||
public PageResult<JSONObject> getPage() throws IOException {
|
public PageResult<JsonNode> getPage() throws IOException {
|
||||||
return this.getPage(null, null);
|
return this.getPage(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,30 +219,31 @@ public class SearchBuilder {
|
|||||||
* @param page 当前页数
|
* @param page 当前页数
|
||||||
* @param limit 每页显示
|
* @param limit 每页显示
|
||||||
*/
|
*/
|
||||||
public PageResult<JSONObject> getPage(Integer page, Integer limit) throws IOException {
|
public PageResult<JsonNode> getPage(Integer page, Integer limit) throws IOException {
|
||||||
this.setPage(page, limit);
|
this.setPage(page, limit);
|
||||||
SearchResponse response = this.get();
|
SearchResponse response = this.get();
|
||||||
SearchHits searchHits = response.getHits();
|
SearchHits searchHits = response.getHits();
|
||||||
long totalCnt = searchHits.getTotalHits().value;
|
long totalCnt = searchHits.getTotalHits().value;
|
||||||
List<JSONObject> list = getList(searchHits);
|
List<JsonNode> list = getList(searchHits);
|
||||||
return PageResult.<JSONObject>builder().data(list).code(0).count(totalCnt).build();
|
return PageResult.<JsonNode>builder().data(list).code(0).count(totalCnt).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回JSON列表数据
|
* 返回JSON列表数据
|
||||||
*/
|
*/
|
||||||
private List<JSONObject> getList(SearchHits searchHits) {
|
private List<JsonNode> getList(SearchHits searchHits) {
|
||||||
List<JSONObject> list = new ArrayList<>();
|
List<JsonNode> list = new ArrayList<>();
|
||||||
if (searchHits != null) {
|
if (searchHits != null) {
|
||||||
searchHits.forEach(item -> {
|
searchHits.forEach(item -> {
|
||||||
JSONObject jsonObject = JSON.parseObject(item.getSourceAsString());
|
JsonNode jsonNode = JsonUtil.parse(item.getSourceAsString());
|
||||||
jsonObject.put("id", item.getId());
|
ObjectNode objectNode = (ObjectNode)jsonNode;
|
||||||
|
objectNode.put("id", item.getId());
|
||||||
|
|
||||||
Map<String, HighlightField> highlightFields = item.getHighlightFields();
|
Map<String, HighlightField> highlightFields = item.getHighlightFields();
|
||||||
if (highlightFields != null) {
|
if (highlightFields != null) {
|
||||||
populateHighLightedFields(jsonObject, highlightFields);
|
populateHighLightedFields(objectNode, highlightFields);
|
||||||
}
|
}
|
||||||
list.add(jsonObject);
|
list.add(objectNode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
@@ -257,8 +259,12 @@ public class SearchBuilder {
|
|||||||
try {
|
try {
|
||||||
String name = field.getName();
|
String name = field.getName();
|
||||||
if (!name.endsWith(".keyword")) {
|
if (!name.endsWith(".keyword")) {
|
||||||
|
if (result instanceof ObjectNode) {
|
||||||
|
((ObjectNode)result).put(field.getName(), concat(field.fragments()));
|
||||||
|
} else {
|
||||||
PropertyUtils.setProperty(result, field.getName(), concat(field.fragments()));
|
PropertyUtils.setProperty(result, field.getName(), concat(field.fragments()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||||
throw new ElasticsearchException("failed to set highlighted value for field: " + field.getName()
|
throw new ElasticsearchException("failed to set highlighted value for field: " + field.getName()
|
||||||
+ " with value: " + Arrays.toString(field.getFragments()), e);
|
+ " with value: " + Arrays.toString(field.getFragments()), e);
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
package com.rocketmq.demo.listener;
|
package com.rocketmq.demo.listener;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.central.common.utils.JsonUtil;
|
||||||
import com.rocketmq.demo.model.Order;
|
import com.rocketmq.demo.model.Order;
|
||||||
import com.rocketmq.demo.service.IOrderService;
|
import com.rocketmq.demo.service.IOrderService;
|
||||||
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
|
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
|
||||||
@@ -24,7 +24,7 @@ public class OrderTransactionListenerImpl implements RocketMQLocalTransactionLis
|
|||||||
public RocketMQLocalTransactionState executeLocalTransaction(Message message, Object arg) {
|
public RocketMQLocalTransactionState executeLocalTransaction(Message message, Object arg) {
|
||||||
//插入订单数据
|
//插入订单数据
|
||||||
String orderJson = new String(((byte[])message.getPayload()));
|
String orderJson = new String(((byte[])message.getPayload()));
|
||||||
Order order = JSON.parseObject(orderJson, Order.class);
|
Order order = JsonUtil.toObject(orderJson, Order.class);
|
||||||
orderService.save(order);
|
orderService.save(order);
|
||||||
|
|
||||||
String produceError = (String)message.getHeaders().get("produceError");
|
String produceError = (String)message.getHeaders().get("produceError");
|
||||||
|
|||||||
+2
-2
@@ -3,9 +3,9 @@ package com.central.gateway.route;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.alibaba.nacos.api.config.listener.Listener;
|
import com.alibaba.nacos.api.config.listener.Listener;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
|
import com.central.common.utils.JsonUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
|
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
|
||||||
import org.springframework.cloud.gateway.route.RouteDefinition;
|
import org.springframework.cloud.gateway.route.RouteDefinition;
|
||||||
@@ -87,7 +87,7 @@ public class NacosRouteDefinitionRepository implements RouteDefinitionRepository
|
|||||||
|
|
||||||
private List<RouteDefinition> getListByStr(String content) {
|
private List<RouteDefinition> getListByStr(String content) {
|
||||||
if (StrUtil.isNotEmpty(content)) {
|
if (StrUtil.isNotEmpty(content)) {
|
||||||
return JSONObject.parseArray(content, RouteDefinition.class);
|
return JsonUtil.toList(content, RouteDefinition.class);
|
||||||
}
|
}
|
||||||
return new ArrayList<>(0);
|
return new ArrayList<>(0);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -3,9 +3,9 @@ package com.central.gateway.route.nacos;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.alibaba.nacos.api.config.listener.Listener;
|
import com.alibaba.nacos.api.config.listener.Listener;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
|
import com.central.common.utils.JsonUtil;
|
||||||
import com.central.gateway.config.ZuulRouteEntity;
|
import com.central.gateway.config.ZuulRouteEntity;
|
||||||
import com.central.gateway.route.AbstractDynRouteLocator;
|
import com.central.gateway.route.AbstractDynRouteLocator;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -106,7 +106,7 @@ public class NacosDynRouteLocator extends AbstractDynRouteLocator {
|
|||||||
|
|
||||||
public List<ZuulRouteEntity> getListByStr(String content) {
|
public List<ZuulRouteEntity> getListByStr(String content) {
|
||||||
if (StrUtil.isNotEmpty(content)) {
|
if (StrUtil.isNotEmpty(content)) {
|
||||||
return JSONObject.parseArray(content, ZuulRouteEntity.class);
|
return JsonUtil.toList(content, ZuulRouteEntity.class);
|
||||||
}
|
}
|
||||||
return new ArrayList<>(0);
|
return new ArrayList<>(0);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
package com.central.log.controller;
|
package com.central.log.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.search.client.service.IQueryService;
|
import com.central.search.client.service.IQueryService;
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -34,7 +34,7 @@ public class AuditLogController {
|
|||||||
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
|
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
|
||||||
})
|
})
|
||||||
@GetMapping(value = "/auditLog")
|
@GetMapping(value = "/auditLog")
|
||||||
public PageResult<JSONObject> getPage(SearchDto searchDto) {
|
public PageResult<JsonNode> getPage(SearchDto searchDto) {
|
||||||
searchDto.setIsHighlighter(true);
|
searchDto.setIsHighlighter(true);
|
||||||
searchDto.setSortCol("timestamp");
|
searchDto.setSortCol("timestamp");
|
||||||
return queryService.strQuery("audit-log-*", searchDto);
|
return queryService.strQuery("audit-log-*", searchDto);
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
package com.central.log.controller;
|
package com.central.log.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.search.client.service.IQueryService;
|
import com.central.search.client.service.IQueryService;
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -28,7 +28,7 @@ public class SlowQueryLogController {
|
|||||||
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
|
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
|
||||||
})
|
})
|
||||||
@GetMapping(value = "/slowQueryLog")
|
@GetMapping(value = "/slowQueryLog")
|
||||||
public PageResult<JSONObject> getPage(SearchDto searchDto) {
|
public PageResult<JsonNode> getPage(SearchDto searchDto) {
|
||||||
searchDto.setIsHighlighter(true);
|
searchDto.setIsHighlighter(true);
|
||||||
searchDto.setSortCol("timestamp");
|
searchDto.setSortCol("timestamp");
|
||||||
return queryService.strQuery("mysql-slowlog-*", searchDto);
|
return queryService.strQuery("mysql-slowlog-*", searchDto);
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
package com.central.log.controller;
|
package com.central.log.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.search.client.service.IQueryService;
|
import com.central.search.client.service.IQueryService;
|
||||||
import com.central.search.model.SearchDto;
|
import com.central.search.model.SearchDto;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -28,7 +28,7 @@ public class SysLogController {
|
|||||||
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
|
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
|
||||||
})
|
})
|
||||||
@GetMapping(value = "/sysLog")
|
@GetMapping(value = "/sysLog")
|
||||||
public PageResult<JSONObject> getPage(SearchDto searchDto) {
|
public PageResult<JsonNode> getPage(SearchDto searchDto) {
|
||||||
searchDto.setIsHighlighter(true);
|
searchDto.setIsHighlighter(true);
|
||||||
searchDto.setSortCol("timestamp");
|
searchDto.setSortCol("timestamp");
|
||||||
return queryService.strQuery("sys-log-*", searchDto);
|
return queryService.strQuery("sys-log-*", searchDto);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.central.oauth.handler;
|
package com.central.oauth.handler;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
|
import com.central.common.utils.JsonUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@@ -36,9 +36,9 @@ public class OauthLogoutSuccessHandler implements LogoutSuccessHandler {
|
|||||||
} else {
|
} else {
|
||||||
response.setStatus(HttpStatus.OK.value());
|
response.setStatus(HttpStatus.OK.value());
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
PrintWriter writer = response.getWriter();
|
PrintWriter writer = response.getWriter();
|
||||||
String jsonStr = JSON.toJSONString(Result.succeed("登出成功"));
|
String jsonStr = JsonUtil.toJSONString(Result.succeed("登出成功"));
|
||||||
writer.write(jsonStr);
|
writer.write(jsonStr);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.central.oauth2.common.util;
|
package com.central.oauth2.common.util;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
@@ -16,7 +16,7 @@ public class JwtUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
String jwtToken = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXN0IjoiYWJjIiwidXNlcl9uYW1lIjoiYWRtaW4iLCJzY29wZSI6WyJhcHAiXSwiZXhwIjoxNTYzNjgyMTI4LCJhdXRob3JpdGllcyI6WyJBRE1JTiJdLCJqdGkiOiJlMDFlNGU0Yi1hZDVkLTRlMTQtODhiMC00OGQ4YzBjN2U5YjkiLCJjbGllbnRfaWQiOiJ3ZWJBcHAifQ.Qrh2aEoN4TL_WIQ9UpxDrW12aqqoVqxeY826sjbea2LB24RBNDYQl1J5vwXzMaQlG9AgjHRL4bTQihwBYYfdL-VuJXx0_l0xONbz9sHPq60a3gAhxOnekNS5-Qet5feTw7j4o2OwNlxo-xty5s8u2lsQY21zCe0tes_T4XeM76JTBpRbQUFGUU3EKxtUFi3Nk9AII4zerW1AbQNvLo4YW2Wvj___0lq5a-xNdCcHlJid8vKgzEF3v3wECOv6OjgL-fUN8VpUsYVt1-_QZp8opPAf-t3OVTtrVIWrJZ_vWV9d6DN5mynKtZ7_mDyMwo_5w3roAZ0ahoBKPKrtYQyEwQ";
|
String jwtToken = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXN0IjoiYWJjIiwidXNlcl9uYW1lIjoiYWRtaW4iLCJzY29wZSI6WyJhcHAiXSwiZXhwIjoxNTYzNjgyMTI4LCJhdXRob3JpdGllcyI6WyJBRE1JTiJdLCJqdGkiOiJlMDFlNGU0Yi1hZDVkLTRlMTQtODhiMC00OGQ4YzBjN2U5YjkiLCJjbGllbnRfaWQiOiJ3ZWJBcHAifQ.Qrh2aEoN4TL_WIQ9UpxDrW12aqqoVqxeY826sjbea2LB24RBNDYQl1J5vwXzMaQlG9AgjHRL4bTQihwBYYfdL-VuJXx0_l0xONbz9sHPq60a3gAhxOnekNS5-Qet5feTw7j4o2OwNlxo-xty5s8u2lsQY21zCe0tes_T4XeM76JTBpRbQUFGUU3EKxtUFi3Nk9AII4zerW1AbQNvLo4YW2Wvj___0lq5a-xNdCcHlJid8vKgzEF3v3wECOv6OjgL-fUN8VpUsYVt1-_QZp8opPAf-t3OVTtrVIWrJZ_vWV9d6DN5mynKtZ7_mDyMwo_5w3roAZ0ahoBKPKrtYQyEwQ";
|
||||||
JSONObject claims = JwtUtils.decodeAndVerify(jwtToken);
|
JsonNode claims = JwtUtils.decodeAndVerify(jwtToken);
|
||||||
//token内容
|
//token内容
|
||||||
System.out.println(claims);
|
System.out.println(claims);
|
||||||
boolean isValid = JwtUtils.checkExp(claims);
|
boolean isValid = JwtUtils.checkExp(claims);
|
||||||
|
|||||||
Reference in New Issue
Block a user