<?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.keyplacepatrol.IKeyPlacePatrolDao">

    <resultMap id="keyPlacePatrolDTO" type="cn.com.tenlion.systembase.pojo.dtos.keyplacepatrol.KeyPlacePatrolDTO">
        <result column="key_place_patrol_id" property="keyPlacePatrolId"/>
        <result column="key_place_id" property="keyPlaceId"/>
        <result column="patrol_time" property="patrolTime"/>
        <result column="patrol_content" property="patrolContent"/>
        <result column="patrol_result" property="patrolResult"/>
        <result column="patrol_photo" property="patrolPhoto"/>
        <result column="patrol_video" property="patrolVideo"/>
        <result column="remake" property="remake"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="keyPlacePatrolBO" type="cn.com.tenlion.systembase.pojo.bos.keyplacepatrol.KeyPlacePatrolBO">
        <result column="key_place_patrol_id" property="keyPlacePatrolId"/>
        <result column="key_place_id" property="keyPlaceId"/>
        <result column="patrol_time" property="patrolTime"/>
        <result column="patrol_content" property="patrolContent"/>
        <result column="patrol_result" property="patrolResult"/>
        <result column="patrol_photo" property="patrolPhoto"/>
        <result column="patrol_video" property="patrolVideo"/>
        <result column="remake" property="remake"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="keyPlacePatrolPO" type="cn.com.tenlion.systembase.pojo.pos.keyplacepatrol.KeyPlacePatrolPO">
        <result column="key_place_patrol_id" property="keyPlacePatrolId"/>
        <result column="key_place_id" property="keyPlaceId"/>
        <result column="patrol_time" property="patrolTime"/>
        <result column="patrol_content" property="patrolContent"/>
        <result column="patrol_result" property="patrolResult"/>
        <result column="patrol_photo" property="patrolPhoto"/>
        <result column="patrol_video" property="patrolVideo"/>
        <result column="remake" property="remake"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <!-- 新增重点场所巡查表 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_key_place_patrol(
            key_place_patrol_id,
            key_place_id,
            patrol_time,
            patrol_content,
            patrol_result,
            patrol_photo,
            patrol_video,
            remake,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{keyPlacePatrolId},
            #{keyPlaceId},
            #{patrolTime},
            #{patrolContent},
            #{patrolResult},
            #{patrolPhoto},
            #{patrolVideo},
            #{remake},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除重点场所巡查表 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_key_place_patrol
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            key_place_patrol_id IN
        <foreach collection="keyPlacePatrolIds" index="index" open="(" separator="," close=")">
            #{keyPlacePatrolIds[${index}]}
        </foreach>
    </update>

    <!-- 删除重点场所巡查表（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_key_place_patrol
        WHERE
            key_place_patrol_id IN
        <foreach collection="keyPlacePatrolIds" index="index" open="(" separator="," close=")">
            #{keyPlacePatrolIds[${index}]}
        </foreach>
    </update>

    <!-- 修改重点场所巡查表 -->
    <update id="update" parameterType="map">
        UPDATE
            data_key_place_patrol
        SET
        <if test="keyPlaceId != null and keyPlaceId != ''">
            key_place_id = #{keyPlaceId},
        </if>
        <if test="patrolTime != null and patrolTime != ''">
            patrol_time = #{patrolTime},
        </if>
        <if test="patrolContent != null and patrolContent != ''">
            patrol_content = #{patrolContent},
        </if>
        <if test="patrolResult != null and patrolResult != ''">
            patrol_result = #{patrolResult},
        </if>
        <if test="patrolPhoto != null and patrolPhoto != ''">
            patrol_photo = #{patrolPhoto},
        </if>
        <if test="patrolVideo != null and patrolVideo != ''">
            patrol_video = #{patrolVideo},
        </if>
        <if test="remake != null and remake != ''">
            remake = #{remake},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            key_place_patrol_id = key_place_patrol_id
        WHERE
            key_place_patrol_id = #{keyPlacePatrolId}
    </update>

    <!-- 重点场所巡查表详情 -->
    <select id="get" parameterType="map" resultMap="keyPlacePatrolDTO">
        SELECT
            t1.key_place_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake,
            t1.creator,
            t1.key_place_patrol_id
        FROM
            data_key_place_patrol t1
        WHERE
            t1.is_delete = 0
            <if test="keyPlacePatrolId != null and keyPlacePatrolId != ''">
        AND
            t1.key_place_patrol_id = #{keyPlacePatrolId}
            </if>
    </select>

    <!-- 重点场所巡查表详情 -->
    <select id="getBO" parameterType="map" resultMap="keyPlacePatrolBO">
        SELECT
            t1.key_place_patrol_id,
            t1.key_place_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            data_key_place_patrol t1
        WHERE
            t1.is_delete = 0
            <if test="keyPlacePatrolId != null and keyPlacePatrolId != ''">
        AND
            t1.key_place_patrol_id = #{keyPlacePatrolId}
            </if>
    </select>

    <!-- 重点场所巡查表详情 -->
    <select id="getPO" parameterType="map" resultMap="keyPlacePatrolPO">
        SELECT
            t1.key_place_patrol_id,
            t1.key_place_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            data_key_place_patrol t1
        WHERE
            t1.is_delete = 0
            <if test="keyPlacePatrolId != null and keyPlacePatrolId != ''">
        AND
            t1.key_place_patrol_id = #{keyPlacePatrolId}
            </if>
    </select>

    <!-- 重点场所巡查表列表 -->
    <select id="list" parameterType="map" resultMap="keyPlacePatrolDTO">
        SELECT
            t1.key_place_patrol_id,
            t1.key_place_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            1
        FROM
            data_key_place_patrol t1
        WHERE
            t1.is_delete = 0
        <if test="keyPlaceId != null and keyPlaceId != ''">
            AND t1.key_place_id = #{keyPlaceId}
        </if>
        <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="keyPlacePatrolIds != null and keyPlacePatrolIds.size > 0">
        AND
            t1.key_place_patrol_id IN
            <foreach collection="keyPlacePatrolIds" index="index" open="(" separator="," close=")">
                #{keyPlacePatrolIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 重点场所巡查表列表 -->
    <select id="listBO" parameterType="map" resultMap="keyPlacePatrolBO">
        SELECT
            t1.key_place_patrol_id,
            t1.key_place_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            data_key_place_patrol 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="keyPlacePatrolIds != null and keyPlacePatrolIds.size > 0">
        AND
            t1.key_place_patrol_id IN
            <foreach collection="keyPlacePatrolIds" index="index" open="(" separator="," close=")">
                #{keyPlacePatrolIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 重点场所巡查表列表 -->
    <select id="listPO" parameterType="map" resultMap="keyPlacePatrolPO">
        SELECT
            t1.key_place_patrol_id,
            t1.key_place_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            data_key_place_patrol 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="keyPlacePatrolIds != null and keyPlacePatrolIds.size > 0">
        AND
            t1.key_place_patrol_id IN
            <foreach collection="keyPlacePatrolIds" index="index" open="(" separator="," close=")">
                #{keyPlacePatrolIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 重点场所巡查表统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_key_place_patrol t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>