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

    <resultMap type="VideoInfo" id="VideoInfoResult">
        <result property="id" column="id"/>
        <result property="sn" column="sn"/>
        <result property="gateway" column="gateway"/>
        <result property="cameraIndex" column="camera_index"/>
        <result property="videoIndex" column="video_index"/>
        <result property="type" column="type"/>
        <result property="deviceType" column="device_type"/>
        <result property="flyIndex" column="fly_index"/>
        <result property="businessName" column="business_name"/>
    </resultMap>

    <sql id="selectVideoInfoVo">
        select id,
               sn,
               gateway,
               camera_index,
               video_index,
               type,
               device_type,
               fly_index,
               business_name
        from video_info
    </sql>

    <select id="selectVideoInfoList" parameterType="VideoInfo" resultMap="VideoInfoResult">
        <include refid="selectVideoInfoVo"/>
        <where>
            <if test="sn != null  and sn != ''">and sn = #{sn}</if>
            <if test="gateway != null  and gateway != ''">and gateway = #{gateway}</if>
            <if test="cameraIndex != null  and cameraIndex != ''">and camera_index = #{cameraIndex}</if>
            <if test="videoIndex != null  and videoIndex != ''">and video_index = #{videoIndex}</if>
            <if test="type != null  and type != ''">and type = #{type}</if>
            <if test="deviceType != null  and deviceType != ''">and device_type = #{deviceType}</if>
            <if test="flyIndex != null  and flyIndex != ''">and fly_index = #{flyIndex}</if>
            <if test="businessName != null  and businessName != ''">and business_name = #{businessName}</if>
        </where>
    </select>

    <select id="selectVideoInfoById" parameterType="Long" resultMap="VideoInfoResult">
        <include refid="selectVideoInfoVo"/>
        where id = #{id}
    </select>

    <!-- 获取视频设备信息 -->
    <select id="findVideoInfo" resultType="com.ruoyi.system.domain.VideoInfo">
        select id,
               sn,
               gateway,
               camera_index as cameraIndex,
               video_index  as videoIndex,
               type,
               device_type  as deviceType,
               fly_index    as flyIndex,
               business_name as businessName
        from video_info
        where sn = #{sn}
          and video_index = #{videoIndex}
          and type = #{type}
          and gateway = #{gateway}
    </select>

    <!-- 根据网关获取视频设备列表信息 -->
    <select id="findVideoInfoByGateway" resultType="com.ruoyi.system.domain.VideoInfo">
        select id,
               sn,
               gateway,
               camera_index,
               video_index,
               type,
               device_type,
               fly_index,
               business_name
        from video_info
        where gateway = #{gateway}
    </select>

    <!-- 获取视频设备信息 -->
    <select id="selectVideoByCondition" resultType="com.ruoyi.system.domain.VideoInfo">
        select id,
               sn,
               gateway,
               camera_index,
               video_index,
               type,
               device_type,
               fly_index,
               business_name
        from video_info
        where gateway = #{gateway}
          and type = #{condition}
    </select>

    <select id="selectGatewayByCondition" resultMap="VideoInfoResult">
        select *
        from video_info
        where sn = #{sn} limit 1
    </select>

    <insert id="insertVideoInfo" parameterType="VideoInfo" useGeneratedKeys="true" keyProperty="id">
        insert into video_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sn != null and sn != ''">sn,</if>
            <if test="gateway != null">gateway,</if>
            <if test="cameraIndex != null and cameraIndex != ''">camera_index,</if>
            <if test="videoIndex != null and videoIndex != ''">video_index,</if>
            <if test="type != null">type,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="flyIndex != null">fly_index,</if>
            <if test="businessName != null and businessName != ''">business_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sn != null and sn != ''">#{sn},</if>
            <if test="gateway != null">#{gateway},</if>
            <if test="cameraIndex != null and cameraIndex != ''">#{cameraIndex},</if>
            <if test="videoIndex != null and videoIndex != ''">#{videoIndex},</if>
            <if test="type != null">#{type},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="flyIndex != null">#{flyIndex},</if>
            <if test="businessName != null and businessName != ''">#{businessName},</if>
        </trim>
    </insert>

    <update id="updateVideoInfo" parameterType="VideoInfo">
        update video_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="sn != null and sn != ''">sn = #{sn},</if>
            <if test="gateway != null">gateway = #{gateway},</if>
            <if test="cameraIndex != null and cameraIndex != ''">camera_index = #{cameraIndex},</if>
            <if test="videoIndex != null and videoIndex != ''">video_index = #{videoIndex},</if>
            <if test="type != null">type = #{type},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="flyIndex != null">fly_index = #{flyIndex},</if>
            <if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteVideoInfoById" parameterType="Long">
        delete
        from video_info
        where id = #{id}
    </delete>

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