Optimize code

This commit is contained in:
2024-01-03 18:48:33 +08:00
parent af134f04e0
commit f3b63ce17d
5 changed files with 30 additions and 29 deletions

View File

@@ -14,13 +14,13 @@ import java.time.format.DateTimeFormatter
import java.util.* import java.util.*
/** /**
* Data format configuration * Date format configuration
* *
* @author FatttSnake, fatttsnake@gmail.com * @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0 * @since 1.0.0
*/ */
@JsonComponent @JsonComponent
class DataFormatConfig { class DateFormatConfig {
/** /**
* The format of the time in response when request APIs * The format of the time in response when request APIs
* *
@@ -28,7 +28,7 @@ class DataFormatConfig {
* @since 1.0.0 * @since 1.0.0
*/ */
@set:Value("\${spring.jackson.date-format}") @set:Value("\${spring.jackson.date-format}")
lateinit var dataFormat: String lateinit var dateFormat: String
/** /**
* The timezone of the time in response when request APIs * The timezone of the time in response when request APIs
@@ -43,7 +43,7 @@ class DataFormatConfig {
@Bean @Bean
fun jackson2ObjectMapperBuilder() = Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder -> fun jackson2ObjectMapperBuilder() = Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder ->
val tz = timeZone val tz = timeZone
val df: DateFormat = SimpleDateFormat(dataFormat) val df: DateFormat = SimpleDateFormat(dateFormat)
df.timeZone = tz df.timeZone = tz
builder.failOnEmptyBeans(false).failOnUnknownProperties(false) builder.failOnEmptyBeans(false).failOnUnknownProperties(false)
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).dateFormat(df) .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).dateFormat(df)
@@ -53,7 +53,7 @@ class DataFormatConfig {
fun jackson2ObjectMapperBuilderCustomizer() = fun jackson2ObjectMapperBuilderCustomizer() =
Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder -> Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder ->
builder.serializerByType( builder.serializerByType(
LocalDateTime::class.java, LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dataFormat)) LocalDateTime::class.java, LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateFormat))
) )
} }

View File

@@ -14,6 +14,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException
import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.MethodArgumentNotValidException
import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.servlet.resource.NoResourceFoundException
import top.fatweb.avatargenerator.AvatarException import top.fatweb.avatargenerator.AvatarException
import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseCode
import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.entity.common.ResponseResult
@@ -42,7 +43,7 @@ class ExceptionHandler {
@ExceptionHandler(value = [Exception::class]) @ExceptionHandler(value = [Exception::class])
fun exceptionHandler(e: Exception): ResponseResult<*> { fun exceptionHandler(e: Exception): ResponseResult<*> {
return when (e) { return when (e) {
is HttpRequestMethodNotSupportedException -> { is HttpRequestMethodNotSupportedException, is NoResourceFoundException -> {
logger.debug(e.localizedMessage, e) logger.debug(e.localizedMessage, e)
ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage, null) ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage, null)
} }

View File

@@ -2,19 +2,19 @@ drop table if exists t_sys_log;
create table t_sys_log -- 系统日志表 create table t_sys_log -- 系统日志表
( (
id bigint not null, id integer not null,
log_type varchar(50) not null, -- 日志类型 log_type text not null, -- 日志类型
operate_user_id bigint not null, -- 操作用户 operate_user_id integer not null, -- 操作用户
operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')), -- 操作时间 operate_time text not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')), -- 操作时间
request_uri varchar(500) default null, -- 请求 URI request_uri text default null, -- 请求 URI
request_method varchar(10) default null, -- 请求方式 request_method text default null, -- 请求方式
request_params text, -- 请求参数 request_params text, -- 请求参数
request_ip varchar(20) not null, -- 请求 IP request_ip text not null, -- 请求 IP
request_server_address varchar(50) not null, -- 请求服务器地址 request_server_address text not null, -- 请求服务器地址
exception int not null default 0, -- 是否异常 exception integer not null default 0, -- 是否异常
exception_info text, -- 异常信息 exception_info text, -- 异常信息
start_time datetime not null, -- 开始时间 start_time text not null, -- 开始时间
end_time datetime not null, -- 结束时间 end_time text not null, -- 结束时间
execute_time bigint default null, -- 执行时间 execute_time integer default null, -- 执行时间
user_agent varchar(500) default null -- 用户代理 user_agent text default null -- 用户代理
); );

View File

@@ -2,8 +2,8 @@ drop table if exists t_event_log;
create table if not exists t_event_log -- 事件日志表 create table if not exists t_event_log -- 事件日志表
( (
id bigint not null primary key, id integer not null primary key,
event varchar(50) not null, -- 事件, event text not null, -- 事件,
operate_user_id bigint not null, -- 操作用户 operate_user_id integer not null, -- 操作用户
operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')) -- 操作时间 operate_time text not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')) -- 操作时间
); );

View File

@@ -2,8 +2,8 @@ drop table if exists t_statistics_log;
create table if not exists t_statistics_log -- 统计日志表 create table if not exists t_statistics_log -- 统计日志表
( (
id bigint not null primary key, id integer not null primary key,
key varchar(50) not null, -- 记录键 key text not null, -- 记录键
value varchar(100) not null, -- 记录值 value text not null, -- 记录值
record_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')) -- 记录时间 record_time text not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')) -- 记录时间
) )