<?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.video.VideoDeviceChannelMapper">

        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.video.VideoDeviceChannel">
                    <id column="channel_id" property="channelId" />
                    <result column="channel_code" property="channelCode" />
                    <result column="channel_name" property="channelName" />
                    <result column="channel_seq" property="channelSeq" />
                    <result column="channel_sn" property="channelSn" />
                    <result column="channel_type" property="channelType" />
                    <result column="capability" property="capability" />
                    <result column="parent_id" property="parentId" />
                    <result column="status" property="status" />
                    <result column="url" property="url" />
                    <result column="img" property="img" />
        </resultMap>

        <!-- 通用查询结果列 -->
        <sql id="Base_Column_List">
        select
        channel_id, channel_code, channel_name, channel_seq, channel_sn, channel_type, capability, parent_id, status,url,img
        from video_device_channel
        </sql>


    <select id="selectVideoDeviceChannelList" parameterType="com.ruoyi.system.domain.video.VideoDeviceChannel" resultType="com.ruoyi.system.domain.video.VideoDeviceChannel">
        select
        channel_id, channel_code, channel_name, channel_seq, channel_sn, channel_type, capability, parent_id, status,type, url,img
        from video_device_channel
        <where>
        <if test="channelId != null  and channelId != ''"> and channel_id = #{channelId} </if>
        <if test="channelCode != null  and channelCode != ''"> and channel_code = #{channelCode} </if>
        <if test="channelName != null  and channelName != ''"> and channel_name like concat('%',#{channelName},'%') </if>
        <if test="channelSeq != null  and channelSeq != ''"> and channel_seq = #{channelSeq} </if>
        <if test="channelSn != null  and channelSn != ''"> and channel_sn = #{channelSn} </if>
        <if test="channelType != null  and channelType != ''"> and channel_type = #{channelType} </if>
        <if test="capability != null  and capability != ''"> and capability = #{capability} </if>
        <if test="parentId != null  and parentId != ''"> and parent_id = #{parentId} </if>
        <if test="status != null  and status != ''"> and status = #{status} </if>
        <if test="type != null and type != ''"> and type = #{type} </if>
        </where>
        order by position
    </select>

    <select id="selectVideoDeviceChannelById" parameterType="Long" resultMap="BaseResultMap">
        <include refid="Base_Column_List"/>
        where id = #{id}
    </select>

    <insert id="InsertVideoDeviceChannel" parameterType="com.ruoyi.system.domain.video.VideoDeviceChannel">
        insert into video_device_channel
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="channelId != null  and channelId != ''"> channel_id, </if>
        <if test="channelCode != null  and channelCode != ''"> channel_code, </if>
        <if test="channelName != null  and channelName != ''"> channel_name, </if>
        <if test="channelSeq != null  and channelSeq != ''"> channel_seq, </if>
        <if test="channelSn != null  and channelSn != ''"> channel_sn, </if>
        <if test="channelType != null  and channelType != ''"> channel_type, </if>
        <if test="capability != null  and capability != ''"> capability, </if>
        <if test="parentId != null  and parentId != ''"> parent_id, </if>
        <if test="status != null  and status != ''"> status, </if>
            <if test="url != null  and url != ''"> url, </if>
            <if test="img != null  and img != ''"> img, </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="channelId != null  and channelId != ''"> #{channelId}, </if>
                    <if test="channelCode != null  and channelCode != ''"> #{channelCode}, </if>
                    <if test="channelName != null  and channelName != ''"> #{channelName}, </if>
                    <if test="channelSeq != null  and channelSeq != ''"> #{channelSeq}, </if>
                    <if test="channelSn != null  and channelSn != ''"> #{channelSn}, </if>
                    <if test="channelType != null  and channelType != ''"> #{channelType}, </if>
                    <if test="capability != null  and capability != ''"> #{capability}, </if>
                    <if test="parentId != null  and parentId != ''"> #{parentId}, </if>
                    <if test="status != null  and status != ''"> #{status}, </if>
                    <if test="url != null  and url != ''"> #{url}, </if>
                    <if test="img != null  and img != ''"> #{img}, </if>
        </trim>
    </insert>

    <update id="UpdateVideoDeviceChannel" parameterType="com.ruoyi.system.domain.video.VideoDeviceChannel">
        update video_device_channel
        <trim prefix="SET" suffixOverrides=",">
                    <if test="channelCode != null"> channel_code = #{channelCode}, </if>
                    <if test="channelName != null"> channel_name = #{channelName}, </if>
                    <if test="channelSeq != null"> channel_seq = #{channelSeq}, </if>
                    <if test="channelSn != null"> channel_sn = #{channelSn}, </if>
                    <if test="channelType != null"> channel_type = #{channelType}, </if>
                    <if test="capability != null"> capability = #{capability}, </if>
                    <if test="parentId != null"> parent_id = #{parentId}, </if>
                    <if test="status != null"> status = #{status}, </if>
                    <if test="url != null"> url = #{url}, </if>
                    <if test="img != null"> img = #{img}, </if>
                    <if test="type != null"> type = #{type}, </if>
        </trim>
        where channel_id = #{channelId}
    </update>

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

    <select id="selectChannelList" parameterType="com.ruoyi.system.domain.video.VideoDeviceChannel" resultType="com.ruoyi.system.domain.video.ext.ChannelUrlInfo">
        select
        channel_id, channel_code, channel_name, status,url,img, type
        from video_device_channel
        <where>
            <if test="channelId != null  and channelId != ''"> and channel_id = #{channelId} </if>
            <if test="channelCode != null  and channelCode != ''"> and channel_code = #{channelCode} </if>
            <if test="channelName != null  and channelName != ''"> and channel_name like concat('%',#{channelName},'%') </if>
            <if test="channelSeq != null  and channelSeq != ''"> and channel_seq = #{channelSeq} </if>
            <if test="channelSn != null  and channelSn != ''"> and channel_sn = #{channelSn} </if>
            <if test="channelType != null  and channelType != ''"> and channel_type = #{channelType} </if>
            <if test="capability != null  and capability != ''"> and capability = #{capability} </if>
            <if test="parentId != null  and parentId != ''"> and parent_id = #{parentId} </if>
            <if test="status != null  and status != ''"> and status = #{status} </if>
            <if test="type != null  and type != ''"> and type = #{type} </if>
        </where>
        order by position
    </select>

    <update id="UpdateDatabaseInfo" parameterType="com.ruoyi.system.domain.video.VideoDeviceChannel">
        update video_device_channel
        <trim prefix="SET" suffixOverrides=",">
            <if test="status != null"> status = #{status}, </if>
            <if test="url != null"> url = #{url}, </if>
            <if test="img != null"> img = #{img}, </if>
        </trim>
        where channel_code = #{channelCode}
    </update>

    <select id="getVideoCount" parameterType="String" resultType="integer">
        select count(*)
        from video_device_channel
        <where>
            status = 1
            <if test="type != null  and type != ''"> and type = #{type} </if>
        </where>
    </select>

    <select id="getCount" parameterType="String" resultType="integer">
        select count(*)
        from video_device_channel
        <where>
            <if test="type != null  and type != ''"> and type = #{type} </if>
        </where>
    </select>

    <update id="position">
        UPDATE video_device_channel
        SET position = #{position} WHERE channel_id = #{channelId}
    </update>

    <select id="positionById" parameterType="String" resultType="integer">
        select position
        from video_device_channel
        where channel_id = #{channelId}
    </select>


</mapper>
