This commit is contained in:
parent
9c104d6f55
commit
8beb75cbc8
|
@ -0,0 +1,42 @@
|
|||
package com.guwan.backend.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.guwan.backend.entity.SysLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysLogMapper extends BaseMapper<SysLog> {
|
||||
|
||||
/**
|
||||
* 分页查询日志
|
||||
*/
|
||||
@Select("SELECT * FROM sys_log WHERE user_id = #{userId} ORDER BY create_time DESC")
|
||||
IPage<SysLog> selectPageByUserId(Page<SysLog> page, @Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 查询指定时间范围内的日志
|
||||
*/
|
||||
@Select("SELECT * FROM sys_log WHERE create_time BETWEEN #{startTime} AND #{endTime}")
|
||||
List<SysLog> selectByTimeRange(@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 查询用户的操作统计
|
||||
*/
|
||||
@Select("SELECT operation, COUNT(*) as count FROM sys_log " +
|
||||
"WHERE user_id = #{userId} GROUP BY operation")
|
||||
List<OperationCount> selectUserOperationCount(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 查询错误日志
|
||||
*/
|
||||
@Select("SELECT * FROM sys_log WHERE status = 0 ORDER BY create_time DESC LIMIT #{limit}")
|
||||
List<SysLog> selectLatestErrors(@Param("limit") Integer limit);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.guwan.backend.mapper.SysLogMapper">
|
||||
|
||||
<!-- 复杂条件查询 -->
|
||||
<select id="selectByCondition" resultType="com.guwan.backend.entity.SysLog">
|
||||
SELECT * FROM sys_log
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="operation != null and operation != ''">
|
||||
AND operation = #{operation}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<if test="startTime != null">
|
||||
AND create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
AND create_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 统计分析查询 -->
|
||||
<select id="selectStatistics" resultType="java.util.Map">
|
||||
SELECT
|
||||
COUNT(*) as total,
|
||||
SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as success,
|
||||
SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) as fail,
|
||||
AVG(time_consuming) as avgTime
|
||||
FROM sys_log
|
||||
WHERE create_time BETWEEN #{startTime} AND #{endTime}
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue