mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-13 05:12:07 +08:00
1、sonarqube质量修复;2、短信模板增删查询移除短信渠道相关内容;
This commit is contained in:
+38
-30
@@ -64,41 +64,49 @@ public class HttpUtils {
|
||||
.userInfo(redirectUri.getUserInfo()).path(redirectUri.getPath());
|
||||
|
||||
if (fragment) {
|
||||
StringBuilder values = new StringBuilder();
|
||||
if (redirectUri.getFragment() != null) {
|
||||
String append = redirectUri.getFragment();
|
||||
values.append(append);
|
||||
}
|
||||
for (String key : query.keySet()) {
|
||||
if (values.length() > 0) {
|
||||
values.append("&");
|
||||
}
|
||||
String name = key;
|
||||
if (keys != null && keys.containsKey(key)) {
|
||||
name = keys.get(key);
|
||||
}
|
||||
values.append(name).append("={").append(key).append("}");
|
||||
}
|
||||
if (values.length() > 0) {
|
||||
template.fragment(values.toString());
|
||||
}
|
||||
UriComponents encoded = template.build().expand(query).encode();
|
||||
builder.fragment(encoded.getFragment());
|
||||
buildFragmentUri(template, builder, redirectUri, query, keys);
|
||||
} else {
|
||||
for (String key : query.keySet()) {
|
||||
String name = key;
|
||||
if (keys != null && keys.containsKey(key)) {
|
||||
name = keys.get(key);
|
||||
}
|
||||
template.queryParam(name, "{" + key + "}");
|
||||
}
|
||||
template.fragment(redirectUri.getFragment());
|
||||
UriComponents encoded = template.build().expand(query).encode();
|
||||
builder.query(encoded.getQuery());
|
||||
buildUri(template, builder, redirectUri, query, keys);
|
||||
}
|
||||
return builder.build().toUriString();
|
||||
}
|
||||
|
||||
private static void buildUri(UriComponentsBuilder template, UriComponentsBuilder builder, URI redirectUri, Map<String, ?> query, Map<String, String> keys) {
|
||||
for (String key : query.keySet()) {
|
||||
String name = key;
|
||||
if (keys != null && keys.containsKey(key)) {
|
||||
name = keys.get(key);
|
||||
}
|
||||
template.queryParam(name, "{" + key + "}");
|
||||
}
|
||||
template.fragment(redirectUri.getFragment());
|
||||
UriComponents encoded = template.build().expand(query).encode();
|
||||
builder.query(encoded.getQuery());
|
||||
}
|
||||
|
||||
private static void buildFragmentUri(UriComponentsBuilder template, UriComponentsBuilder builder, URI redirectUri, Map<String, ?> query, Map<String, String> keys) {
|
||||
StringBuilder values = new StringBuilder();
|
||||
if (redirectUri.getFragment() != null) {
|
||||
String append = redirectUri.getFragment();
|
||||
values.append(append);
|
||||
}
|
||||
for (String key : query.keySet()) {
|
||||
if (values.length() > 0) {
|
||||
values.append("&");
|
||||
}
|
||||
String name = key;
|
||||
if (keys != null && keys.containsKey(key)) {
|
||||
name = keys.get(key);
|
||||
}
|
||||
values.append(name).append("={").append(key).append("}");
|
||||
}
|
||||
if (values.length() > 0) {
|
||||
template.fragment(values.toString());
|
||||
}
|
||||
UriComponents encoded = template.build().expand(query).encode();
|
||||
builder.fragment(encoded.getFragment());
|
||||
}
|
||||
|
||||
public static String[] obtainBasicAuthorization(HttpServletRequest request) {
|
||||
String clientId;
|
||||
String clientSecret;
|
||||
|
||||
+30
-18
@@ -303,24 +303,7 @@ public class JsonUtils {
|
||||
for (JsonNode jsonObject : jsonArray) {
|
||||
List<Object> row = new ArrayList<>();
|
||||
for (String header : headers) {
|
||||
JsonNode valueNode = jsonObject.get(header);
|
||||
if (valueNode != null) {
|
||||
if (valueNode.isTextual()) {
|
||||
row.add(valueNode.asText());
|
||||
} else if (valueNode.isInt()) {
|
||||
row.add(valueNode.asInt());
|
||||
} else if (valueNode.isBoolean()) {
|
||||
row.add(valueNode.asBoolean());
|
||||
} else if (valueNode.isDouble()) {
|
||||
row.add(valueNode.asDouble());
|
||||
} else if (valueNode.isArray() || valueNode.isObject() ) {
|
||||
row.add(jsonTo2DArray(valueNode.toString()));
|
||||
} else {
|
||||
row.add(valueNode.asText());
|
||||
}
|
||||
} else {
|
||||
row.add(null); // 处理缺少的值
|
||||
}
|
||||
getRow(jsonObject, header, row);
|
||||
}
|
||||
result.add(row);
|
||||
}
|
||||
@@ -332,6 +315,35 @@ public class JsonUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取行
|
||||
*
|
||||
* @param jsonObject
|
||||
* @param header
|
||||
* @param row
|
||||
* @return
|
||||
*/
|
||||
private static void getRow(JsonNode jsonObject, String header, List<Object> row) {
|
||||
JsonNode valueNode = jsonObject.get(header);
|
||||
if (valueNode != null) {
|
||||
if (valueNode.isTextual()) {
|
||||
row.add(valueNode.asText());
|
||||
} else if (valueNode.isInt()) {
|
||||
row.add(valueNode.asInt());
|
||||
} else if (valueNode.isBoolean()) {
|
||||
row.add(valueNode.asBoolean());
|
||||
} else if (valueNode.isDouble()) {
|
||||
row.add(valueNode.asDouble());
|
||||
} else if (valueNode.isArray() || valueNode.isObject()) {
|
||||
row.add(jsonTo2DArray(valueNode.toString()));
|
||||
} else {
|
||||
row.add(valueNode.asText());
|
||||
}
|
||||
} else {
|
||||
row.add(null); // 处理缺少的值
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 抽取 json数据,不改变数据结构对应的值,只改变数据结构(参考 HPACK 算法) 实现json数据抽取
|
||||
public static List<List<Object>> getData(Object object) {
|
||||
|
||||
+3
-1
@@ -2,6 +2,8 @@ package com.cf.imes.framework.file.core.client;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 文件客户端的配置
|
||||
* 不同实现的客户端,需要不同的配置,通过子类来定义
|
||||
@@ -12,5 +14,5 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
// @JsonTypeInfo 注解的作用,Jackson 多态
|
||||
// 1. 序列化到时数据库时,增加 @class 属性。
|
||||
// 2. 反序列化到内存对象时,通过 @class 属性,可以创建出正确的类型
|
||||
public interface FileClientConfig {
|
||||
public interface FileClientConfig extends Serializable {
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class ChenfengRedisAutoConfiguration {
|
||||
return template;
|
||||
}
|
||||
|
||||
public static RedisSerializer<?> buildRedisSerializer() {
|
||||
public static RedisSerializer buildRedisSerializer() {
|
||||
RedisSerializer<Object> json = RedisSerializer.json();
|
||||
// 解决 LocalDateTime 的序列化
|
||||
ObjectMapper objectMapper = (ObjectMapper) ReflectUtil.getFieldValue(json, "mapper");
|
||||
|
||||
+17
-17
@@ -59,7 +59,7 @@ public class GlobalExceptionHandler {
|
||||
* @param ex 异常
|
||||
* @return 通用返回
|
||||
*/
|
||||
public CommonResult<?> allExceptionHandler(HttpServletRequest request, Throwable ex) {
|
||||
public CommonResult allExceptionHandler(HttpServletRequest request, Throwable ex) {
|
||||
if (ex instanceof MissingServletRequestParameterException) {
|
||||
return missingServletRequestParameterExceptionHandler((MissingServletRequestParameterException) ex);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class GlobalExceptionHandler {
|
||||
* 例如说,接口上设置了 @RequestParam("xx") 参数,结果并未传递 xx 参数
|
||||
*/
|
||||
@ExceptionHandler(value = MissingServletRequestParameterException.class)
|
||||
public CommonResult<?> missingServletRequestParameterExceptionHandler(MissingServletRequestParameterException ex) {
|
||||
public CommonResult missingServletRequestParameterExceptionHandler(MissingServletRequestParameterException ex) {
|
||||
log.warn("[missingServletRequestParameterExceptionHandler]", ex);
|
||||
return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数缺失:%s", ex.getParameterName()));
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class GlobalExceptionHandler {
|
||||
* 例如说,接口上设置了 @RequestParam("xx") 参数为 Integer,结果传递 xx 参数类型为 String
|
||||
*/
|
||||
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
||||
public CommonResult<?> methodArgumentTypeMismatchExceptionHandler(MethodArgumentTypeMismatchException ex) {
|
||||
public CommonResult methodArgumentTypeMismatchExceptionHandler(MethodArgumentTypeMismatchException ex) {
|
||||
log.warn("[missingServletRequestParameterExceptionHandler]", ex);
|
||||
return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数类型错误:%s", ex.getMessage()));
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class GlobalExceptionHandler {
|
||||
* 处理 SpringMVC 参数校验不正确
|
||||
*/
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public CommonResult<?> methodArgumentNotValidExceptionExceptionHandler(MethodArgumentNotValidException ex) {
|
||||
public CommonResult methodArgumentNotValidExceptionExceptionHandler(MethodArgumentNotValidException ex) {
|
||||
log.warn("[methodArgumentNotValidExceptionExceptionHandler]", ex);
|
||||
FieldError fieldError = ex.getBindingResult().getFieldError();
|
||||
assert fieldError != null; // 断言,避免告警
|
||||
@@ -131,7 +131,7 @@ public class GlobalExceptionHandler {
|
||||
* 处理 SpringMVC 参数绑定不正确,本质上也是通过 Validator 校验
|
||||
*/
|
||||
@ExceptionHandler(BindException.class)
|
||||
public CommonResult<?> bindExceptionHandler(BindException ex) {
|
||||
public CommonResult bindExceptionHandler(BindException ex) {
|
||||
log.warn("[handleBindException]", ex);
|
||||
FieldError fieldError = ex.getFieldError();
|
||||
assert fieldError != null; // 断言,避免告警
|
||||
@@ -142,9 +142,9 @@ public class GlobalExceptionHandler {
|
||||
* 处理 Validator 校验不通过产生的异常
|
||||
*/
|
||||
@ExceptionHandler(value = ConstraintViolationException.class)
|
||||
public CommonResult<?> constraintViolationExceptionHandler(ConstraintViolationException ex) {
|
||||
public CommonResult constraintViolationExceptionHandler(ConstraintViolationException ex) {
|
||||
log.warn("[constraintViolationExceptionHandler]", ex);
|
||||
ConstraintViolation<?> constraintViolation = ex.getConstraintViolations().iterator().next();
|
||||
ConstraintViolation constraintViolation = ex.getConstraintViolations().iterator().next();
|
||||
return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数不正确:%s", constraintViolation.getMessage()));
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class GlobalExceptionHandler {
|
||||
* 处理 Dubbo Consumer 本地参数校验时,抛出的 ValidationException 异常
|
||||
*/
|
||||
@ExceptionHandler(value = ValidationException.class)
|
||||
public CommonResult<?> validationException(ValidationException ex) {
|
||||
public CommonResult validationException(ValidationException ex) {
|
||||
log.warn("[constraintViolationExceptionHandler]", ex);
|
||||
// 无法拼接明细的错误信息,因为 Dubbo Consumer 抛出 ValidationException 异常时,是直接的字符串信息,且人类不可读
|
||||
return CommonResult.error(BAD_REQUEST);
|
||||
@@ -166,7 +166,7 @@ public class GlobalExceptionHandler {
|
||||
* 2. spring.mvc.static-path-pattern 为 /statics/**
|
||||
*/
|
||||
@ExceptionHandler(NoHandlerFoundException.class)
|
||||
public CommonResult<?> noHandlerFoundExceptionHandler(NoHandlerFoundException ex) {
|
||||
public CommonResult noHandlerFoundExceptionHandler(NoHandlerFoundException ex) {
|
||||
log.warn("[noHandlerFoundExceptionHandler]", ex);
|
||||
return CommonResult.error(NOT_FOUND.getCode(), String.format("请求地址不存在:%s", ex.getRequestURL()));
|
||||
}
|
||||
@@ -177,7 +177,7 @@ public class GlobalExceptionHandler {
|
||||
* 例如说,A 接口的方法为 GET 方式,结果请求方法为 POST 方式,导致不匹配
|
||||
*/
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public CommonResult<?> httpRequestMethodNotSupportedExceptionHandler(HttpRequestMethodNotSupportedException ex) {
|
||||
public CommonResult httpRequestMethodNotSupportedExceptionHandler(HttpRequestMethodNotSupportedException ex) {
|
||||
log.warn("[httpRequestMethodNotSupportedExceptionHandler]", ex);
|
||||
return CommonResult.error(METHOD_NOT_ALLOWED.getCode(), String.format("请求方法不正确:%s", ex.getMessage()));
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public class GlobalExceptionHandler {
|
||||
/**
|
||||
* 处理 Resilience4j 限流抛出的异常
|
||||
*/
|
||||
public CommonResult<?> requestNotPermittedExceptionHandler(HttpServletRequest req, Throwable ex) {
|
||||
public CommonResult requestNotPermittedExceptionHandler(HttpServletRequest req, Throwable ex) {
|
||||
log.warn("[requestNotPermittedExceptionHandler][url({}) 访问过于频繁]", req.getRequestURL(), ex);
|
||||
return CommonResult.error(TOO_MANY_REQUESTS);
|
||||
}
|
||||
@@ -196,7 +196,7 @@ public class GlobalExceptionHandler {
|
||||
* 来源是,使用 @PreAuthorize 注解,AOP 进行权限拦截
|
||||
*/
|
||||
@ExceptionHandler(value = AccessDeniedException.class)
|
||||
public CommonResult<?> accessDeniedExceptionHandler(HttpServletRequest req, AccessDeniedException ex) {
|
||||
public CommonResult accessDeniedExceptionHandler(HttpServletRequest req, AccessDeniedException ex) {
|
||||
log.warn("[accessDeniedExceptionHandler][userId({}) 无法访问 url({})]", WebFrameworkUtils.getLoginUserId(req),
|
||||
req.getRequestURL(), ex);
|
||||
return CommonResult.error(FORBIDDEN);
|
||||
@@ -208,7 +208,7 @@ public class GlobalExceptionHandler {
|
||||
* 例如说,商品库存不足,用户手机号已存在。
|
||||
*/
|
||||
@ExceptionHandler(value = ServiceException.class)
|
||||
public CommonResult<?> serviceExceptionHandler(ServiceException ex) {
|
||||
public CommonResult serviceExceptionHandler(ServiceException ex) {
|
||||
log.info("[serviceExceptionHandler]", ex);
|
||||
return CommonResult.error(ex.getCode(), ex.getMessage());
|
||||
}
|
||||
@@ -220,7 +220,7 @@ public class GlobalExceptionHandler {
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(value = DuplicateKeyException.class)
|
||||
public CommonResult<?> duplicateKeyExceptionHandler(DuplicateKeyException ex) {
|
||||
public CommonResult duplicateKeyExceptionHandler(DuplicateKeyException ex) {
|
||||
log.info("[duplicateKeyExceptionHandler]", ex);
|
||||
return CommonResult.error(INTERNAL_SERVER_ERROR.getCode(), "请求数据已存在,请检查");
|
||||
}
|
||||
@@ -229,9 +229,9 @@ public class GlobalExceptionHandler {
|
||||
* 处理系统异常,兜底处理所有的一切
|
||||
*/
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public CommonResult<?> defaultExceptionHandler(HttpServletRequest req, Throwable ex) {
|
||||
public CommonResult defaultExceptionHandler(HttpServletRequest req, Throwable ex) {
|
||||
// 情况一:处理表不存在的异常
|
||||
CommonResult<?> tableNotExistsResult = handleTableNotExists(ex);
|
||||
CommonResult tableNotExistsResult = handleTableNotExists(ex);
|
||||
if (tableNotExistsResult != null) {
|
||||
return tableNotExistsResult;
|
||||
}
|
||||
@@ -306,7 +306,7 @@ public class GlobalExceptionHandler {
|
||||
* @param ex 异常
|
||||
* @return 如果是 Table 不存在的异常,则返回对应的 CommonResult
|
||||
*/
|
||||
private CommonResult<?> handleTableNotExists(Throwable ex) {
|
||||
private CommonResult handleTableNotExists(Throwable ex) {
|
||||
String message = ExceptionUtil.getRootCauseMessage(ex);
|
||||
if (!message.contains("doesn't exist")) {
|
||||
return null;
|
||||
|
||||
+2
-2
@@ -155,8 +155,8 @@ public class WebFrameworkUtils {
|
||||
request.setAttribute(REQUEST_ATTRIBUTE_COMMON_RESULT, result);
|
||||
}
|
||||
|
||||
public static CommonResult<?> getCommonResult(ServletRequest request) {
|
||||
return (CommonResult<?>) request.getAttribute(REQUEST_ATTRIBUTE_COMMON_RESULT);
|
||||
public static CommonResult getCommonResult(ServletRequest request) {
|
||||
return (CommonResult) request.getAttribute(REQUEST_ATTRIBUTE_COMMON_RESULT);
|
||||
}
|
||||
|
||||
public static HttpServletRequest getRequest() {
|
||||
|
||||
Reference in New Issue
Block a user