<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tongran.mtragent.mapper.RmMtrProbeResultMapper">

    <resultMap type="RmMtrProbeResult" id="RmMtrProbeResultResult">
        <result property="id"    column="id"    />
        <result property="mtrClientId"    column="mtr_client_id"    />
        <result property="clientId"    column="client_id"    />
        <result property="publicIp"    column="public_ip"    />
        <result property="packetLossRate"    column="packet_loss_rate"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="hopResult"    column="hop_result"    />
    </resultMap>

    <sql id="selectRmMtrProbeResultVo">
        select id, mtr_client_id, client_id, public_ip, packet_loss_rate, create_time, update_time, create_by, update_by, hop_result from rm_mtr_probe_result
    </sql>

    <select id="selectRmMtrProbeResultList" parameterType="RmMtrProbeResult" resultMap="RmMtrProbeResultResult">
        <include refid="selectRmMtrProbeResultVo"/>
        <where>
            <if test="mtrClientId != null  and mtrClientId != ''"> and mtr_client_id = #{mtrClientId}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="publicIp != null  and publicIp != ''"> and public_ip = #{publicIp}</if>
            <if test="packetLossRate != null "> and packet_loss_rate = #{packetLossRate}</if>
            <if test="hopResult != null  and hopResult != ''"> and hop_result = #{hopResult}</if>
        </where>
    </select>

    <select id="selectRmMtrProbeResultById" parameterType="Long" resultMap="RmMtrProbeResultResult">
        <include refid="selectRmMtrProbeResultVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmMtrProbeResult" parameterType="RmMtrProbeResult" useGeneratedKeys="true" keyProperty="id">
        insert into rm_mtr_probe_result
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mtrClientId != null">mtr_client_id,</if>
            <if test="clientId != null">client_id,</if>
            <if test="publicIp != null">public_ip,</if>
            <if test="packetLossRate != null">packet_loss_rate,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="hopResult != null">hop_result,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mtrClientId != null">#{mtrClientId},</if>
            <if test="clientId != null">#{clientId},</if>
            <if test="publicIp != null">#{publicIp},</if>
            <if test="packetLossRate != null">#{packetLossRate},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="hopResult != null">#{hopResult},</if>
        </trim>
    </insert>

    <update id="updateRmMtrProbeResult" parameterType="RmMtrProbeResult">
        update rm_mtr_probe_result
        <trim prefix="SET" suffixOverrides=",">
            <if test="mtrClientId != null">mtr_client_id = #{mtrClientId},</if>
            <if test="clientId != null">client_id = #{clientId},</if>
            <if test="publicIp != null">public_ip = #{publicIp},</if>
            <if test="packetLossRate != null">packet_loss_rate = #{packetLossRate},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="hopResult != null">hop_result = #{hopResult},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRmMtrProbeResultById" parameterType="Long">
        delete from rm_mtr_probe_result where id = #{id}
    </delete>

    <delete id="deleteRmMtrProbeResultByIds" parameterType="String">
        delete from rm_mtr_probe_result where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="batchInsertRmMtrProbeResult" parameterType="RmMtrProbeResult">
        INSERT IGNORE INTO ${tableName}
        (
        mtr_client_id,
        client_id,
        public_ip,
        packet_loss_rate,
        create_time,
        update_time,
        hop_result
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.mtrClientId},
            #{item.clientId},
            #{item.publicIp},
            #{item.packetLossRate},
            #{item.createTime},
            #{item.updateTime},
            #{item.hopResult}
            )
        </foreach>
    </insert>
    <!-- 在 RmMtrProbeResultMapper.xml 中添加 -->
    <select id="selectByCondition" parameterType="RmMtrProbeResult" resultMap="RmMtrProbeResultResult">
        SELECT
        id, mtr_client_id, client_id, public_ip, packet_loss_rate,
        create_time, update_time, create_by, update_by, hop_result
        FROM ${tableName}
        <where>
            <if test="mtrClientId != null and mtrClientId != ''">
                AND mtr_client_id = #{mtrClientId}
            </if>
            <if test="clientId != null and clientId != ''">
                AND client_id = #{clientId}
            </if>
            <!-- 时间范围查询 -->
            <if test="startTime != null">
                AND create_time &gt;= #{startTime}
            </if>
            <if test="endTime != null">
                AND create_time &lt;= #{endTime}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>
</mapper>