<?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.cmvr.device.mapper.DeDeviceTerminalConfigMapper">
    
    <resultMap type="DeDeviceTerminalConfig" id="DeDeviceTerminalConfigResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remake"    column="remake"    />
        <result property="name"    column="name"    />
        <result property="host"    column="host"    />
        <result property="port"    column="port"    />
        <result property="status"    column="status"    />
        <result property="description"    column="description"    />
        <result property="quicNodeId"    column="quic_node_id"    />
        <result property="quicObservedIp"    column="quic_observed_ip"    />
        <result property="quicSessionId"    column="quic_session_id"    />
        <result property="quicBootId"    column="quic_boot_id"    />
        <result property="quicSoftwareVersion"    column="quic_software_version"    />
        <result property="quicOnlineStatus"    column="quic_online_status"    />
        <result property="quicLastHeartbeatTime"    column="quic_last_heartbeat_time"    />
    </resultMap>

    <sql id="selectDeDeviceTerminalConfigVo">
        select id, create_by, create_time, update_by, update_time, remake, name, host, port, status, description,
               quic_node_id, quic_observed_ip, quic_session_id, quic_boot_id, quic_software_version,
               quic_online_status, quic_last_heartbeat_time
        from de_device_terminal_config
    </sql>

    <select id="selectDeDeviceTerminalConfigList" parameterType="DeDeviceTerminalConfig" resultMap="DeDeviceTerminalConfigResult">
        <include refid="selectDeDeviceTerminalConfigVo"/>
        <where>  
            <if test="remake != null  and remake != ''"> and remake = #{remake}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="host != null  and host != ''"> and host = #{host}</if>
            <if test="port != null "> and port = #{port}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="quicNodeId != null  and quicNodeId != ''"> and quic_node_id = #{quicNodeId}</if>
            <if test="quicOnlineStatus != null  and quicOnlineStatus != ''"> and quic_online_status = #{quicOnlineStatus}</if>
        </where>
    </select>

    <select id="selectByQuicNodeId" resultMap="DeDeviceTerminalConfigResult">
        <include refid="selectDeDeviceTerminalConfigVo"/>
        where quic_node_id = #{quicNodeId}
        limit 1
    </select>
    
    <select id="selectDeDeviceTerminalConfigById" parameterType="String" resultMap="DeDeviceTerminalConfigResult">
        <include refid="selectDeDeviceTerminalConfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertDeDeviceTerminalConfig" parameterType="DeDeviceTerminalConfig">
        insert into de_device_terminal_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remake != null">remake,</if>
            <if test="name != null">name,</if>
            <if test="host != null">host,</if>
            <if test="port != null">port,</if>
            <if test="status != null">status,</if>
            <if test="description != null">description,</if>
            <if test="quicNodeId != null">quic_node_id,</if>
            <if test="quicOnlineStatus != null">quic_online_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remake != null">#{remake},</if>
            <if test="name != null">#{name},</if>
            <if test="host != null">#{host},</if>
            <if test="port != null">#{port},</if>
            <if test="status != null">#{status},</if>
            <if test="description != null">#{description},</if>
            <if test="quicNodeId != null">#{quicNodeId},</if>
            <if test="quicOnlineStatus != null">#{quicOnlineStatus},</if>
         </trim>
    </insert>

    <update id="updateDeDeviceTerminalConfig" parameterType="DeDeviceTerminalConfig">
        update de_device_terminal_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remake != null">remake = #{remake},</if>
            <if test="name != null">name = #{name},</if>
            <if test="host != null">host = #{host},</if>
            <if test="port != null">port = #{port},</if>
            <if test="status != null">status = #{status},</if>
            <if test="description != null">description = #{description},</if>
            <if test="quicNodeId != null">quic_node_id = #{quicNodeId},</if>
            <if test="quicOnlineStatus != null">quic_online_status = #{quicOnlineStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateQuicRuntimeState">
        update de_device_terminal_config
        <set>
            <if test="host != null and host != ''">host = #{host},</if>
            <if test="port != null">port = #{port},</if>
            quic_observed_ip = #{observedIp},
            quic_session_id = #{sessionId},
            quic_boot_id = #{bootId},
            quic_software_version = #{softwareVersion},
            quic_online_status = #{onlineStatus},
            quic_last_heartbeat_time = #{lastHeartbeatTime},
            update_time = now()
        </set>
        where id = #{id}
    </update>

    <delete id="deleteDeDeviceTerminalConfigById" parameterType="String">
        delete from de_device_terminal_config where id = #{id}
    </delete>

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