package com.erp.audit.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.erp.audit.entity.AuditLog;
import com.erp.audit.dto.AuditLogQueryRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 审计日志Mapper
 */
@Mapper
public interface AuditLogRepository extends BaseMapper<AuditLog> {

    /**
     * 分页查询审计日志
     */
    IPage<AuditLog> selectPage(Page<AuditLog> page, @Param("q") AuditLogQueryRequest request);

    /**
     * 查询某时间范围内的日志
     */
    List<AuditLog> selectByTimeRange(@Param("startTime") LocalDateTime startTime,
                                      @Param("endTime") LocalDateTime endTime,
                                      @Param("tenantId") Long tenantId);

    /**
     * 统计某用户操作次数
     */
    Long countByUserId(@Param("userId") Long userId, @Param("startTime") LocalDateTime startTime);

    /**
     * 批量插入
     */
    int batchInsert(@Param("list") List<AuditLog> list);
}
