mirror of
https://github.com/chillzhuang/blade-tool
synced 2024-12-12 20:29:27 +08:00
⚡ 根据P3C优化代码
This commit is contained in:
parent
4b67b9a91f
commit
a623b387a5
@ -16,7 +16,7 @@
|
|||||||
package org.springblade.core.boot.file;
|
package org.springblade.core.boot.file;
|
||||||
|
|
||||||
import org.springblade.core.tool.constant.SystemConstant;
|
import org.springblade.core.tool.constant.SystemConstant;
|
||||||
import org.springblade.core.tool.date.DateUtil;
|
import org.springblade.core.tool.utils.DateUtil;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package org.springblade.core.boot.file;
|
package org.springblade.core.boot.file;
|
||||||
|
|
||||||
import org.springblade.core.tool.constant.SystemConstant;
|
import org.springblade.core.tool.constant.SystemConstant;
|
||||||
import org.springblade.core.tool.date.DateUtil;
|
import org.springblade.core.tool.utils.DateUtil;
|
||||||
import org.springblade.core.tool.utils.ImageUtil;
|
import org.springblade.core.tool.utils.ImageUtil;
|
||||||
import org.springblade.core.tool.utils.StringPool;
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import org.springblade.core.secure.exception.SecureException;
|
|||||||
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.api.R;
|
||||||
import org.springblade.core.tool.api.ResultCode;
|
import org.springblade.core.tool.api.ResultCode;
|
||||||
import org.springblade.core.tool.utils.Func;
|
import org.springblade.core.tool.utils.Func;
|
||||||
import org.springblade.core.tool.utils.URLUtil;
|
import org.springblade.core.tool.utils.UrlUtil;
|
||||||
import org.springblade.core.tool.utils.WebUtil;
|
import org.springblade.core.tool.utils.WebUtil;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
@ -155,7 +155,7 @@ public class BladeRestExceptionTranslator {
|
|||||||
public R handleError(Throwable e) {
|
public R handleError(Throwable e) {
|
||||||
log.error("服务器异常", e);
|
log.error("服务器异常", e);
|
||||||
//发送服务异常事件
|
//发送服务异常事件
|
||||||
ErrorLogPublisher.publishEvent(e, URLUtil.getPath(WebUtil.getRequest().getRequestURI()));
|
ErrorLogPublisher.publishEvent(e, UrlUtil.getPath(WebUtil.getRequest().getRequestURI()));
|
||||||
return R.failure(ResultCode.INTERNAL_SERVER_ERROR, (Func.isEmpty(e.getMessage()) ? ResultCode.INTERNAL_SERVER_ERROR.getMessage() : e.getMessage()));
|
return R.failure(ResultCode.INTERNAL_SERVER_ERROR, (Func.isEmpty(e.getMessage()) ? ResultCode.INTERNAL_SERVER_ERROR.getMessage() : e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import org.springblade.core.log.constant.EventConstant;
|
|||||||
import org.springblade.core.launch.props.BladeProperties;
|
import org.springblade.core.launch.props.BladeProperties;
|
||||||
import org.springblade.core.secure.utils.SecureUtil;
|
import org.springblade.core.secure.utils.SecureUtil;
|
||||||
import org.springblade.core.launch.server.ServerInfo;
|
import org.springblade.core.launch.server.ServerInfo;
|
||||||
import org.springblade.core.tool.utils.URLUtil;
|
import org.springblade.core.tool.utils.UrlUtil;
|
||||||
import org.springblade.core.tool.utils.WebUtil;
|
import org.springblade.core.tool.utils.WebUtil;
|
||||||
import org.springblade.core.log.feign.ILogClient;
|
import org.springblade.core.log.feign.ILogClient;
|
||||||
import org.springblade.core.log.model.LogApi;
|
import org.springblade.core.log.model.LogApi;
|
||||||
@ -64,7 +64,7 @@ public class ApiLogListener {
|
|||||||
logApi.setEnv(bladeProperties.getEnv());
|
logApi.setEnv(bladeProperties.getEnv());
|
||||||
logApi.setRemoteIp(WebUtil.getIP(request));
|
logApi.setRemoteIp(WebUtil.getIP(request));
|
||||||
logApi.setUserAgent(request.getHeader(WebUtil.USER_AGENT_HEADER));
|
logApi.setUserAgent(request.getHeader(WebUtil.USER_AGENT_HEADER));
|
||||||
logApi.setRequestUri(URLUtil.getPath(request.getRequestURI()));
|
logApi.setRequestUri(UrlUtil.getPath(request.getRequestURI()));
|
||||||
logApi.setMethod(request.getMethod());
|
logApi.setMethod(request.getMethod());
|
||||||
logApi.setParams(WebUtil.getRequestParamString(request));
|
logApi.setParams(WebUtil.getRequestParamString(request));
|
||||||
logApi.setCreateBy(SecureUtil.getUserAccount(request));
|
logApi.setCreateBy(SecureUtil.getUserAccount(request));
|
||||||
|
@ -24,7 +24,7 @@ import org.springblade.core.log.constant.EventConstant;
|
|||||||
import org.springblade.core.log.feign.ILogClient;
|
import org.springblade.core.log.feign.ILogClient;
|
||||||
import org.springblade.core.log.model.LogBlade;
|
import org.springblade.core.log.model.LogBlade;
|
||||||
import org.springblade.core.secure.utils.SecureUtil;
|
import org.springblade.core.secure.utils.SecureUtil;
|
||||||
import org.springblade.core.tool.utils.URLUtil;
|
import org.springblade.core.tool.utils.UrlUtil;
|
||||||
import org.springblade.core.tool.utils.WebUtil;
|
import org.springblade.core.tool.utils.WebUtil;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
@ -56,7 +56,7 @@ public class BladeLogListener {
|
|||||||
Map<String, Object> source = (Map<String, Object>) event.getSource();
|
Map<String, Object> source = (Map<String, Object>) event.getSource();
|
||||||
LogBlade logBlade = (LogBlade) source.get(EventConstant.EVENT_LOG);
|
LogBlade logBlade = (LogBlade) source.get(EventConstant.EVENT_LOG);
|
||||||
HttpServletRequest request = (HttpServletRequest) source.get(EventConstant.EVENT_REQUEST);
|
HttpServletRequest request = (HttpServletRequest) source.get(EventConstant.EVENT_REQUEST);
|
||||||
logBlade.setRequestUri(URLUtil.getPath(request.getRequestURI()));
|
logBlade.setRequestUri(UrlUtil.getPath(request.getRequestURI()));
|
||||||
logBlade.setUserAgent(request.getHeader(WebUtil.USER_AGENT_HEADER));
|
logBlade.setUserAgent(request.getHeader(WebUtil.USER_AGENT_HEADER));
|
||||||
logBlade.setMethod(request.getMethod());
|
logBlade.setMethod(request.getMethod());
|
||||||
logBlade.setParams(WebUtil.getRequestParamString(request));
|
logBlade.setParams(WebUtil.getRequestParamString(request));
|
||||||
|
@ -21,7 +21,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springblade.core.tool.date.DatePattern;
|
import org.springblade.core.tool.utils.DateUtil;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -113,8 +113,8 @@ public class LogApi implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springblade.core.tool.date.DatePattern;
|
import org.springblade.core.tool.utils.DateUtil;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -95,8 +95,8 @@ public class LogBlade implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springblade.core.tool.date.DatePattern;
|
import org.springblade.core.tool.utils.DateUtil;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ public class LogError implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springblade.core.tool.date.DatePattern;
|
import org.springblade.core.tool.utils.DateUtil;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -50,8 +50,8 @@ public class BaseEntity implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
@ApiModelProperty(value = "创建时间")
|
@ApiModelProperty(value = "创建时间")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
@ -64,8 +64,8 @@ public class BaseEntity implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 更新时间
|
* 更新时间
|
||||||
*/
|
*/
|
||||||
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
|
||||||
@ApiModelProperty(value = "更新时间")
|
@ApiModelProperty(value = "更新时间")
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ import com.fasterxml.jackson.core.JsonParser;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import org.springblade.core.tool.date.DatePattern;
|
|
||||||
import org.springblade.core.tool.jackson.BladeJavaTimeModule;
|
import org.springblade.core.tool.jackson.BladeJavaTimeModule;
|
||||||
|
import org.springblade.core.tool.utils.DateUtil;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||||
@ -47,7 +47,7 @@ public class JacksonConfiguration {
|
|||||||
@Primary
|
@Primary
|
||||||
@Bean
|
@Bean
|
||||||
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
|
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
|
||||||
builder.simpleDateFormat(DatePattern.NORM_DATETIME_PATTERN);
|
builder.simpleDateFormat(DateUtil.PATTERN_DATETIME);
|
||||||
//创建ObjectMapper
|
//创建ObjectMapper
|
||||||
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
||||||
//设置地点为中国
|
//设置地点为中国
|
||||||
@ -57,7 +57,7 @@ public class JacksonConfiguration {
|
|||||||
//设置为中国上海时区
|
//设置为中国上海时区
|
||||||
objectMapper.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
|
objectMapper.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
|
||||||
//序列化时,日期的统一格式
|
//序列化时,日期的统一格式
|
||||||
objectMapper.setDateFormat(new SimpleDateFormat(DatePattern.NORM_DATETIME_PATTERN, Locale.CHINA));
|
objectMapper.setDateFormat(new SimpleDateFormat(DateUtil.PATTERN_DATETIME, Locale.CHINA));
|
||||||
//序列化处理
|
//序列化处理
|
||||||
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
|
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
|
||||||
objectMapper.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
|
objectMapper.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
|
||||||
|
@ -54,7 +54,7 @@ public class PathUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String protocol = url.getProtocol();
|
String protocol = url.getProtocol();
|
||||||
String file = URLUtil.decodeURL(url.getPath(), Charsets.UTF_8);
|
String file = UrlUtil.decodeURL(url.getPath(), Charsets.UTF_8);
|
||||||
if (FILE_PROTOCOL.equals(protocol)) {
|
if (FILE_PROTOCOL.equals(protocol)) {
|
||||||
return new File(file).getParentFile().getParentFile().getAbsolutePath();
|
return new File(file).getParentFile().getParentFile().getAbsolutePath();
|
||||||
} else if (JAR_PROTOCOL.equals(protocol) || ZIP_PROTOCOL.equals(protocol)) {
|
} else if (JAR_PROTOCOL.equals(protocol) || ZIP_PROTOCOL.equals(protocol)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user