Complete core functions #9

Merged
FatttSnake merged 171 commits from FatttSnake into dev 2024-02-23 11:56:35 +08:00
4 changed files with 29 additions and 12 deletions
Showing only changes of commit c2e5248aa0 - Show all commits

View File

@@ -1,9 +1,11 @@
package top.fatweb.api.entity.system
import com.baomidou.mybatisplus.annotation.EnumValue
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonValue
import java.io.Serializable
import java.time.LocalDateTime
@@ -15,6 +17,18 @@ import java.time.LocalDateTime
*/
@TableName("t_sys_log")
class SysLog : Serializable {
/**
* Log type enum
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
enum class LogType(@field:EnumValue @field:JsonValue val code: String) {
INFO("INFO"), ERROR("ERROR"), LOGIN("LOGIN"), LOGOUT("LOGOUT"), REGISTER("REGISTER"), STATISTIC("STATISTIC"), API(
"API"
)
}
/**
* ID
*
@@ -29,9 +43,10 @@ class SysLog : Serializable {
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see LogType
*/
@TableField("log_type")
var logType: String? = null
var logType: LogType? = null
/**
* Operate user ID

View File

@@ -2,6 +2,7 @@ package top.fatweb.api.interceptor
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.core.MethodParameter
import org.springframework.http.MediaType
import org.springframework.http.converter.HttpMessageConverter
@@ -32,7 +33,7 @@ import java.util.concurrent.Executor
*/
@ControllerAdvice
class SysLogInterceptor(
private val customThreadPoolTaskExecutor: Executor, private val sysLogService: ISysLogService
@Qualifier("applicationTaskExecutor") private val customThreadPoolTaskExecutor: Executor, private val sysLogService: ISysLogService
) : HandlerInterceptor, ResponseBodyAdvice<Any> {
private val sysLogThreadLocal = ThreadLocal<SysLog>()
private val resultThreadLocal = ThreadLocal<Any>()
@@ -66,19 +67,19 @@ class SysLogInterceptor(
sysLog.apply {
logType = requestUri?.let {
when {
it.startsWith("/login") -> "LOGIN"
it.startsWith("/logout") -> "LOGOUT"
it.startsWith("/register") -> "REGISTER"
it.startsWith("/system/statistic/") -> "STATISTIC"
it.startsWith("/api/") -> "API"
else -> "INFO"
it.startsWith("/login") -> SysLog.LogType.LOGIN
it.startsWith("/logout") -> SysLog.LogType.LOGOUT
it.startsWith("/register") -> SysLog.LogType.REGISTER
it.startsWith("/system/statistic/") -> SysLog.LogType.STATISTIC
it.startsWith("/api/") -> SysLog.LogType.API
else -> SysLog.LogType.INFO
}
} ?: "INFO"
} ?: SysLog.LogType.INFO
exception = 0
}
} else {
sysLog.apply {
logType = "ERROR"
logType = SysLog.LogType.ERROR
exception = 1
exceptionInfo = result.msg
}

View File

@@ -10,7 +10,7 @@ enum class MailSecurityType(val code: String) {
@JsonCreator
fun fromCode(code: String): MailSecurityType? {
values().forEach {
entries.forEach {
if (it.code == code) {
return it
}

View File

@@ -3,6 +3,7 @@ package top.fatweb.api.vo.system
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
import io.swagger.v3.oas.annotations.media.Schema
import top.fatweb.api.entity.system.SysLog
import java.time.LocalDateTime
/**
@@ -29,7 +30,7 @@ data class SysLogVo(
* @since 1.0.0
*/
@Schema(description = "日志类型")
val logType: String?,
val logType: SysLog.LogType?,
/**
* Operate user ID