<?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="cn.com.tenlion.systembase.dao.publicvideo.IPublicVideoDao">

    <resultMap id="publicVideoDTO" type="cn.com.tenlion.systembase.pojo.dtos.publicvideo.PublicVideoDTO">
        <result column="public_video_id" property="publicVideoId"/>
        <result column="rural_name" property="ruralName"/>
        <result column="rural_phone" property="ruralPhone"/>
        <result column="rural_area" property="ruralArea"/>
        <result column="rural_population" property="ruralPopulation"/>
        <result column="public_camera" property="publicCamera"/>
        <result column="hd_camera" property="hdCamera"/>
        <result column="rural_camera" property="ruralCamera"/>
        <result column="day_camera" property="dayCamera"/>
        <result column="square_camera" property="squareCamera"/>
        <result column="hundred_camera" property="hundredCamera"/>
        <result column="location" property="location"/>
        <result column="location_code" property="locationCode"/>
        <result column="grid" property="grid"/>
    </resultMap>

    <resultMap id="publicVideoBO" type="cn.com.tenlion.systembase.pojo.bos.publicvideo.PublicVideoBO">
        <result column="public_video_id" property="publicVideoId"/>
        <result column="rural_name" property="ruralName"/>
        <result column="rural_phone" property="ruralPhone"/>
        <result column="rural_area" property="ruralArea"/>
        <result column="rural_population" property="ruralPopulation"/>
        <result column="public_camera" property="publicCamera"/>
        <result column="hd_camera" property="hdCamera"/>
        <result column="rural_camera" property="ruralCamera"/>
        <result column="day_camera" property="dayCamera"/>
        <result column="square_camera" property="squareCamera"/>
        <result column="hundred_camera" property="hundredCamera"/>
    </resultMap>

    <resultMap id="publicVideoPO" type="cn.com.tenlion.systembase.pojo.pos.publicvideo.PublicVideoPO">
        <result column="public_video_id" property="publicVideoId"/>
        <result column="rural_name" property="ruralName"/>
        <result column="rural_phone" property="ruralPhone"/>
        <result column="rural_area" property="ruralArea"/>
        <result column="rural_population" property="ruralPopulation"/>
        <result column="public_camera" property="publicCamera"/>
        <result column="hd_camera" property="hdCamera"/>
        <result column="rural_camera" property="ruralCamera"/>
        <result column="day_camera" property="dayCamera"/>
        <result column="square_camera" property="squareCamera"/>
        <result column="hundred_camera" property="hundredCamera"/>
    </resultMap>

    <!-- 新增城乡社区公共安全视频监控 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_public_video(
            public_video_id,
            rural_name,
            rural_phone,
            rural_area,
            rural_population,
            public_camera,
            hd_camera,
            rural_camera,
            day_camera,
            square_camera,
            hundred_camera,
            location,
            location_code,
            grid,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{publicVideoId},
            #{ruralName},
            #{ruralPhone},
            #{ruralArea},
            #{ruralPopulation},
            #{publicCamera},
            #{hdCamera},
            #{ruralCamera},
            #{dayCamera},
            #{squareCamera},
            #{hundredCamera},
            #{location},
            #{locationCode},
            #{grid},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除城乡社区公共安全视频监控 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_public_video
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            public_video_id IN
        <foreach collection="publicVideoIds" index="index" open="(" separator="," close=")">
            #{publicVideoIds[${index}]}
        </foreach>
    </update>

    <!-- 删除城乡社区公共安全视频监控（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_public_video
        WHERE
            public_video_id IN
        <foreach collection="publicVideoIds" index="index" open="(" separator="," close=")">
            #{publicVideoIds[${index}]}
        </foreach>
    </update>

    <!-- 修改城乡社区公共安全视频监控 -->
    <update id="update" parameterType="map">
        UPDATE
            data_public_video
        SET
        <if test="ruralName != null and ruralName != ''">
            rural_name = #{ruralName},
        </if>
        <if test="ruralPhone != null and ruralPhone != ''">
            rural_phone = #{ruralPhone},
        </if>
        <if test="ruralArea != null">
            rural_area = #{ruralArea},
        </if>
        <if test="ruralPopulation != null">
            rural_population = #{ruralPopulation},
        </if>
        <if test="publicCamera != null">
            public_camera = #{publicCamera},
        </if>
        <if test="hdCamera != null">
            hd_camera = #{hdCamera},
        </if>
        <if test="ruralCamera != null">
            rural_camera = #{ruralCamera},
        </if>
        <if test="dayCamera != null">
            day_camera = #{dayCamera},
        </if>
        <if test="squareCamera != null">
            square_camera = #{squareCamera},
        </if>
        <if test="hundredCamera != null">
            hundred_camera = #{hundredCamera},
        </if>
        <if test="location != null and location != ''">
            location = #{location},
        </if>
        <if test="locationCode != null and locationCode != ''">
            location_code = #{locationCode},
        </if>
        <if test="grid != null and grid != ''">
            grid = #{grid},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            public_video_id = public_video_id
        WHERE
            public_video_id = #{publicVideoId}
    </update>

    <!-- 城乡社区公共安全视频监控详情 -->
    <select id="get" parameterType="map" resultMap="publicVideoDTO">
        SELECT
            t1.rural_name,
            t1.rural_phone,
            t1.rural_area,
            t1.rural_population,
            t1.public_camera,
            t1.hd_camera,
            t1.rural_camera,
            t1.day_camera,
            t1.square_camera,
            t1.hundred_camera,
            t1.location,
            t1.location_code,
            t1.grid,
            t1.public_video_id
        FROM
            data_public_video t1
        WHERE
            t1.is_delete = 0
            <if test="publicVideoId != null and publicVideoId != ''">
        AND
            t1.public_video_id = #{publicVideoId}
            </if>
    </select>

    <!-- 城乡社区公共安全视频监控详情 -->
    <select id="getBO" parameterType="map" resultMap="publicVideoBO">
        SELECT
            t1.public_video_id,
            t1.rural_name,
            t1.rural_phone,
            t1.rural_area,
            t1.rural_population,
            t1.public_camera,
            t1.hd_camera,
            t1.rural_camera,
            t1.day_camera,
            t1.square_camera,
            t1.hundred_camera
        FROM
            data_public_video t1
        WHERE
            t1.is_delete = 0
            <if test="publicVideoId != null and publicVideoId != ''">
        AND
            t1.public_video_id = #{publicVideoId}
            </if>
    </select>

    <!-- 城乡社区公共安全视频监控详情 -->
    <select id="getPO" parameterType="map" resultMap="publicVideoPO">
        SELECT
            t1.public_video_id,
            t1.rural_name,
            t1.rural_phone,
            t1.rural_area,
            t1.rural_population,
            t1.public_camera,
            t1.hd_camera,
            t1.rural_camera,
            t1.day_camera,
            t1.square_camera,
            t1.hundred_camera
        FROM
            data_public_video t1
        WHERE
            t1.is_delete = 0
            <if test="publicVideoId != null and publicVideoId != ''">
        AND
            t1.public_video_id = #{publicVideoId}
            </if>
    </select>

    <!-- 城乡社区公共安全视频监控列表 -->
    <select id="list" parameterType="map" resultMap="publicVideoDTO">
        SELECT
            t1.public_video_id,
            t1.rural_name,
            t1.rural_phone,
            t1.rural_area,
            t1.rural_population,
            t1.public_camera,
            t1.hd_camera,
            t1.rural_camera,
            t1.day_camera,
            t1.square_camera,
            t1.hundred_camera,
            t1.location,
            t1.location_code,
            t1.grid,
            1
        FROM
            data_public_video t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.rural_name LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="areaCode != null and areaCode != ''">
            AND t1.location_code = #{areaCode}
        </if>
        <if test="areaCodeLike != null and areaCodeLike != ''">
            AND t1.location_code LIKE CONCAT(#{areaCodeLike}, '%')
        </if>
        <if test="grid != null and grid != ''">
            AND t1.grid = #{grid}
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="publicVideoIds != null and publicVideoIds.size > 0">
        AND
            t1.public_video_id IN
            <foreach collection="publicVideoIds" index="index" open="(" separator="," close=")">
                #{publicVideoIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 城乡社区公共安全视频监控列表 -->
    <select id="listBO" parameterType="map" resultMap="publicVideoBO">
        SELECT
            t1.public_video_id,
            t1.rural_name,
            t1.rural_phone,
            t1.rural_area,
            t1.rural_population,
            t1.public_camera,
            t1.hd_camera,
            t1.rural_camera,
            t1.day_camera,
            t1.square_camera,
            t1.hundred_camera
        FROM
            data_public_video t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="publicVideoIds != null and publicVideoIds.size > 0">
        AND
            t1.public_video_id IN
            <foreach collection="publicVideoIds" index="index" open="(" separator="," close=")">
                #{publicVideoIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 城乡社区公共安全视频监控列表 -->
    <select id="listPO" parameterType="map" resultMap="publicVideoPO">
        SELECT
            t1.public_video_id,
            t1.rural_name,
            t1.rural_phone,
            t1.rural_area,
            t1.rural_population,
            t1.public_camera,
            t1.hd_camera,
            t1.rural_camera,
            t1.day_camera,
            t1.square_camera,
            t1.hundred_camera
        FROM
            data_public_video t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="publicVideoIds != null and publicVideoIds.size > 0">
        AND
            t1.public_video_id IN
            <foreach collection="publicVideoIds" index="index" open="(" separator="," close=")">
                #{publicVideoIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 城乡社区公共安全视频监控统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_public_video t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>