<?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.huijy.management.mapper.CameraMapper">
    
    <resultMap type="Camera" id="CameraResult">
        <result property="cameraId"    column="camera_id"    />
        <result property="name"    column="name"    />
        <result property="ipAddres"    column="ip_addres"    />
        <result property="port"    column="port"    />
        <result property="callUrl"    column="call_url"    />
        <result property="lat"    column="lat"    />
        <result property="lng"    column="lng"    />
        <result property="onlineState"    column="online_state"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="userName"    column="user_name"    />
        <result property="password"    column="password"    />
    </resultMap>

    <sql id="selectCameraVo">
        select camera_id, name, ip_addres, port, call_url, lat, lng, online_state, create_time, update_time, user_name, password from t_camera
    </sql>

    <select id="selectCameraList" parameterType="Camera" resultMap="CameraResult">
        <include refid="selectCameraVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="ipAddres != null  and ipAddres != ''"> and ip_addres = #{ipAddres}</if>
            <if test="onlineState != null "> and online_state = #{onlineState}</if>
        </where>
    </select>
    
    <select id="selectCameraByCameraId" parameterType="Long" resultMap="CameraResult">
        <include refid="selectCameraVo"/>
        where camera_id = #{cameraId}
    </select>
        
    <insert id="insertCamera" parameterType="Camera" useGeneratedKeys="true" keyProperty="cameraId">
        insert into t_camera
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="ipAddres != null">ip_addres,</if>
            <if test="port != null">port,</if>
            <if test="callUrl != null">call_url,</if>
            <if test="lat != null">lat,</if>
            <if test="lng != null">lng,</if>
            <if test="onlineState != null">online_state,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="userName != null">user_name,</if>
            <if test="password != null">password,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="ipAddres != null">#{ipAddres},</if>
            <if test="port != null">#{port},</if>
            <if test="callUrl != null">#{callUrl},</if>
            <if test="lat != null">#{lat},</if>
            <if test="lng != null">#{lng},</if>
            <if test="onlineState != null">#{onlineState},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="userName != null">#{userName},</if>
            <if test="password != null">#{password},</if>
         </trim>
    </insert>

    <update id="updateCamera" parameterType="Camera">
        update t_camera
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="ipAddres != null">ip_addres = #{ipAddres},</if>
            <if test="port != null">port = #{port},</if>
            <if test="callUrl != null">call_url = #{callUrl},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="onlineState != null">online_state = #{onlineState},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="password != null">password = #{password},</if>
        </trim>
        where camera_id = #{cameraId}
    </update>

    <delete id="deleteCameraByCameraId" parameterType="Long">
        delete from t_camera where camera_id = #{cameraId}
    </delete>

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