package com.common.mapper;


import com.common.entity.DeviceReceiveLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface DeviceReceiveLogMapper {

    /**
     * 插入单条记录
     */
    int insert(DeviceReceiveLog log);

    /**
     * 批量插入记录
     */
    int batchInsert(@Param("list") List<DeviceReceiveLog> logs);

    /**
     * 根据ID查询
     */
    DeviceReceiveLog selectById(@Param("id") Long id);

    /**
     * 根据设备ID查询
     */
    List<DeviceReceiveLog> selectByDeviceId(@Param("deviceId") Integer deviceId);

    /**
     * 根据采集探针ID查询
     */
    List<DeviceReceiveLog> selectByCollectId(@Param("collectId") Integer collectId);

    /**
     * 根据IP地址查询
     */
    List<DeviceReceiveLog> selectByDeviceIp(@Param("deviceIp") String deviceIp);

    /**
     * 根据时间范围查询
     */
    List<DeviceReceiveLog> selectByTimeRange(
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime);

    /**
     * 多条件组合查询
     */
    List<DeviceReceiveLog> selectByCondition(DeviceReceiveLog condition);

    /**
     * 统计设备接收日志数量
     */
    Long countByCondition(DeviceReceiveLog condition);

    /**
     * 根据时间范围删除旧数据
     */
    int deleteByTimeRange(
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime);

    /**
     * 获取最近N条记录
     */
    List<DeviceReceiveLog> selectRecent(@Param("limit") Integer limit);

    /**
     * 按设备分组统计日志数量
     */
    List<Map<String, Object>> countByDeviceGroup();
}