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

    <resultMap type="RmEpsTopologyManagement" id="RmEpsTopologyManagementResult">
        <result property="id"    column="id"    />
        <result property="switchName"    column="switch_name"    />
        <result property="clientId"    column="client_Id"    />
        <result property="switchSn"    column="switch_sn"    />
        <result property="interfaceName"    column="interface_name"    />
        <result property="connectedDeviceType"    column="connected_device_type"    />
        <result property="serverName"    column="server_name"    />
        <result property="serverSn"    column="server_sn"    />
        <result property="serverPort"    column="server_port"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="creatorId"    column="creator_id"    />
        <result property="creatorName"    column="creator_name"    />
        <result property="updaterId"    column="updater_id"    />
        <result property="updaterName"    column="updater_name"    />
        <result property="switchIpAddress"    column="switch_ip_address"    />
        <result property="peerSwitchName"    column="peer_switch_name"    />
        <result property="peerSwitchInterface"    column="peer_switch_interface"    />
        <result property="serverClientId"    column="server_client_id"    />
        <result property="peerName"    column="peerName"    />
    </resultMap>

    <sql id="selectRmEpsTopologyManagementVo">
        SELECT
            id,
            switch_name,
            client_id,
            switch_sn,
            interface_name,
            connected_device_type,
            server_name,
            server_sn,
            server_port,
            create_time,
            update_time,
            creator_id,
            creator_name,
            updater_id,
            updater_name,
            switch_ip_address,
            peer_switch_name,
            (SELECT switch_name FROM rm_switch_management WHERE client_id = rm_eps_topology_management.peer_switch_name) AS peerName,
            peer_switch_interface,
            server_client_id
        FROM rm_eps_topology_management
    </sql>

    <select id="selectRmEpsTopologyManagementList" parameterType="RmEpsTopologyManagement" resultMap="RmEpsTopologyManagementResult">
        <include refid="selectRmEpsTopologyManagementVo"/>
        <where>
            <if test="switchName != null  and switchName != ''"> and switch_name like concat('%', #{switchName}, '%')</if>
            <if test="switchSn != null  and switchSn != ''"> and switch_sn = #{switchSn}</if>
            <if test="interfaceName != null  and interfaceName != ''"> and interface_name like concat('%', #{interfaceName}, '%')</if>
            <if test="connectedDeviceType != null  and connectedDeviceType != ''"> and connected_device_type = #{connectedDeviceType}</if>
            <if test="serverName != null  and serverName != ''"> and server_name like concat('%', #{serverName}, '%')</if>
            <if test="serverSn != null  and serverSn != ''"> and server_sn = #{serverSn}</if>
            <if test="serverPort != null  and serverPort != ''"> and server_port = #{serverPort}</if>
            <if test="creatorId != null "> and creator_id = #{creatorId}</if>
            <if test="creatorName != null  and creatorName != ''"> and creator_name like concat('%', #{creatorName}, '%')</if>
            <if test="updaterId != null "> and updater_id = #{updaterId}</if>
            <if test="updaterName != null  and updaterName != ''"> and updater_name like concat('%', #{updaterName}, '%')</if>
            <if test="switchIpAddress != null  and switchIpAddress != ''"> and switch_ip_address = #{switchIpAddress}</if>
            <if test="resourceName != null  and resourceName != ''">and (switch_name like concat('%', #{resourceName}, '%') or server_name like concat('%', #{resourceName}, '%'))</if>
            <if test="peerSwitchName != null  and peerSwitchName != ''"> and peer_switch_name like concat('%', #{peerSwitchName}, '%')</if>
            <if test="peerSwitchInterface != null  and peerSwitchInterface != ''"> and peer_switch_interface = #{peerSwitchInterface}</if>
            <if test="serverClientId != null  and serverClientId != ''"> and server_client_id = #{serverClientId}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
    </select>

    <select id="selectRmEpsTopologyManagementById" parameterType="Long" resultMap="RmEpsTopologyManagementResult">
        <include refid="selectRmEpsTopologyManagementVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmEpsTopologyManagement" parameterType="RmEpsTopologyManagement" useGeneratedKeys="true" keyProperty="id">
        insert into rm_eps_topology_management
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="switchName != null">switch_name,</if>
            <if test="clientId != null">client_id,</if>
            <if test="switchSn != null">switch_sn,</if>
            <if test="interfaceName != null">interface_name,</if>
            <if test="connectedDeviceType != null">connected_device_type,</if>
            <if test="serverName != null">server_name,</if>
            <if test="serverSn != null">server_sn,</if>
            <if test="serverPort != null">server_port,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="creatorId != null">creator_id,</if>
            <if test="creatorName != null">creator_name,</if>
            <if test="updaterId != null">updater_id,</if>
            <if test="updaterName != null">updater_name,</if>
            <if test="switchIpAddress != null">switch_ip_address,</if>
            <if test="peerSwitchName != null">peer_switch_name,</if>
            <if test="peerSwitchInterface != null">peer_switch_interface,</if>
            <if test="serverClientId != null">server_client_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="switchName != null">#{switchName},</if>
            <if test="clientId != null">#{clientId},</if>
            <if test="switchSn != null">#{switchSn},</if>
            <if test="interfaceName != null">#{interfaceName},</if>
            <if test="connectedDeviceType != null">#{connectedDeviceType},</if>
            <if test="serverName != null">#{serverName},</if>
            <if test="serverSn != null">#{serverSn},</if>
            <if test="serverPort != null">#{serverPort},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="creatorId != null">#{creatorId},</if>
            <if test="creatorName != null">#{creatorName},</if>
            <if test="updaterId != null">#{updaterId},</if>
            <if test="updaterName != null">#{updaterName},</if>
            <if test="switchIpAddress != null">#{switchIpAddress},</if>
            <if test="peerSwitchName != null">#{peerSwitchName},</if>
            <if test="peerSwitchInterface != null">#{peerSwitchInterface},</if>
            <if test="serverClientId != null">#{serverClientId},</if>
        </trim>
    </insert>

    <update id="updateRmEpsTopologyManagement" parameterType="RmEpsTopologyManagement">
        update rm_eps_topology_management
        <trim prefix="SET" suffixOverrides=",">
            <if test="switchName != null">switch_name = #{switchName},</if>
            <if test="clientId != null">client_id = #{clientId},</if>
            <if test="switchSn != null">switch_sn = #{switchSn},</if>
            <if test="interfaceName != null">interface_name = #{interfaceName},</if>
            <if test="connectedDeviceType != null">connected_device_type = #{connectedDeviceType},</if>
            <if test="serverName != null">server_name = #{serverName},</if>
            <if test="serverSn != null">server_sn = #{serverSn},</if>
            <if test="serverPort != null">server_port = #{serverPort},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="creatorId != null">creator_id = #{creatorId},</if>
            <if test="creatorName != null">creator_name = #{creatorName},</if>
            <if test="updaterId != null">updater_id = #{updaterId},</if>
            <if test="updaterName != null">updater_name = #{updaterName},</if>
            <if test="switchIpAddress != null">switch_ip_address = #{switchIpAddress},</if>
            <if test="peerSwitchName != null">peer_switch_name = #{peerSwitchName},</if>
            <if test="peerSwitchInterface != null">peer_switch_interface = #{peerSwitchInterface},</if>
            <if test="serverClientId != null">server_client_id = #{serverClientId},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateRmEpsTopologyManagementByServerSn" parameterType="RmEpsTopologyManagement">
        update rm_eps_topology_management
        <trim prefix="SET" suffixOverrides=",">
            <if test="serverName != null">`server_name` = #{serverName},</if>
        </trim>
        where server_sn = #{serverSn}
    </update>
    <update id="updateRmEpsTopologyManagementBySwitchSn" parameterType="RmEpsTopologyManagement">
        update rm_eps_topology_management
        <trim prefix="SET" suffixOverrides=",">
            <if test="switchName != null">`switch_name` = #{switchName},</if>
        </trim>
        where switch_sn = #{switchSn}
    </update>


    <delete id="deleteRmEpsTopologyManagementById" parameterType="Long">
        delete from rm_eps_topology_management where id = #{id}
    </delete>

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