<?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.xinda.iot.mapper.SpDeviceMapper">
    
    <resultMap type="CamDevice" id="CamDeviceResult">
        <result property="id"    column="id"    />
        <result property="sipId"    column="sip_id"    />
        <result property="deviceId"    column="device_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="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectCamDeviceVo">
        select id, sip_id, device_id, create_by, create_time, update_by, update_time, del_flag from iot_sip_device
    </sql>

    <select id="selectCamDeviceList" parameterType="CamDevice" resultMap="CamDeviceResult">
        <include refid="selectCamDeviceVo"/>
        <where>  
            <if test="sipId != null "> and sip_id = #{sipId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
        </where>
    </select>
    
    <select id="selectCamDeviceById" parameterType="Long" resultMap="CamDeviceResult">
        <include refid="selectCamDeviceVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCamDevice" parameterType="CamDevice" useGeneratedKeys="true" keyProperty="id">
        insert into iot_sip_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sipId != null">sip_id,</if>
            <if test="deviceId != null">device_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="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sipId != null">#{sipId},</if>
            <if test="deviceId != null">#{deviceId},</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="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateCamDevice" parameterType="CamDevice">
        update iot_sip_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="sipId != null">sip_id = #{sipId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <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="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCamDeviceById" parameterType="Long">
        delete from iot_sip_device where id = #{id}
    </delete>
    <delete id="deleteCamDeviceBySipId" parameterType="Long">
        delete from iot_sip_device where sip_id = #{sipId}
    </delete>

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