package com.haha.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.haha.entity.OperationLog;
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接口
 */
@Mapper
public interface OperationLogMapper extends BaseMapper<OperationLog> {

    /**
     * 统计各模块操作次数
     */
    @Select("SELECT module, COUNT(*) as count FROM t_operation_log " +
            "WHERE create_time >= #{startTime} GROUP BY module ORDER BY count DESC")
    List<Map<String, Object>> countByModule(@Param("startTime") LocalDateTime startTime);

    /**
     * 统计操作成功失败数
     */
    @Select("SELECT status, COUNT(*) as count FROM t_operation_log " +
            "WHERE create_time >= #{startTime} GROUP BY status")
    List<Map<String, Object>> countByStatus(@Param("startTime") LocalDateTime startTime);

    /**
     * 统计每日操作数量
     */
    @Select("SELECT DATE(create_time) as date, COUNT(*) as count FROM t_operation_log " +
            "WHERE create_time >= #{startTime} GROUP BY DATE(create_time) ORDER BY date")
    List<Map<String, Object>> countByDate(@Param("startTime") LocalDateTime startTime);
}
