<?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.system.mapper.EpsInitialTrafficDataMapper">

    <update id="createEpsTrafficTable">
        CREATE TABLE IF NOT EXISTS ${tableName} (
            id BIGINT(20) AUTO_INCREMENT COMMENT '唯一标识ID',
            `name` VARCHAR(255) COMMENT '接口名称',
            `mac` VARCHAR(50) COMMENT 'MAC地址',
            `status` VARCHAR(20) COMMENT '运行状态',
            `type` VARCHAR(30) COMMENT '接口类型',
            ipV4 VARCHAR(20) COMMENT 'IPv4地址',
            `in_dropped` DECIMAL(20,2) COMMENT '入站丢包率(%)',
            `out_dropped` DECIMAL(20,2) COMMENT '出站丢包率(%)',
            `in_speed` varchar(50) COMMENT '接收带宽(bit)',
            `out_speed` varchar(50) COMMENT '发送带宽(bit)',
            `total_in_speed` varchar(50) COMMENT '总接收带宽(bit)',
            `total_out_speed` varchar(50) COMMENT '总发送带宽(bit)',
            `machine_flow` varchar(50) COMMENT '金山带宽(bit)',
            `speed` varchar(100) COMMENT '协商速度',
            `duplex` varchar(100) COMMENT '工作模式',
            business_id varchar(50) COMMENT '业务代码',
            business_name varchar(200) COMMENT '业务名称',
            service_sn varchar(64) COMMENT '服务器SN',
            node_name varchar(200) COMMENT '服务器名称',
            revenue_method varchar(10) COMMENT '收益方式(1.流量,2包端)',
            package_bandwidth DECIMAL(10,2) COMMENT '包端带宽值',
            create_time DATETIME COMMENT '创建时间',
            update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
            create_by VARCHAR(50) COMMENT '创建人',
            update_by VARCHAR(50) COMMENT '修改人',
            client_id VARCHAR(255) COMMENT '设备唯一标识',
            ipv4_in_speed VARCHAR(50) COMMENT 'IPv4接收流量',
            ipv4_out_speed VARCHAR(50) COMMENT 'IPv4发送流量',
            ipv6_in_speed VARCHAR(50) COMMENT 'IPv6接收流量',
            ipv6_out_speed VARCHAR(50) COMMENT 'IPv6发送流量',
            total_ipv4_in_speed VARCHAR(50) COMMENT 'IPv4接收总流量',
            total_ipv4_out_speed VARCHAR(50) COMMENT 'IPv4发送总流量',
            total_ipv6_in_speed VARCHAR(50) COMMENT 'IPv6接收总流量',
            total_ipv6_out_speed VARCHAR(50) COMMENT 'IPv6发送总流量',
            ipV6 VARCHAR(50) COMMENT 'IPv6地址',
            ping_dropped double COMMENT 'ping丢包率',
            PRIMARY KEY (id),
            UNIQUE KEY uk_client_mac_name_time (client_id, mac, name, create_time),
            INDEX idx_name_time (`name`,create_time)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='EPS设备流量初始数据表';
    </update>

    <update id="createEpsInitialTrafficTable">
        CREATE TABLE IF NOT EXISTS ${tableName} (
            id BIGINT(20) AUTO_INCREMENT COMMENT '唯一标识ID',
            `name` VARCHAR(255) COMMENT '接口名称',
            `mac` VARCHAR(20) COMMENT 'MAC地址',
            `status` VARCHAR(20) COMMENT '运行状态',
            `type` VARCHAR(30) COMMENT '接口类型',
            ipV4 VARCHAR(20) COMMENT 'IPv4地址',
            `in_dropped` DECIMAL(20,2) COMMENT '入站丢包率(%)',
            `out_dropped` DECIMAL(20,2) COMMENT '出站丢包率(%)',
            `in_speed` VARCHAR(50) COMMENT '接收带宽(Mbps)',
            `out_speed` VARCHAR(50) COMMENT '发送带宽(Mbps)',
            `total_in_speed` VARCHAR(50) COMMENT '总接收带宽(Mbps)',
            `total_out_speed` VARCHAR(50) COMMENT '总发送带宽(Mbps)',
            `speed` varchar(100) COMMENT '协商速度',
            `duplex` varchar(100) COMMENT '工作模式',
            create_time DATETIME COMMENT '创建时间',
            update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
            create_by VARCHAR(50) COMMENT '创建人',
            update_by VARCHAR(50) COMMENT '修改人',
            client_id VARCHAR(255) COMMENT '设备唯一标识',
            ipv4_in_speed VARCHAR(50) COMMENT 'IPv4接收流量',
            ipv4_out_speed VARCHAR(50) COMMENT 'IPv4发送流量',
            ipv6_in_speed VARCHAR(50) COMMENT 'IPv6接收流量',
            ipv6_out_speed VARCHAR(50) COMMENT 'IPv6发送流量',
            total_ipv4_in_speed VARCHAR(50) COMMENT 'IPv4接收总流量',
            total_ipv4_out_speed VARCHAR(50) COMMENT 'IPv4发送总流量',
            total_ipv6_in_speed VARCHAR(50) COMMENT 'IPv6接收总流量',
            total_ipv6_out_speed VARCHAR(50) COMMENT 'IPv6发送总流量',
            ipV6 VARCHAR(50) COMMENT 'IPv6地址',
            ping_dropped double COMMENT 'ping丢包率',
            PRIMARY KEY (id),
            UNIQUE KEY uk_client_mac_name_time (client_id, mac, name, create_time),
            INDEX idx_name_time (`name`,create_time)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='初始带宽流量表';
    </update>
    <update id="createMtrProbeResultTable">
        CREATE TABLE IF NOT EXISTS ${tableName} (
            id BIGINT(20) AUTO_INCREMENT COMMENT '主键ID',
            mtr_client_id VARCHAR(200) COMMENT 'MTR客户端ID',
            client_id VARCHAR(200) COMMENT '客户端ID',
            public_ip VARCHAR(45) COMMENT '公网IP地址',
            packet_loss_rate DECIMAL(5,2) COMMENT '丢包率(%)',
            hop_result LONGTEXT COMMENT '每一跳解析结果(JSON形式)',
            create_time DATETIME  DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
            update_time DATETIME  DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
            create_by VARCHAR(64) COMMENT '创建人',
            update_by VARCHAR(64) COMMENT '更新人',
            PRIMARY KEY (id),
            UNIQUE KEY uk_probe_record (mtr_client_id, client_id, create_time),
            INDEX idx_mtr_client_id (mtr_client_id, create_time)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='网络mtr探测结果表';
    </update>
    <update id="createSwitchInfoTable">
        CREATE TABLE IF NOT EXISTS ${tableName} (
            id BIGINT(20) AUTO_INCREMENT COMMENT '主键ID',
            client_id VARCHAR(255) NOT NULL COMMENT '客户端ID',
            name VARCHAR(100) NOT NULL COMMENT '网络接口名称',
            switch_ip VARCHAR(100) COMMENT '交换机IP',
            in_bytes DECIMAL(22,0) COMMENT '接收流量(字节)',
            out_bytes DECIMAL(22,0) COMMENT '发送流量(字节)',
            in_speed DECIMAL(20,2) DEFAULT 0.00 COMMENT '接收速率(bit/s)',
            out_speed DECIMAL(20,2) DEFAULT 0.00 COMMENT '发送速率(bit/s)',
            max_speed DECIMAL(20,0) COMMENT '流量最大值',
            status VARCHAR(20) COMMENT '接口状态',
            type VARCHAR(30) COMMENT '接口类型',
            if_speed VARCHAR(50) COMMENT '端口速率(Mbps)',
            if_index VARCHAR(50) COMMENT '端口索引',
            if_in_discards VARCHAR(50) COMMENT '入站丢包',
            if_out_discards VARCHAR(50) COMMENT '出站丢包',
            if_in_errors VARCHAR(50) COMMENT '入站错误',
            if_out_errors VARCHAR(50) COMMENT '出站错误',
            create_time DATETIME COMMENT '创建时间',
            update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
            create_by VARCHAR(50) COMMENT '创建人',
            update_by VARCHAR(50) COMMENT '更新人',
            PRIMARY KEY (id),
            UNIQUE KEY uk_switch_record (client_id, switch_ip, name, create_time),
            INDEX idx_create_time (create_time),
            INDEX idx_draw (client_id, name, create_time)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='交换机监控信息表';
    </update>

    <update id="createSwitchInfoDetailsTable">
        CREATE TABLE IF NOT EXISTS ${tableName} (
            id BIGINT(20) AUTO_INCREMENT COMMENT '主键ID',
            client_id VARCHAR(255) NOT NULL COMMENT '客户端ID',
            name VARCHAR(100) NOT NULL COMMENT '网络接口名称',
            switch_ip VARCHAR(100) COMMENT '交换机IP',
            switch_name VARCHAR(100) COMMENT '交换机名称',
            switch_sn VARCHAR(64) COMMENT '交换机SN',
            in_bytes DECIMAL(22,2) COMMENT '接收流量(字节)',
            out_bytes DECIMAL(22,2) COMMENT '发送流量(字节)',
            in_speed DECIMAL(20,2) COMMENT '接收速率(bit/s)',
            out_speed DECIMAL(20,2) COMMENT '发送速率(bit/s)',
            max_speed DECIMAL(20,2) COMMENT '流量最大值',
            status VARCHAR(20) COMMENT '接口状态',
            type VARCHAR(30) COMMENT '接口类型',
            interface_device_type VARCHAR(50) COMMENT '连接设备类型',
            interface_name_remark VARCHAR(255) COMMENT '接口别名',
            server_name VARCHAR(100) COMMENT '服务器名称',
            server_client_id VARCHAR(255) COMMENT '服务器客户端ID',
            server_port VARCHAR(200) COMMENT '服务器网口',
            server_sn VARCHAR(64) COMMENT '服务器SN',
            business_code VARCHAR(100) COMMENT '业务代码',
            business_name VARCHAR(200) COMMENT '业务名称',
            if_speed VARCHAR(50) COMMENT '端口速率(Mbps)',
            if_index VARCHAR(50) COMMENT '端口索引',
            if_in_discards VARCHAR(50) COMMENT '入站丢包',
            if_out_discards VARCHAR(50) COMMENT '出站丢包',
            if_in_errors VARCHAR(50) COMMENT '入站错误',
            if_out_errors VARCHAR(50) COMMENT '出站错误',
            create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
            update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
            create_by VARCHAR(50) COMMENT '创建人',
            update_by VARCHAR(50) COMMENT '更新人',
            PRIMARY KEY (id),
            UNIQUE KEY uk_switch_detail (client_id, switch_ip, name, create_time),
            INDEX idx_filter_sort (name, interface_device_type, switch_sn, create_time),
            INDEX idx_create_time (create_time),
            INDEX idx_client_time (client_id, name, create_time)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='交换机监控详情表';
    </update>
    <update id="createOtherMsgTable">
        CREATE TABLE IF NOT EXISTS ${tableName} (
            id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
            client_id VARCHAR(64) COMMENT '客户端ID',
            collect_type VARCHAR(100) COMMENT '采集类型',
            collect_value LONGTEXT COMMENT '采集值',
            create_time DATETIME COMMENT '创建时间',
            update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
            create_by VARCHAR(64) COMMENT '创建人',
            update_by VARCHAR(64) COMMENT '修改人',
            PRIMARY KEY (id),
            UNIQUE KEY uk_client_collect (client_id, collect_type, create_time)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='服务器系统其他信息采集数据表';
    </update>
    <update id="createSwitchOpMdTable">
        CREATE TABLE IF NOT EXISTS ${tableName} (
            id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
            fiber_ent_index VARCHAR(64) COMMENT '光模块端口索引',
            fiber_port_name VARCHAR(128) COMMENT '光模块端口名称',
            hw_entity_optical_tx_low_threshold DECIMAL(10,2) COMMENT '光模块发送光衰阈值(dBm)',
            hw_entity_optical_rx_low_threshold DECIMAL(10,2) COMMENT '光模块接收光衰阈值(dBm)',
            hw_entity_optical_rx_power DECIMAL(10,2) COMMENT '光模块接收功率(dBm)',
            hw_entity_optical_tx_power DECIMAL(10,2) COMMENT '光模块发送功率(dBm)',
            client_id VARCHAR(64) COMMENT '客户端ID',
            create_time DATETIME COMMENT '创建时间',
            update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
            create_by VARCHAR(64) COMMENT '创建人',
            update_by VARCHAR(64) COMMENT '修改人',
            PRIMARY KEY (id),
            UNIQUE KEY uk_client_fiber_time (client_id, create_time, fiber_port_name)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='光模块信息表';
    </update>
    <update id="createDiskInfo">
        CREATE TABLE IF NOT EXISTS ${tableName} (
            `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
            `client_id` varchar(255) NOT NULL COMMENT '客户端ID',
            `name` varchar(100) NOT NULL COMMENT '磁盘名称(如sda、sdb等)',
            `serial` varchar(100) COMMENT '磁盘序列号',
            `total` bigint(20) COMMENT '磁盘总大小(GB)',
            `write_speed` bigint(20) COMMENT '磁盘写入速率(字节/秒)',
            `read_speed` bigint(20) COMMENT '磁盘读取速率(字节/秒)',
            `write_times` bigint(20) COMMENT '磁盘写入次数',
            `read_times` bigint(20) COMMENT '磁盘读取次数',
            `write_bytes` bigint(20) COMMENT '磁盘写入总字节数',
            `read_bytes` bigint(20) COMMENT '磁盘读取总字节数',
            `create_by` varchar(50) COMMENT '创建人',
            `update_by` varchar(50) COMMENT '更新人',
            `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
            `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
            `type` varchar(255) COMMENT '磁盘类型',
            `used_space` bigint(20) COMMENT '已用空间',
            PRIMARY KEY (`id`),
            UNIQUE KEY uk_client_disk_time (`client_id`, `name`, `create_time`),
            INDEX idx_clent_type_time(`client_id`, `create_time`, `type`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='磁盘监控信息表';
    </update>
    <!-- 单条插入语句 -->
    <insert id="insert">
        INSERT INTO ${tableName} (
            `name`,
            `mac`,
            `status`,
            `type`,
            ipV4,
            `in_dropped`,
            `out_dropped`,
            `in_speed`,
            `out_speed`,
            `total_in_speed`,
            `total_out_speed`,
            `speed`,
            `duplex`,
            business_id,
            business_name,
            service_sn,
            node_name,
            revenue_method,
            package_bandwidth,
            create_by,
            update_by,
            client_id,
            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},
                     #{speed},
                     #{duplex},
                     #{businessId},
                     #{businessName},
                     #{serviceSn},
                     #{nodeName},
                     #{revenueMethod},
                     #{packageBandwidth},
                     #{createBy},
                     #{updateBy},
                     #{clientId},
                     #{ipv4InSpeed},
                     #{ipv4OutSpeed},
                     #{ipv6InSpeed},
                     #{ipv6OutSpeed},
                     #{totalIpv4InSpeed},
                     #{totalIpv4OutSpeed},
                     #{totalIpv6InSpeed},
                     #{totalIpv6OutSpeed},
                     #{ipV6},
                     #{pingDropped}
                 )
    </insert>

    <!-- 批量插入语句 -->
    <insert id="batchInsert">
        INSERT IGNORE INTO ${tableName} (
        id,
        `name`,
        `mac`,
        `status`,
        `type`,
        ipV4,
        `in_dropped`,
        `out_dropped`,
        `in_speed`,
        `out_speed`,
        `total_in_speed`,
        `total_out_speed`,
        `speed`,
        `duplex`,
        business_id,
        business_name,
        service_sn,
        node_name,
        revenue_method,
        package_bandwidth,
        create_time,
        update_time,
        create_by,
        update_by,
        client_id,
        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="dataList" item="data" separator=",">
            (
            #{data.id,jdbcType=BIGINT},
            #{data.name,jdbcType=VARCHAR},
            #{data.mac,jdbcType=VARCHAR},
            #{data.status,jdbcType=VARCHAR},
            #{data.type,jdbcType=VARCHAR},
            #{data.ipV4,jdbcType=VARCHAR},
            #{data.inDropped,jdbcType=DECIMAL},
            #{data.outDropped,jdbcType=DECIMAL},
            #{data.inSpeed,jdbcType=VARCHAR},
            #{data.outSpeed,jdbcType=VARCHAR},
            #{data.totalInSpeed,jdbcType=VARCHAR},
            #{data.totalOutSpeed,jdbcType=VARCHAR},
            #{data.speed,jdbcType=VARCHAR},
            #{data.duplex,jdbcType=VARCHAR},
            #{data.businessId,jdbcType=VARCHAR},
            #{data.businessName,jdbcType=VARCHAR},
            #{data.serviceSn,jdbcType=VARCHAR},
            #{data.nodeName,jdbcType=VARCHAR},
            #{data.revenueMethod,jdbcType=VARCHAR},
            #{data.packageBandwidth,jdbcType=DECIMAL},
            #{data.createTime,jdbcType=TIMESTAMP},
            #{data.updateTime,jdbcType=TIMESTAMP},
            #{data.createBy,jdbcType=VARCHAR},
            #{data.updateBy,jdbcType=VARCHAR},
            #{data.clientId,jdbcType=VARCHAR},
            #{data.ipv4InSpeed,jdbcType=VARCHAR},
            #{data.ipv4OutSpeed,jdbcType=VARCHAR},
            #{data.ipv6InSpeed,jdbcType=VARCHAR},
            #{data.ipv6OutSpeed,jdbcType=VARCHAR},
            #{data.totalIpv4InSpeed,jdbcType=VARCHAR},
            #{data.totalIpv4OutSpeed,jdbcType=VARCHAR},
            #{data.totalIpv6InSpeed,jdbcType=VARCHAR},
            #{data.totalIpv6OutSpeed,jdbcType=VARCHAR},
            #{data.ipV6,jdbcType=VARCHAR},
            #{data.pingDropped,jdbcType=DECIMAL}
            )
        </foreach>
    </insert>

    <!-- 条件查询 -->
    <select id="selectByCondition" resultType="EpsInitialTrafficData">
        SELECT
        a.id,
        GROUP_CONCAT(DISTINCT a.`name` SEPARATOR ',') AS name,
        a.`mac` AS mac,
        a.`status` AS status,
        a.`type` AS type,
        a.`ipV4` AS ipV4,
        a.`in_dropped` AS inDropped,
        a.`out_dropped` AS outDropped,
        CAST(sum(ifnull(a.`in_speed`,0)) AS DECIMAL(20,0)) AS inSpeed,
        CAST(sum(ifnull(a.`out_speed`,0)) AS DECIMAL(20,0)) AS outSpeed,
        CAST(sum(ifnull(a.`total_in_speed`,0)) AS DECIMAL(20,0)) AS totalInSpeed,
        CAST(sum(ifnull(a.`total_out_speed`,0)) AS DECIMAL(20,0)) AS totalOutSpeed,
        CAST(sum(ifnull(a.`ipv4_in_speed`,0)) AS DECIMAL(20,0)) AS ipv4InSpeed,
        CAST(sum(ifnull(a.`ipv4_out_speed`,0)) AS DECIMAL(20,0)) AS ipv4OutSpeed,
        CAST(sum(ifnull(a.`ipv6_in_speed`,0)) AS DECIMAL(20,0)) AS ipv6InSpeed,
        CAST(sum(ifnull(a.`ipv6_out_speed`,0)) AS DECIMAL(20,0)) AS ipv6OutSpeed,
        CAST(sum(ifnull(a.`total_ipv4_in_speed`,0)) AS DECIMAL(20,0)) AS totalIpv4InSpeed,
        CAST(sum(ifnull(a.`total_ipv4_out_speed`,0)) AS DECIMAL(20,0)) AS totalIpv4OutSpeed,
        CAST(sum(ifnull(a.`total_ipv6_in_speed`,0)) AS DECIMAL(20,0)) AS totalIpv6InSpeed,
        CAST(sum(ifnull(a.`total_ipv6_out_speed`,0)) AS DECIMAL(20,0)) AS totalIpv6OutSpeed,
        a.`machine_flow` AS machineFlow,
        a.`speed` AS speed,
        a.`duplex` AS duplex,
        a.`ping_dropped` AS pingDropped,
        a.business_id AS businessId,
        a.business_name AS businessName,
        a.service_sn AS serviceSn,
        a.node_name AS nodeName,
        a.revenue_method AS revenueMethod,
        a.package_bandwidth AS packageBandwidth,
        a.create_time AS createTime,
        a.update_time AS updateTime,
        a.create_by AS createBy,
        a.update_by AS updateBy,
        a.client_id AS clientId,
        a.ipV6 AS ipV6
        FROM ${tableName} a
        <!-- 动态关联表 -->
        <if test="mac == null or mac == ''">
            INNER JOIN rm_network_interface b ON a.client_id = b.client_id and a.mac = b.mac_address
            AND (b.bind_ip = 1 OR b.bind_ip = 3)
            AND b.new_flag = 1
        </if>
        <where>
            <if test="serviceSn != '' and serviceSn != null">
                and a.service_sn = #{serviceSn}
            </if>
            <if test="businessId != '' and businessId != null">
                and a.business_id = #{businessId}
            </if>
            <if test="clientId != '' and clientId != null">
                and a.client_id = #{clientId}
            </if>
            <if test="startTime != null">
                and a.create_time &gt;= #{startTime}
            </if>
            <if test="endTime != null">
                and a.create_time &lt;= #{endTime}
            </if>
            <if test="revenueMethod != null">
                and a.revenue_method = #{revenueMethod}
            </if>
            <if test="mac != null and mac != ''">
                and a.mac = #{mac}
            </if>
        </where>
        GROUP BY a.create_time DESC
    </select>

    <!-- 条件查询 -->
    <select id="getAllTraficMsg" resultType="EpsInitialTrafficData">
        SELECT
        id,
        `name` AS name,
        `mac` AS mac,
        `status` AS status,
        `type` AS type,
        `ipV4` AS 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,
        `speed` AS speed,
        `duplex` AS duplex,
        create_time AS createTime,
        update_time AS updateTime,
        create_by AS createBy,
        update_by AS updateBy,
        client_id AS clientId,
        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 AS ipV6,
        `ping_dropped` AS pingDropped
        FROM ${tableName}
        <where>
            <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>

    <update id="updateMachineTraffic" parameterType="EpsInitialTrafficData">
        update ${tableName} set machine_flow=#{machineFlow} where client_id=#{clientId} and create_time=#{createTime}
    </update>

    <select id="getTrafficListByClientIds" resultType="EpsInitialTrafficData">
        SELECT
        CAST(sum(ifnull(a.in_speed,0)) AS DECIMAL(20,0)) AS inSpeed,
        CAST(sum(ifnull(a.out_speed,0)) AS DECIMAL(20,0)) AS outSpeed,
        CAST(sum(ifnull(a.ipv4_in_speed,0)) AS DECIMAL(20,0)) AS ipv4InSpeed,
        CAST(sum(ifnull(a.ipv4_out_speed,0)) AS DECIMAL(20,0)) AS ipv4OutSpeed,
        CAST(sum(ifnull(a.ipv6_in_speed,0)) AS DECIMAL(20,0)) AS ipv6InSpeed,
        CAST(sum(ifnull(a.ipv6_out_speed,0)) AS DECIMAL(20,0)) AS ipv6OutSpeed,
        a.create_time AS createTime
        FROM ${tableName} a
        INNER JOIN rm_network_interface b ON a.client_id = b.client_id and a.mac = b.mac_address
        AND (b.bind_ip = 1 OR b.bind_ip = 3)
        AND b.new_flag = 1
        <where>
            <if test="businessId != '' and businessId != null">
                and a.business_id = #{businessId}
            </if>
            <if test="startTime != null">
                and a.create_time &gt;= #{startTime}
            </if>
            <if test="endTime != null">
                and a.create_time &lt;= #{endTime}
            </if>
            <if test="clientIds != null">
                and a.client_id in
                <foreach collection="clientIds.split(',')" item="clientId" open="(" separator="," close=")">
                    #{clientId}
                </foreach>
            </if>
        </where>
        group by a.create_time
        ORDER BY outSpeed desc
    </select>
</mapper>