package com.lesingle.modules.sys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lesingle.modules.sys.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;
import java.util.Map;

@Mapper
public interface SysLogMapper extends BaseMapper<SysLog> {

    /** 按操作类型统计（Top 10） */
    @Select("SELECT action, COUNT(*) AS count FROM t_sys_log WHERE create_time >= #{since} GROUP BY action ORDER BY count DESC LIMIT 10")
    List<Map<String, Object>> selectActionStats(@Param("since") LocalDateTime since);

    /** 按日期统计 */
    @Select("SELECT DATE(create_time) AS date, COUNT(*) AS count FROM t_sys_log WHERE create_time >= #{since} GROUP BY DATE(create_time) ORDER BY date")
    List<Map<String, Object>> selectDailyStats(@Param("since") LocalDateTime since);
}
