<?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.rocketmq.mapper.InitialBandwidthTrafficMapper">

    <resultMap type="InitialBandwidthTraffic" id="InitialBandwidthTrafficResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="mac" column="mac"/>
        <result property="status" column="status"/>
        <result property="type" column="type"/>
        <result property="ipV4" column="ipV4"/>
        <result property="inDropped" column="in_dropped"/>
        <result property="outDropped" column="out_dropped"/>
        <result property="inSpeed" column="in_speed"/>
        <result property="outSpeed" column="out_speed"/>
        <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="clientId" column="client_id"/>
        <result property="speed" column="speed"/>
        <result property="duplex" column="duplex"/>

    </resultMap>
    <sql id="selectInitialBandwidthTrafficVo"> select id, name, mac, status, type, ipV4, in_dropped, out_dropped, in_speed, out_speed, create_time, update_time, create_by, update_by, client_id from initial_bandwidth_traffic </sql>
    <select id="selectInitialBandwidthTrafficList" parameterType="InitialBandwidthTraffic" resultMap="InitialBandwidthTrafficResult">
        <include refid="selectInitialBandwidthTrafficVo"/>
        <where>
            <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="mac != null and mac != ''"> and mac = #{mac}</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
            <if test="type != null and type != ''"> and type = #{type}</if>
            <if test="ipV4 != null and ipV4 != ''"> and ipV4 = #{ipV4}</if>
            <if test="inDropped != null "> and in_dropped = #{inDropped}</if>
            <if test="outDropped != null "> and out_dropped = #{outDropped}</if>
            <if test="inSpeed != null and inSpeed != ''"> and in_speed = #{inSpeed}</if>
            <if test="outSpeed != null and outSpeed != ''"> and out_speed = #{outSpeed}</if>
            <if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
        </where>
    </select>
    <select id="selectInitialBandwidthTrafficById" parameterType="Long" resultMap="InitialBandwidthTrafficResult">
        <include refid="selectInitialBandwidthTrafficVo"/>
        where id = #{id}
    </select>
    <insert id="insertInitialBandwidthTraffic" parameterType="InitialBandwidthTraffic" useGeneratedKeys="true" keyProperty="id">
        insert into initial_bandwidth_traffic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="mac != null">mac,</if>
            <if test="status != null">status,</if>
            <if test="type != null">type,</if>
            <if test="ipV4 != null">ipV4,</if>
            <if test="inDropped != null">in_dropped,</if>
            <if test="outDropped != null">out_dropped,</if>
            <if test="inSpeed != null">in_speed,</if>
            <if test="outSpeed != null">out_speed,</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="clientId != null">client_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="mac != null">#{mac},</if>
            <if test="status != null">#{status},</if>
            <if test="type != null">#{type},</if>
            <if test="ipV4 != null">#{ipV4},</if>
            <if test="inDropped != null">#{inDropped},</if>
            <if test="outDropped != null">#{outDropped},</if>
            <if test="inSpeed != null">#{inSpeed},</if>
            <if test="outSpeed != null">#{outSpeed},</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="clientId != null">#{clientId},</if>
        </trim>
    </insert>
    <update id="updateInitialBandwidthTraffic" parameterType="InitialBandwidthTraffic">
        update initial_bandwidth_traffic
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="mac != null">mac = #{mac},</if>
            <if test="status != null">status = #{status},</if>
            <if test="type != null">type = #{type},</if>
            <if test="ipV4 != null">ipV4 = #{ipV4},</if>
            <if test="inDropped != null">in_dropped = #{inDropped},</if>
            <if test="outDropped != null">out_dropped = #{outDropped},</if>
            <if test="inSpeed != null">in_speed = #{inSpeed},</if>
            <if test="outSpeed != null">out_speed = #{outSpeed},</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="clientId != null">client_id = #{clientId},</if>
        </trim>
        where id = #{id}
    </update>
    <delete id="deleteInitialBandwidthTrafficById" parameterType="Long"> delete from initial_bandwidth_traffic where id = #{id} </delete>
    <delete id="deleteInitialBandwidthTrafficByIds" parameterType="String">
        delete from initial_bandwidth_traffic where id in
        <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach>
    </delete>
    <!-- 单条插入 -->
    <insert id="insert" parameterType="InitialBandwidthTraffic">
        INSERT INTO ${tableName} (
            `name`, `mac`, `status`, `type`, ipV4, `in_dropped`, `out_dropped`,
            `in_speed`, `out_speed`, `total_in_speed`, `total_out_speed`, duplex, speed,
            create_by, update_by, client_id, create_time,
            ipv4_in_speed, ipv4_out_speed, ipv6_in_speed, ipv6_out_speed,
            total_ipv4_in_speed, total_ipv4_out_speed, total_ipv6_in_speed, total_ipv6_out_speed,
            ipV6, ping_dropped
        ) VALUES (
                     #{name}, #{mac}, #{status}, #{type}, #{ipV4}, #{inDropped}, #{outDropped},
                     #{inSpeed}, #{outSpeed}, #{totalInSpeed}, #{totalOutSpeed}, #{duplex}, #{speed},
                     #{createBy}, #{updateBy}, #{clientId}, #{createTime},
                     #{ipv4InSpeed}, #{ipv4OutSpeed}, #{ipv6InSpeed}, #{ipv6OutSpeed},
                     #{totalIpv4InSpeed}, #{totalIpv4OutSpeed}, #{totalIpv6InSpeed}, #{totalIpv6OutSpeed},
                     #{ipV6}, #{pingDropped}
                 )
    </insert>

    <insert id="batchInsert" parameterType="InitialBandwidthTraffic">
        INSERT IGNORE INTO ${tableName} (
        `name`, `mac`, `status`, `type`, ipV4, `in_dropped`, `out_dropped`,
        `in_speed`, `out_speed`, `total_in_speed`, `total_out_speed`, duplex, speed,
        create_by, update_by, client_id, create_time,
        ipv4_in_speed, ipv4_out_speed, ipv6_in_speed, ipv6_out_speed,
        total_ipv4_in_speed, total_ipv4_out_speed, total_ipv6_in_speed, total_ipv6_out_speed,
        ipV6, ping_dropped
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.name}, #{item.mac}, #{item.status}, #{item.type}, #{item.ipV4}, #{item.inDropped}, #{item.outDropped},
            #{item.inSpeed}, #{item.outSpeed}, #{item.totalInSpeed}, #{item.totalOutSpeed}, #{item.duplex}, #{item.speed},
            #{item.createBy}, #{item.updateBy}, #{item.clientId}, #{item.createTime},
            #{item.ipv4InSpeed}, #{item.ipv4OutSpeed}, #{item.ipv6InSpeed}, #{item.ipv6OutSpeed},
            #{item.totalIpv4InSpeed}, #{item.totalIpv4OutSpeed}, #{item.totalIpv6InSpeed}, #{item.totalIpv6OutSpeed},
            #{item.ipV6}, #{item.pingDropped}
            )
        </foreach>
    </insert>

    <select id="getNetInterfaceDetailsMsg" parameterType="InitialBandwidthTraffic" resultType="InitialBandwidthTraffic">
        select
        id,
        `name`,
        mac,
        status,
        `type`,
        ipV4,
        in_dropped as inDropped,
        out_dropped as outDropped,
        in_speed as inSpeed,
        out_speed as outSpeed,
        total_in_speed as totalInSpeed,
        total_out_speed as totalOutSpeed,
        create_time as createTime,
        update_time as updateTime,
        create_by as createBy,
        update_by as updateBy,
        client_id as clientId,
        duplex,
        speed,
        ipv4_in_speed as ipv4InSpeed,
        ipv4_out_speed as ipv4OutSpeed,
        ipv6_in_speed as ipv6InSpeed,
        ipv6_out_speed as ipv6OutSpeed,
        total_ipv4_in_speed as totalIpv4InSpeed,
        total_ipv4_out_speed as totalIpv4OutSpeed,
        total_ipv6_in_speed as totalIpv6InSpeed,
        total_ipv6_out_speed as totalIpv6OutSpeed,
        ipV6,
        ping_dropped as pingDropped
        from ${tableName}
        <where>
            <if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
            <if test="name != null and name != ''"> and name like concat(#{name},'%')</if>
        </where>
        order by create_time desc
        limit 1
    </select>

    <select id="getNetTrafficList" parameterType="InitialBandwidthTraffic" resultType="InitialBandwidthTraffic">
        select
        id,
        `name`,
        mac,
        status,
        `type`,
        ipV4,
        in_dropped as inDropped,
        out_dropped as outDropped,
        in_speed as inSpeed,
        out_speed as outSpeed,
        total_in_speed as totalInSpeed,
        total_out_speed as totalOutSpeed,
        create_time as createTime,
        update_time as updateTime,
        create_by as createBy,
        update_by as updateBy,
        client_id as clientId,
        duplex,
        speed,
        ipv4_in_speed as ipv4InSpeed,
        ipv4_out_speed as ipv4OutSpeed,
        ipv6_in_speed as ipv6InSpeed,
        ipv6_out_speed as ipv6OutSpeed,
        total_ipv4_in_speed as totalIpv4InSpeed,
        total_ipv4_out_speed as totalIpv4OutSpeed,
        total_ipv6_in_speed as totalIpv6InSpeed,
        total_ipv6_out_speed as totalIpv6OutSpeed,
        ipV6,
        ping_dropped as pingDropped
        from ${tableName}
        <where>
            <if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
            <if test="name != null and name != ''"> and name like concat(#{name},'%')</if>
            <if test="startTime != null  and startTime != ''"> and create_time &gt;= #{startTime}</if>
            <if test="endTime != null  and endTime != ''"> and create_time &lt;= #{endTime}</if>
        </where>
    </select>
    <select id="countByClientIdAndTime" parameterType="InitialBandwidthTraffic" resultType="java.lang.Integer">
        select count(1)
        from ${tableName}
        <where>
            <if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
            <if test="startTime != null"> and create_time = #{startTime}</if>
        </where>
    </select>
</mapper>