<?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.xunmei.core.access.mapper.CoreMonitoringTaskRegistrationMonitorMapper">

    <resultMap type="com.xunmei.core.access.domain.CoreMonitoringTaskRegistrationMonitor" id="CoreMonitoringTaskRegistrationMonitorResult">
                <result property="id" column="id"/>
                <result property="taskRegistrationId" column="task_registration_id"/>
                <result property="host" column="host"/>
                <result property="videoChannel" column="video_channel"/>
                <result property="createTime" column="create_time"/>
                <result property="createBy" column="create_by"/>
                <result property="updateTime" column="update_time"/>
                <result property="updateBy" column="update_by"/>
                <result property="delFlag" column="del_flag"/>
    </resultMap>

    <sql id="selectCoreMonitoringTaskRegistrationMonitorVo">
        select id, task_registration_id, host, video_channel, create_time, create_by, update_time, update_by, del_flag
        from core_monitoring_task_registration_monitor
    </sql>

    <select id="selectCoreMonitoringTaskRegistrationMonitorList" parameterType="com.xunmei.core.access.domain.CoreMonitoringTaskRegistrationMonitor"
            resultMap="CoreMonitoringTaskRegistrationMonitorResult">
        <include refid="selectCoreMonitoringTaskRegistrationMonitorVo"/>
        <where>
                        <if test="taskRegistrationId != null ">
                            and task_registration_id = #{taskRegistrationId}
                        </if>
                        <if test="host != null ">
                            and host = #{host}
                        </if>
                        <if test="videoChannel != null  and videoChannel != ''">
                            and video_channel = #{videoChannel}
                        </if>
        </where>
    </select>

    <select id="selectCoreMonitoringTaskRegistrationMonitorById" parameterType="String"
            resultMap="CoreMonitoringTaskRegistrationMonitorResult">
            <include refid="selectCoreMonitoringTaskRegistrationMonitorVo"/>
            where id = #{id}
    </select>
    <select id="selectTaskName" resultType="com.xunmei.core.access.vo.CoreMonitoringTaskRegistrationVO">
        SELECT
            cmtr.id as id,
            cmrt.task_name as  taskName,
            cmtr.task_start_time as taskStartTime
        FROM
            core_monitoring_retrieval_task cmrt
                LEFT JOIN core_monitoring_task_registration cmtr ON cmtr.task_id = cmrt.id
        WHERE
            cmtr.task_id =#{taskId}
    </select>
    <select id="selectMonitorByTaskRegistrationId"
            resultType="com.xunmei.core.access.vo.CoreMonitoringTaskRegistrationMonitorVO">
        SELECT
            cmtrm.id AS id,
            cmtrm.`host` AS `host`,
            cmtrm.video_channel AS videoChannel,
            sd.device_name AS hostName,
            sd1.device_name AS videoChannelName
        FROM
            core_monitoring_task_registration_monitor cmtrm
                LEFT JOIN sys_device sd ON sd.id = cmtrm.`host`
                LEFT JOIN sys_device sd1 ON sd1.host_id = sd.id
        WHERE
            cmtrm.task_registration_id =#{taskRegistrationId}
    </select>
    <select id="selectMonitorById"
            resultType="com.xunmei.core.access.vo.CoreMonitoringTaskRegistrationMonitorVO">
        SELECT
            cmtrm.id AS id,
            cmtrm.`host` AS `host`,
            cmtrm.video_channel AS videoChannel,
            sd.device_name AS hostName,
            sd1.device_name AS videoChannelName
        FROM
            core_monitoring_task_registration_monitor cmtrm
                LEFT JOIN sys_device sd ON sd.id = cmtrm.`host`
                LEFT JOIN sys_device sd1 ON sd1.host_id = sd.id
        WHERE
            cmtrm.id = #{id}
    </select>

    <insert id="insertCoreMonitoringTaskRegistrationMonitor" parameterType="com.xunmei.core.access.domain.CoreMonitoringTaskRegistrationMonitor">
        insert into core_monitoring_task_registration_monitor
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,
                    </if>
                    <if test="taskRegistrationId != null">task_registration_id,
                    </if>
                    <if test="host != null">host,
                    </if>
                    <if test="videoChannel != null">video_channel,
                    </if>
                    <if test="createTime != null">create_time,
                    </if>
                    <if test="createBy != null">create_by,
                    </if>
                    <if test="updateTime != null">update_time,
                    </if>
                    <if test="updateBy != null">update_by,
                    </if>
                    <if test="delFlag != null">del_flag,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null">#{id},
                    </if>
                    <if test="taskRegistrationId != null">#{taskRegistrationId},
                    </if>
                    <if test="host != null">#{host},
                    </if>
                    <if test="videoChannel != null">#{videoChannel},
                    </if>
                    <if test="createTime != null">#{createTime},
                    </if>
                    <if test="createBy != null">#{createBy},
                    </if>
                    <if test="updateTime != null">#{updateTime},
                    </if>
                    <if test="updateBy != null">#{updateBy},
                    </if>
                    <if test="delFlag != null">#{delFlag},
                    </if>
        </trim>
    </insert>

    <update id="updateCoreMonitoringTaskRegistrationMonitor" parameterType="com.xunmei.core.access.domain.CoreMonitoringTaskRegistrationMonitor">
        update core_monitoring_task_registration_monitor
        <trim prefix="SET" suffixOverrides=",">
                    <if test="taskRegistrationId != null">task_registration_id =
                        #{taskRegistrationId},
                    </if>
                    <if test="host != null">host =
                        #{host},
                    </if>
                    <if test="videoChannel != null">video_channel =
                        #{videoChannel},
                    </if>
                    <if test="createTime != null">create_time =
                        #{createTime},
                    </if>
                    <if test="createBy != null">create_by =
                        #{createBy},
                    </if>
                    <if test="updateTime != null">update_time =
                        #{updateTime},
                    </if>
                    <if test="updateBy != null">update_by =
                        #{updateBy},
                    </if>
                    <if test="delFlag != null">del_flag =
                        #{delFlag},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCoreMonitoringTaskRegistrationMonitorById" parameterType="String">
        delete
        from core_monitoring_task_registration_monitor where id = #{id}
    </delete>

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