<?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.AllInterfaceNameMapper">

    <resultMap type="AllInterfaceName" id="AllInterfaceNameResult">
        <result property="id"    column="id"    />
        <result property="clientId"    column="client_id"    />
        <result property="interfaceName"    column="interface_name"    />
        <result property="deviceSn"    column="device_sn"    />
        <result property="nodeName"    column="node_name"    />
        <result property="businessCode"    column="business_code"    />
        <result property="businessName"    column="business_name"    />
        <result property="resourceType"    column="resource_type"    />
        <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="switchName"    column="switch_name"    />
        <result property="interfaceDeviceType"    column="interface_device_type"    />
        <result property="serverPort"    column="server_port"    />
        <result property="switchSn"    column="switch_sn"    />
        <result property="switchIp"    column="switch_ip"    />
        <result property="serverIp"    column="server_ip"    />
    </resultMap>

    <sql id="selectAllInterfaceNameVo">
        select id, client_id, interface_name, device_sn, node_name, business_code, business_name, resource_type, create_time, update_time, create_by, update_by, switch_name, interface_device_type, server_port, switch_sn, switch_ip, server_ip from all_interface_name
    </sql>

    <select id="selectAllInterfaceNameList" parameterType="AllInterfaceName" resultMap="AllInterfaceNameResult">
        <include refid="selectAllInterfaceNameVo"/>
        <where>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="interfaceName != null  and interfaceName != ''"> and interface_name like concat('%', #{interfaceName}, '%')</if>
            <if test="deviceSn != null  and deviceSn != ''"> and device_sn = #{deviceSn}</if>
            <if test="nodeName != null  and nodeName != ''"> and node_name like concat('%', #{nodeName}, '%')</if>
            <if test="businessCode != null  and businessCode != ''"> and business_code = #{businessCode}</if>
            <if test="businessName != null  and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
            <if test="resourceType != null  and resourceType != ''"> and resource_type = #{resourceType}</if>
            <if test="switchName != null  and switchName != ''"> and switch_name like concat('%', #{switchName}, '%')</if>
            <if test="interfaceDeviceType != null  and interfaceDeviceType != ''"> and interface_device_type = #{interfaceDeviceType}</if>
            <if test="serverPort != null  and serverPort != ''"> and server_port = #{serverPort}</if>
            <if test="switchSn != null  and switchSn != ''"> and switch_sn = #{switchSn}</if>
            <if test="switchIp != null  and switchIp != ''"> and switch_ip = #{switchIp}</if>
            <if test="serverIp != null  and serverIp != ''"> and server_ip = #{serverIp}</if>
        </where>
    </select>

    <select id="selectAllInterfaceNameById" parameterType="Long" resultMap="AllInterfaceNameResult">
        <include refid="selectAllInterfaceNameVo"/>
        where id = #{id}
    </select>

    <insert id="insertAllInterfaceName" parameterType="AllInterfaceName" useGeneratedKeys="true" keyProperty="id">
        insert IGNORE into all_interface_name
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id,</if>
            <if test="interfaceName != null and interfaceName != ''">interface_name,</if>
            <if test="deviceSn != null and deviceSn != ''">device_sn,</if>
            <if test="nodeName != null">node_name,</if>
            <if test="businessCode != null">business_code,</if>
            <if test="businessName != null">business_name,</if>
            <if test="resourceType != null">resource_type,</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="switchName != null">switch_name,</if>
            <if test="interfaceDeviceType != null">interface_device_type,</if>
            <if test="serverPort != null">server_port,</if>
            <if test="switchSn != null">switch_sn,</if>
            <if test="switchIp != null">switch_ip,</if>
            <if test="serverIp != null">server_ip,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">#{clientId},</if>
            <if test="interfaceName != null and interfaceName != ''">#{interfaceName},</if>
            <if test="deviceSn != null and deviceSn != ''">#{deviceSn},</if>
            <if test="nodeName != null">#{nodeName},</if>
            <if test="businessCode != null">#{businessCode},</if>
            <if test="businessName != null">#{businessName},</if>
            <if test="resourceType != null">#{resourceType},</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="switchName != null">#{switchName},</if>
            <if test="interfaceDeviceType != null">#{interfaceDeviceType},</if>
            <if test="serverPort != null">#{serverPort},</if>
            <if test="switchSn != null">#{switchSn},</if>
            <if test="switchIp != null">#{switchIp},</if>
            <if test="serverIp != null">#{serverIp},</if>
        </trim>
    </insert>

    <update id="updateAllInterfaceName" parameterType="AllInterfaceName">
        update all_interface_name
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
            <if test="interfaceName != null and interfaceName != ''">interface_name = #{interfaceName},</if>
            <if test="deviceSn != null and deviceSn != ''">device_sn = #{deviceSn},</if>
            <if test="nodeName != null">node_name = #{nodeName},</if>
            <if test="businessCode != null">business_code = #{businessCode},</if>
            <if test="businessName != null">business_name = #{businessName},</if>
            <if test="resourceType != null">resource_type = #{resourceType},</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="switchName != null">switch_name = #{switchName},</if>
            <if test="interfaceDeviceType != null">interface_device_type = #{interfaceDeviceType},</if>
            <if test="serverPort != null">server_port = #{serverPort},</if>
            <if test="switchSn != null">switch_sn = #{switchSn},</if>
            <if test="switchIp != null">switch_ip = #{switchIp},</if>
            <if test="serverIp != null">server_ip = #{serverIp},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAllInterfaceNameById" parameterType="Long">
        delete from all_interface_name where id = #{id}
    </delete>

    <delete id="deleteAllInterfaceNameByIds" parameterType="String">
        delete from all_interface_name where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <!-- 根据接口名称批量查询 -->
    <select id="selectByNames" parameterType="AllInterfaceName" resultType="AllInterfaceName">
        SELECT
        id,
        interface_name AS interfaceName,
        client_id AS clientId,
        resource_type AS resourceType,
        device_sn AS deviceSn,
        node_name AS nodeName,
        business_code AS businessCode,
        business_name AS businessName,
        switch_name AS switchName,
        interface_device_type AS interfaceDeviceType,
        server_port AS serverPort,
        switch_sn AS switchSn,
        switch_ip AS switchIp,
        server_ip AS serverIp
        FROM
        all_interface_name
        <where>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="interfaceName != null  and interfaceName != ''"> and interface_name = #{interfaceName}</if>
            <if test="deviceSn != null  and deviceSn != ''"> and device_sn = #{deviceSn}</if>
            <if test="nodeName != null  and nodeName != ''"> and node_name = #{nodeName}</if>
            <if test="businessCode != null  and businessCode != ''"> and business_code = #{businessCode}</if>
            <if test="resourceType != null  and resourceType != ''"> and resource_type = #{resourceType}</if>
            <if test="switchName != null  and switchName != ''"> and switch_name = #{switchName}</if>
            <if test="interfaceDeviceType != null  and interfaceDeviceType != ''"> and interface_device_type = #{interfaceDeviceType}</if>
            <if test="serverPort != null  and serverPort != ''"> and server_port = #{serverPort}</if>
            <if test="switchSn != null  and switchSn != ''"> and switch_sn = #{switchSn}</if>
            <if test="switchIp != null  and switchIp != ''"> and switch_ip = #{switchIp}</if>
            <if test="serverIp != null  and serverIp != ''"> and server_ip = #{serverIp}</if>
        </where>
    </select>

    <!-- 批量插入接口名称 -->
    <insert id="batchInsert" parameterType="java.util.List">
        INSERT IGNORE INTO all_interface_name
        (
        interface_name,
        client_id,
        resource_type,
        device_sn,
        node_name,
        business_code,
        business_name,
        switch_name, interface_device_type, server_port, switch_sn, switch_ip, server_ip,
        create_time,
        update_time
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.interfaceName},
            #{item.clientId},
            #{item.resourceType},
            #{item.deviceSn},
            #{item.nodeName},
            #{item.businessCode},
            #{item.businessName},
            #{item.switchName}, #{item.interfaceDeviceType}, #{item.serverPort}, #{item.switchSn}, #{item.switchIp}, #{item.serverIp},
            NOW(),
            NOW()
            )
        </foreach>
    </insert>

    <select id="getAllDeviceSn" parameterType="AllInterfaceName" resultType="AllInterfaceName">
        SELECT
            client_id AS clientId
        FROM
            all_interface_name
        <where>
            and resource_type = '1' and client_id != ''
        </where>
            group by client_id
    </select>
    <select id="getAllSwitchSn" parameterType="AllInterfaceName" resultType="AllInterfaceName">
        SELECT
        client_id AS clientId, switch_ip switchIp
        FROM
        all_interface_name
        <where>
            and resource_type = '2' and client_id != ''
        </where>
        group by client_id
    </select>
    <update id="batchUpdate" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="" separator=";" close="">
            UPDATE all_interface_name
            SET
            business_code = #{item.businessCode},
            business_name = #{item.businessName},
            update_time = NOW(),
            client_id = #{item.clientId},
            device_sn = #{item.deviceSn},
            node_name = #{item.nodeName},
            server_port = #{item.serverPort},
            interface_device_type = #{item.interfaceDeviceType},
            switch_name = #{item.switchName},
            switch_sn = #{item.switchSn},
            switch_ip = #{item.switchIp},
            server_ip = #{item.serverIp}
            WHERE id = #{item.id}
        </foreach>
    </update>
</mapper>