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

    <resultMap type="EpsServerRevenueConfig" id="EpsServerRevenueConfigResult">
        <result property="id"    column="id"    />
        <result property="nodeName"    column="node_name"    />
        <result property="revenueMethod"    column="revenue_method"    />
        <result property="hardwareSn"    column="hardware_sn"    />
        <result property="trafficPort"    column="traffic_port"    />
        <result property="bandwidth95"    column="bandwidth_95"    />
        <result property="packageBandwidth"    column="package_bandwidth"    />
        <result property="updateTime"    column="update_time"    />
        <result property="businessName"    column="business_name"    />
        <result property="businessCode"    column="business_code"    />
        <result property="registrationStatus"    column="registration_status"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="changed"    column="changed"    />
        <result property="serverIp"    column="server_ip"    />
    </resultMap>

    <sql id="selectEpsServerRevenueConfigVo">
        select id, node_name, revenue_method, hardware_sn, traffic_port, bandwidth_95, package_bandwidth, update_time, business_name, business_code, registration_status, create_by, update_by, create_time, changed, server_ip from eps_server_revenue_config
    </sql>

    <select id="selectEpsServerRevenueConfigList" parameterType="EpsServerRevenueConfig" resultMap="EpsServerRevenueConfigResult">
        <include refid="selectEpsServerRevenueConfigVo"/>
        <where>
            and registration_status = "1"
            <if test="nodeName != null  and nodeName != ''"> and node_name like concat('%', #{nodeName}, '%')</if>
            <if test="revenueMethod != null  and revenueMethod != ''"> and revenue_method = #{revenueMethod}</if>
            <if test="hardwareSn != null  and hardwareSn != ''"> and hardware_sn = #{hardwareSn}</if>
            <if test="trafficPort != null  and trafficPort != ''"> and traffic_port = #{trafficPort}</if>
            <if test="bandwidth95 != null "> and bandwidth_95 = #{bandwidth95}</if>
            <if test="packageBandwidth != null "> and package_bandwidth = #{packageBandwidth}</if>
            <if test="businessName != null  and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
            <if test="businessCode != null  and businessCode != ''"> and business_code = #{businessCode}</if>
            <if test="changed != null  and changed != ''"> and changed = #{changed}</if>
            <if test="serverIp != null  and serverIp != ''"> and server_ip = #{serverIp}</if>
        </where>
    </select>

    <select id="selectEpsServerRevenueConfigById" parameterType="Long" resultMap="EpsServerRevenueConfigResult">
        <include refid="selectEpsServerRevenueConfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertEpsServerRevenueConfig" parameterType="EpsServerRevenueConfig">
        insert into eps_server_revenue_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="nodeName != null">node_name,</if>
            <if test="revenueMethod != null">revenue_method,</if>
            <if test="hardwareSn != null">hardware_sn,</if>
            <if test="trafficPort != null">traffic_port,</if>
            <if test="bandwidth95 != null">bandwidth_95,</if>
            <if test="packageBandwidth != null">package_bandwidth,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="businessName != null">business_name,</if>
            <if test="businessCode != null">business_code,</if>
            <if test="registrationStatus != null">registration_status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="changed != null">changed,</if>
            <if test="serverIp != null">server_ip,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="nodeName != null">#{nodeName},</if>
            <if test="revenueMethod != null">#{revenueMethod},</if>
            <if test="hardwareSn != null">#{hardwareSn},</if>
            <if test="trafficPort != null">#{trafficPort},</if>
            <if test="bandwidth95 != null">#{bandwidth95},</if>
            <if test="packageBandwidth != null">#{packageBandwidth},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="businessName != null">#{businessName},</if>
            <if test="businessCode != null">#{businessCode},</if>
            <if test="registrationStatus != null">#{registrationStatus},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="changed != null">#{changed},</if>
            <if test="serverIp != null">#{serverIp},</if>
        </trim>
    </insert>

    <update id="updateEpsServerRevenueConfig" parameterType="EpsServerRevenueConfig">
        update eps_server_revenue_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="nodeName != null">node_name = #{nodeName},</if>
            <if test="revenueMethod != null">revenue_method = #{revenueMethod},</if>
            <if test="hardwareSn != null">hardware_sn = #{hardwareSn},</if>
            <if test="trafficPort != null">traffic_port = #{trafficPort},</if>
            <if test="bandwidth95 != null">bandwidth_95 = #{bandwidth95},</if>
            <if test="packageBandwidth != null">package_bandwidth = #{packageBandwidth},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="businessName != null">business_name = #{businessName},</if>
            <if test="businessCode != null">business_code = #{businessCode},</if>
            <if test="registrationStatus != null">registration_status = #{registrationStatus},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="changed != null">changed = #{changed},</if>
            <if test="serverIp != null">server_ip = #{serverIp},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateEpsServerRevenueConfigByServerSn" parameterType="EpsServerRevenueConfig">
        update eps_server_revenue_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="nodeName != null">node_name = #{nodeName},</if>
        </trim>
        where hardware_sn = #{hardwareSn}
    </update>

    <delete id="deleteEpsServerRevenueConfigById" parameterType="Long">
        delete from eps_server_revenue_config where id = #{id}
    </delete>

    <delete id="deleteEpsServerRevenueConfigByIds" parameterType="String">
        delete from eps_server_revenue_config where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getNodeMsgByIp" parameterType="String" resultType="java.util.Map">
        SELECT
            rrr.hardware_sn AS hardwareSn,
            rrr.resource_name AS resourceName,
            esrc.revenue_method AS revenueMethod,
            esrc.business_code AS businessCode,
            esrc.business_name AS businessName,
            esrc.package_bandwidth AS packageBandwidth
        FROM
        rm_resource_registration rrr
        LEFT JOIN
        eps_server_revenue_config esrc
        ON
        rrr.hardware_sn = esrc.hardware_sn
        <where>
            and rrr.registration_status = '1'
            and rrr.ip_address = #{ipAddress}
        </where>
    </select>

    <select id="getNodeMsgBySn" parameterType="String" resultType="java.util.Map">
        SELECT
        rrr.hardware_sn AS hardwareSn,
        rrr.resource_name AS resourceName,
        esrc.revenue_method AS revenueMethod,
        esrc.business_code AS businessCode,
        esrc.business_name AS businessName,
        esrc.package_bandwidth AS packageBandwidth
        FROM
        rm_resource_registration rrr
        LEFT JOIN
        eps_server_revenue_config esrc
        ON
        rrr.hardware_sn = esrc.hardware_sn
        <where>
            and rrr.registration_status = '1'
            and rrr.hardware_sn = #{hardwareSn}
        </where>
    </select>

    <select id="countBySn" parameterType="String">
        <include refid="selectEpsServerRevenueConfigVo"/>
        where hardware_sn = #{hardwareSn}
    </select>

    <select id="countBusinessByTraffic" resultType="java.lang.Integer">
        select count(1) from eps_server_revenue_config a left join rm_resource_registration b on a.hardware_sn=b.hardware_sn where a.revenue_method = '1' and b.online_status='1'
    </select>
    <select id="countDeviceNumTop5" resultType="java.util.Map">
        select count(1) total,a.business_name businessName from eps_server_revenue_config a left join rm_resource_registration b on a.hardware_sn=b.hardware_sn where a.revenue_method = '1' and b.online_status='1' group by a.business_name order by total desc limit 5
    </select>
</mapper>