Move table t_sys_log to sqlite
This commit is contained in:
@@ -34,6 +34,26 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!File("data/db").isDirectory) {
|
||||
if (!File("data/db").mkdir()) {
|
||||
logger.error("Can not create directory 'data/db', please try again later.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (!File("data/db/sqlite.db").isFile || File("data/db/sqlite.db").inputStream()
|
||||
.use { it.readNBytes(15).toString(Charsets.UTF_8) != "SQLite format 3" }
|
||||
) {
|
||||
logger.warn("The 'data/db/sqlite.db' database is lost or damaged, recreating...")
|
||||
if (File("data/db/sqlite.db").exists() && !File("data/db/sqlite.db").delete()) {
|
||||
logger.error("Can not recreate database 'data/db/sqlite.db', please try again later.")
|
||||
}
|
||||
|
||||
FatWebApiApplication::class.java.getResourceAsStream("/db/sqlite.db")?.let {
|
||||
File("data/db/sqlite.db").writeBytes(it.readAllBytes())
|
||||
}
|
||||
}
|
||||
|
||||
if (File("application-config.yml").exists() || File("data/application-config.yml").exists()) {
|
||||
runApplication<FatWebApiApplication>(*args)
|
||||
} else {
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.security.access.prepost.PreAuthorize
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import top.fatweb.api.converter.system.SysLogConverter
|
||||
import top.fatweb.api.entity.common.ResponseCode
|
||||
import top.fatweb.api.entity.common.ResponseResult
|
||||
import top.fatweb.api.param.system.SysLogGetParam
|
||||
@@ -44,9 +43,7 @@ class SysLogController(
|
||||
@PreAuthorize("hasAnyAuthority('system:log:query:all')")
|
||||
fun get(@Valid sysLogGetParam: SysLogGetParam?): ResponseResult<PageVo<SysLogVo>> {
|
||||
return ResponseResult.success(
|
||||
ResponseCode.DATABASE_SELECT_SUCCESS, data = SysLogConverter.sysLogPageToSysLogPageVo(
|
||||
sysLogService.getPage(sysLogGetParam)
|
||||
)
|
||||
ResponseCode.DATABASE_SELECT_SUCCESS, data = sysLogService.getPage(sysLogGetParam)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ interface SysLogMapper : BaseMapper<SysLog> {
|
||||
* @param logType List of log types
|
||||
* @param requestMethod List of request methods
|
||||
* @param searchRequestUrl Request URL to search for
|
||||
* @param searchRegex Use regex
|
||||
* @param searchStartTime Start time to search for
|
||||
* @param searchEndTime end time to search for
|
||||
* @return System log in page
|
||||
@@ -38,7 +37,6 @@ interface SysLogMapper : BaseMapper<SysLog> {
|
||||
logType: List<String>?,
|
||||
requestMethod: List<String>?,
|
||||
searchRequestUrl: String?,
|
||||
searchRegex: Boolean,
|
||||
searchStartTime: LocalDateTime?,
|
||||
searchEndTime: LocalDateTime?
|
||||
): IPage<SysLog>
|
||||
|
||||
@@ -51,8 +51,10 @@ data class SysLogGetParam(
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
/*
|
||||
@Schema(description = "查询使用正则表达式", allowableValues = ["true", "false"], defaultValue = "false")
|
||||
val searchRegex: Boolean = false,
|
||||
*/
|
||||
|
||||
/**
|
||||
* Start time to search for
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package top.fatweb.api.service.permission.impl
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem
|
||||
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
|
||||
import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper
|
||||
@@ -47,6 +48,7 @@ import java.time.ZoneOffset
|
||||
* @see User
|
||||
* @see IUserService
|
||||
*/
|
||||
@DS("master")
|
||||
@Service
|
||||
class UserServiceImpl(
|
||||
private val passwordEncoder: PasswordEncoder,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package top.fatweb.api.service.system
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage
|
||||
import com.baomidou.mybatisplus.extension.service.IService
|
||||
import top.fatweb.api.entity.system.SysLog
|
||||
import top.fatweb.api.param.system.SysLogGetParam
|
||||
import top.fatweb.api.vo.PageVo
|
||||
import top.fatweb.api.vo.system.SysLogVo
|
||||
|
||||
/**
|
||||
* System log service interface
|
||||
@@ -22,8 +23,8 @@ interface ISysLogService : IService<SysLog> {
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see SysLogGetParam
|
||||
* @see IPage
|
||||
* @see SysLog
|
||||
* @see PageVo
|
||||
* @see SysLogVo
|
||||
*/
|
||||
fun getPage(sysLogGetParam: SysLogGetParam?): IPage<SysLog>
|
||||
fun getPage(sysLogGetParam: SysLogGetParam?): PageVo<SysLogVo>
|
||||
}
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package top.fatweb.api.service.system.impl
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage
|
||||
import com.baomidou.dynamic.datasource.annotation.DS
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
||||
import org.springframework.stereotype.Service
|
||||
import top.fatweb.api.converter.system.SysLogConverter
|
||||
import top.fatweb.api.entity.system.SysLog
|
||||
import top.fatweb.api.mapper.system.SysLogMapper
|
||||
import top.fatweb.api.param.system.SysLogGetParam
|
||||
import top.fatweb.api.service.permission.IUserService
|
||||
import top.fatweb.api.service.system.ISysLogService
|
||||
import top.fatweb.api.util.PageUtil
|
||||
import top.fatweb.api.vo.PageVo
|
||||
import top.fatweb.api.vo.system.SysLogVo
|
||||
|
||||
/**
|
||||
* System log service implement
|
||||
@@ -21,21 +25,29 @@ import top.fatweb.api.util.PageUtil
|
||||
* @see SysLog
|
||||
* @see ISysLogService
|
||||
*/
|
||||
@DS("sqlite")
|
||||
@Service
|
||||
class SysLogServiceImpl : ServiceImpl<SysLogMapper, SysLog>(), ISysLogService {
|
||||
override fun getPage(sysLogGetParam: SysLogGetParam?): IPage<SysLog> {
|
||||
class SysLogServiceImpl(
|
||||
private val userService: IUserService
|
||||
) : ServiceImpl<SysLogMapper, SysLog>(), ISysLogService {
|
||||
override fun getPage(sysLogGetParam: SysLogGetParam?): PageVo<SysLogVo> {
|
||||
val sysLogPage = Page<SysLog>(sysLogGetParam?.currentPage ?: 1, sysLogGetParam?.pageSize ?: 20)
|
||||
|
||||
PageUtil.setPageSort(sysLogGetParam, sysLogPage, OrderItem.desc("start_time"))
|
||||
|
||||
return baseMapper.selectPage(
|
||||
val sysLogIPage = baseMapper.selectPage(
|
||||
sysLogPage,
|
||||
sysLogGetParam?.logType?.split(","),
|
||||
sysLogGetParam?.requestMethod?.split(","),
|
||||
sysLogGetParam?.searchRequestUrl,
|
||||
sysLogGetParam?.searchRegex ?: false,
|
||||
sysLogGetParam?.searchStartTime,
|
||||
sysLogGetParam?.searchEndTime
|
||||
)
|
||||
sysLogIPage.records.forEach {
|
||||
it.operateUsername =
|
||||
it.operateUserId?.let { it1 -> userService.getOne(it1)?.username }
|
||||
}
|
||||
|
||||
return SysLogConverter.sysLogPageToSysLogPageVo(sysLogIPage)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user