package com.common.mapper;

import com.common.entity.XdrHoneypot;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * XDR Honeypot Mapper 接口
 */
public interface XdrHoneypotMapper {

    /**
     * 插入单条记录
     */
    @Insert("INSERT INTO xdr_honeypot (vcsource, dstart_time, dtime, risk_level, vcconnection, " +
            "file_info, extra, vctype, agent_sn, agent_name, honeypot_id, honeypot_name, " +
            "src_ip, src_port, src_mac, dest_ip, dest_port, proxy_ip, node) " +
            "VALUES (#{vcsource}, #{dstartTime}, #{dtime}, #{riskLevel}, #{vcconnection}, " +
            "#{fileInfo}, #{extra}, #{vctype}, #{agentSn}, #{agentName}, #{honeypotId}, #{honeypotName}, " +
            "#{srcIp}, #{srcPort}, #{srcMac}, #{destIp}, #{destPort}, #{proxyIp}, #{node})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(XdrHoneypot xdrHoneypot);

    /**
     * 批量插入记录
     */
    int batchInsert(List<XdrHoneypot> xdrHoneypotList);

    /**
     * 根据ID查询记录
     */
    @Select("SELECT * FROM xdr_honeypot WHERE id = #{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "vcsource", column = "vcsource"),
            @Result(property = "dstartTime", column = "dstart_time"),
            @Result(property = "dtime", column = "dtime"),
            @Result(property = "riskLevel", column = "risk_level"),
            @Result(property = "vcconnection", column = "vcconnection"),
            @Result(property = "fileInfo", column = "file_info"),
            @Result(property = "extra", column = "extra"),
            @Result(property = "vctype", column = "vctype"),
            @Result(property = "agentSn", column = "agent_sn"),
            @Result(property = "agentName", column = "agent_name"),
            @Result(property = "honeypotId", column = "honeypot_id"),
            @Result(property = "honeypotName", column = "honeypot_name"),
            @Result(property = "srcIp", column = "src_ip"),
            @Result(property = "srcPort", column = "src_port"),
            @Result(property = "srcMac", column = "src_mac"),
            @Result(property = "destIp", column = "dest_ip"),
            @Result(property = "destPort", column = "dest_port"),
            @Result(property = "proxyIp", column = "proxy_ip"),
            @Result(property = "node", column = "node")
    })
    XdrHoneypot selectById(Long id);

    /**
     * 查询所有记录
     */
    @Select("SELECT * FROM xdr_honeypot ORDER BY id DESC")
    @Results({
            @Result(property = "dstartTime", column = "dstart_time"),
            @Result(property = "riskLevel", column = "risk_level"),
            @Result(property = "fileInfo", column = "file_info"),
            @Result(property = "agentSn", column = "agent_sn"),
            @Result(property = "agentName", column = "agent_name"),
            @Result(property = "honeypotId", column = "honeypot_id"),
            @Result(property = "honeypotName", column = "honeypot_name"),
            @Result(property = "srcIp", column = "src_ip"),
            @Result(property = "srcPort", column = "src_port"),
            @Result(property = "srcMac", column = "src_mac"),
            @Result(property = "destIp", column = "dest_ip"),
            @Result(property = "destPort", column = "dest_port"),
            @Result(property = "proxyIp", column = "proxy_ip")
    })
    List<XdrHoneypot> selectAll();

    /**
     * 根据源IP查询记录
     */
    @Select("SELECT * FROM xdr_honeypot WHERE src_ip = #{srcIp} ORDER BY dtime DESC")
    List<XdrHoneypot> selectBySrcIp(String srcIp);

    /**
     * 根据风险等级查询记录
     */
    @Select("SELECT * FROM xdr_honeypot WHERE risk_level = #{riskLevel} ORDER BY dtime DESC")
    List<XdrHoneypot> selectByRiskLevel(String riskLevel);

    /**
     * 更新记录
     */
    @Update("UPDATE xdr_honeypot SET risk_level = #{riskLevel}, extra = #{extra} WHERE id = #{id}")
    int update(XdrHoneypot xdrHoneypot);

    /**
     * 根据ID删除记录
     */
    @Delete("DELETE FROM xdr_honeypot WHERE id = #{id}")
    int delete(Long id);

    /**
     * 统计总记录数
     */
    @Select("SELECT COUNT(*) FROM xdr_honeypot")
    long count();
}