<?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.project.zcustom.mapper.unit.LargeCameraMapper">

    <resultMap type="com.project.zcustom.domain.addional.LargeCamera" id="LargeCameraResult">
        <result property="id"    column="id"    />
        <result property="cameraName"    column="camera_name"    />
        <result property="projectId"    column="project_id"    />
        <result property="type"    column="type"    />
        <result property="status"    column="status"    />
        <result property="onlineFlag"    column="online_flag"    />
        <result property="connectFlag"    column="connect_flag"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectLargeCameraVo">
        select id, camera_name, project_id, type, status, online_flag, connect_flag, del_flag, create_by, create_time, update_by, update_time from large_plat_camera
    </sql>

    <select id="selectLargeCameraList" parameterType="LargeCamera" resultMap="LargeCameraResult">
        <include refid="selectLargeCameraVo"/>
        <where>
            <if test="cameraName != null  and cameraName != ''"> and camera_name like concat('%', #{cameraName}, '%')</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="onlineFlag != null  and onlineFlag != ''"> and online_flag = #{onlineFlag}</if>
            <if test="connectFlag != null  and connectFlag != ''"> and connect_flag = #{connectFlag}</if>
        </where>
    </select>

    <select id="selectLargeCameraById" parameterType="Long" resultMap="LargeCameraResult">
        <include refid="selectLargeCameraVo"/>
        where id = #{id}
    </select>

    <insert id="insertLargeCamera" parameterType="LargeCamera" useGeneratedKeys="true" keyProperty="id">
        insert into large_plat_camera
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cameraName != null">camera_name,</if>
            <if test="projectId != null">project_id,</if>
            <if test="type != null">type,</if>
            <if test="status != null">status,</if>
            <if test="onlineFlag != null">online_flag,</if>
            <if test="connectFlag != null">connect_flag,</if>
            <if test="delFlag != null">del_flag,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cameraName != null">#{cameraName},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="type != null">#{type},</if>
            <if test="status != null">#{status},</if>
            <if test="onlineFlag != null">#{onlineFlag},</if>
            <if test="connectFlag != null">#{connectFlag},</if>
            <if test="delFlag != null">#{delFlag},</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>
         </trim>
    </insert>

    <update id="updateLargeCamera" parameterType="LargeCamera">
        update large_plat_camera
        <trim prefix="SET" suffixOverrides=",">
            <if test="cameraName != null">camera_name = #{cameraName},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="status != null">status = #{status},</if>
            <if test="onlineFlag != null">online_flag = #{onlineFlag},</if>
            <if test="connectFlag != null">connect_flag = #{connectFlag},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLargeCameraById" parameterType="Long">
        delete from large_plat_camera where id = #{id}
    </delete>

    <delete id="deleteLargeCameraByIds" parameterType="String">
        delete from large_plat_camera where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="reallyDeleteByWrapper">
        DELETE FROM large_plat_camera ${ew.customSqlSegment}
    </delete>

    <select id="getCameraList" parameterType="Long" resultMap="LargeCameraResult">
        select * from large_plat_camera
        where del_flag = '0' and project_id = #{projectId}
    </select>

    <select id="getCameraNum" resultType="int">
        select count(*) from large_plat_camera
        where del_flag = '0'
    </select>

    <select id="getConnectCameraNumByProject" parameterType="Long" resultMap="LargeCameraResult">
        <include refid="selectLargeCameraVo"/>
        where connect_flag = '0' and del_flag = '0' and project_id = #{projectId}
    </select>

    <select id="getConnectOnlineCameraNum" resultType="int">
        select count(*) from large_plat_camera
        where connect_flag = '0' and del_flag = '0' and online_flag = '0'
    </select>

</mapper>
