refactor: 根据 Sonar 建议调整,StrUtil => CharSequenceUtil

工具层调整以减少 Sonar 建议,应用层则可忽略,怎么用方便怎么来
This commit is contained in:
2024-02-07 17:48:32 +08:00
parent 00bba33517
commit ea71cf573b
26 changed files with 117 additions and 114 deletions

View File

@@ -16,7 +16,7 @@
package top.charles7c.continew.starter.log.common.model;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.text.CharSequenceUtil;
import org.springframework.http.HttpHeaders;
import top.charles7c.continew.starter.core.util.IpUtils;
import top.charles7c.continew.starter.log.common.enums.Include;
@@ -99,7 +99,7 @@ public class LogRequest {
.map(Map.Entry::getValue)
.findFirst()
.orElse(null);
if (StrUtil.isNotBlank(userAgentString)) {
if (CharSequenceUtil.isNotBlank(userAgentString)) {
this.browser = (includes.contains(Include.BROWSER)) ? ServletUtils.getBrowser(userAgentString) : null;
this.os = (includes.contains(Include.OS)) ? ServletUtils.getOs(userAgentString) : null;
}

View File

@@ -16,7 +16,7 @@
package top.charles7c.continew.starter.log.httptracepro.handler;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.ttl.TransmittableThreadLocal;
import io.swagger.v3.oas.annotations.Hidden;
@@ -153,14 +153,14 @@ public class LogInterceptor implements HandlerInterceptor {
*/
private void logDescription(LogRecord logRecord, Log methodLog, HandlerMethod handlerMethod) {
// 例如:@Log("新增部门") -> 新增部门
if (null != methodLog && StrUtil.isNotBlank(methodLog.value())) {
if (null != methodLog && CharSequenceUtil.isNotBlank(methodLog.value())) {
logRecord.setDescription(methodLog.value());
return;
}
// 例如:@Operation(summary="新增部门") -> 新增部门
Operation methodOperation = handlerMethod.getMethodAnnotation(Operation.class);
if (null != methodOperation) {
logRecord.setDescription(StrUtil.blankToDefault(methodOperation.summary(), "请在该接口方法上指定日志描述"));
logRecord.setDescription(CharSequenceUtil.blankToDefault(methodOperation.summary(), "请在该接口方法上指定日志描述"));
}
}
@@ -174,11 +174,11 @@ public class LogInterceptor implements HandlerInterceptor {
*/
private void logModule(LogRecord logRecord, Log methodLog, Log classLog, HandlerMethod handlerMethod) {
// 例如:@Log(module = "部门管理") -> 部门管理
if (null != methodLog && StrUtil.isNotBlank(methodLog.module())) {
if (null != methodLog && CharSequenceUtil.isNotBlank(methodLog.module())) {
logRecord.setModule(methodLog.module());
return;
}
if (null != classLog && StrUtil.isNotBlank(classLog.module())) {
if (null != classLog && CharSequenceUtil.isNotBlank(classLog.module())) {
logRecord.setModule(classLog.module());
return;
}
@@ -186,7 +186,7 @@ public class LogInterceptor implements HandlerInterceptor {
Tag classTag = handlerMethod.getBeanType().getDeclaredAnnotation(Tag.class);
if (null != classTag) {
String name = classTag.name();
logRecord.setModule(StrUtil.blankToDefault(name, "请在该接口类上指定所属模块"));
logRecord.setModule(CharSequenceUtil.blankToDefault(name, "请在该接口类上指定所属模块"));
}
}

View File

@@ -16,6 +16,7 @@
package top.charles7c.continew.starter.log.httptracepro.handler;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.JakartaServletUtil;
import cn.hutool.json.JSONUtil;
@@ -53,7 +54,7 @@ public final class RecordableServletHttpRequest implements RecordableHttpRequest
@Override
public URI getUrl() {
String queryString = request.getQueryString();
if (StrUtil.isBlank(queryString)) {
if (CharSequenceUtil.isBlank(queryString)) {
return URI.create(request.getRequestURL().toString());
}
try {
@@ -89,7 +90,7 @@ public final class RecordableServletHttpRequest implements RecordableHttpRequest
@Override
public Map<String, Object> getParam() {
String body = this.getBody();
return StrUtil.isNotBlank(body) && JSONUtil.isTypeJSON(body)
return CharSequenceUtil.isNotBlank(body) && JSONUtil.isTypeJSON(body)
? JSONUtil.toBean(body, Map.class)
: Collections.unmodifiableMap(request.getParameterMap());
}

View File

@@ -16,6 +16,7 @@
package top.charles7c.continew.starter.log.httptracepro.handler;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import jakarta.servlet.http.HttpServletResponse;
@@ -67,6 +68,6 @@ public final class RecordableServletHttpResponse implements RecordableHttpRespon
@Override
public Map<String, Object> getParam() {
String body = this.getBody();
return StrUtil.isNotBlank(body) && JSONUtil.isTypeJSON(body) ? JSONUtil.toBean(body, Map.class) : null;
return CharSequenceUtil.isNotBlank(body) && JSONUtil.isTypeJSON(body) ? JSONUtil.toBean(body, Map.class) : null;
}
}