Finish SysLogController

This commit is contained in:
2023-11-09 15:27:07 +08:00
parent 0ff2698f33
commit 65ddc644fb
4 changed files with 53 additions and 4 deletions

View File

@@ -1,9 +1,10 @@
package top.fatweb.api.mapper.system package top.fatweb.api.mapper.system
import top.fatweb.api.entity.system.SysLog
import com.baomidou.mybatisplus.core.mapper.BaseMapper import com.baomidou.mybatisplus.core.mapper.BaseMapper
import com.baomidou.mybatisplus.core.metadata.IPage import com.baomidou.mybatisplus.core.metadata.IPage
import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Mapper
import top.fatweb.api.entity.system.SysLog
import java.time.LocalDateTime
/** /**
* <p> * <p>
@@ -15,5 +16,13 @@ import org.apache.ibatis.annotations.Mapper
*/ */
@Mapper @Mapper
interface SysLogMapper : BaseMapper<SysLog> { interface SysLogMapper : BaseMapper<SysLog> {
fun selectPage(page: IPage<SysLog>, logType: List<String>?, requestMethod: List<String>?): IPage<SysLog> fun selectPage(
page: IPage<SysLog>,
logType: List<String>?,
requestMethod: List<String>?,
searchRequestUrl: String?,
searchRegex: Boolean,
searchStartTime: LocalDateTime?,
searchEndTime: LocalDateTime?
): IPage<SysLog>
} }

View File

@@ -1,7 +1,9 @@
package top.fatweb.api.param.system package top.fatweb.api.param.system
import io.swagger.v3.oas.annotations.media.Schema import io.swagger.v3.oas.annotations.media.Schema
import org.springframework.format.annotation.DateTimeFormat
import top.fatweb.api.param.PageParam import top.fatweb.api.param.PageParam
import java.time.LocalDateTime
@Schema(description = "获取系统日志请求参数") @Schema(description = "获取系统日志请求参数")
data class SysLogGetParam( data class SysLogGetParam(
@@ -19,5 +21,19 @@ data class SysLogGetParam(
example = "GET,POST", example = "GET,POST",
allowableValues = ["GET", "POST", "PUT", "PATCH", "DELETE", "DELETE", "OPTIONS"] allowableValues = ["GET", "POST", "PUT", "PATCH", "DELETE", "DELETE", "OPTIONS"]
) )
val requestMethod: String? = null val requestMethod: String? = null,
@Schema(description = "查询请求 Url")
val searchRequestUrl: String? = null,
@Schema(description = "查询使用正则表达式")
val searchRegex: Boolean = false,
@Schema(description = "查询开始时间")
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
val searchStartTime: LocalDateTime? = null,
@Schema(description = "查询结束时间")
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
val searchEndTime: LocalDateTime? = null
) : PageParam() ) : PageParam()

View File

@@ -39,6 +39,14 @@ class SysLogServiceImpl : ServiceImpl<SysLogMapper, SysLog>(), ISysLogService {
) )
} }
return baseMapper.selectPage(sysLogPage, sysLogGetParam?.logType?.split(","), sysLogGetParam?.requestMethod?.split(",")) return baseMapper.selectPage(
sysLogPage,
sysLogGetParam?.logType?.split(","),
sysLogGetParam?.requestMethod?.split(","),
sysLogGetParam?.searchRequestUrl,
sysLogGetParam?.searchRegex ?: false,
sysLogGetParam?.searchStartTime,
sysLogGetParam?.searchEndTime
)
} }
} }

View File

@@ -29,6 +29,22 @@
separator="," close=")" nullable="true"> separator="," close=")" nullable="true">
#{item} #{item}
</foreach> </foreach>
<if test="searchRequestUrl != null">
<choose>
<when test="searchRegex == true">
and concat_ws('?', concat(t_sys_log.request_server_address, t_sys_log.request_uri),
if(length(t_sys_log.request_params) != 0, t_sys_log.request_params, null)) regexp #{searchRequestUrl}
</when>
<otherwise>
and concat_ws('?', concat(t_sys_log.request_server_address, t_sys_log.request_uri),
if(length(t_sys_log.request_params) != 0, t_sys_log.request_params, null)) like concat('%',
#{searchRequestUrl}, '%')
</otherwise>
</choose>
</if>
<if test="searchStartTime != null and searchEndTime != null">
and t_sys_log.start_time between #{searchStartTime} and #{searchEndTime}
</if>
</where> </where>
</select> </select>