<?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.logisticssafepatrol.ILogisticsSafePatrolDao">

    <resultMap id="logisticsSafePatrolDTO" type="cn.com.tenlion.systembase.pojo.dtos.logisticssafepatrol.LogisticsSafePatrolDTO">
        <result column="logistics_safe_patrol_id" property="logisticsSafePatrolId"/>
        <result column="logistics_safe_id" property="logisticsSafeId"/>
        <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"/>
    </resultMap>

    <resultMap id="logisticsSafePatrolBO" type="cn.com.tenlion.systembase.pojo.bos.logisticssafepatrol.LogisticsSafePatrolBO">
        <result column="logistics_safe_patrol_id" property="logisticsSafePatrolId"/>
        <result column="logistics_safe_id" property="logisticsSafeId"/>
        <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"/>
    </resultMap>

    <resultMap id="logisticsSafePatrolPO" type="cn.com.tenlion.systembase.pojo.pos.logisticssafepatrol.LogisticsSafePatrolPO">
        <result column="logistics_safe_patrol_id" property="logisticsSafePatrolId"/>
        <result column="logistics_safe_id" property="logisticsSafeId"/>
        <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"/>
    </resultMap>

    <!-- 新增寄递物流安全巡查 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_logistics_safe_patrol(
            logistics_safe_patrol_id,
            logistics_safe_id,
            patrol_time,
            patrol_content,
            patrol_result,
            patrol_photo,
            patrol_video,
            remake,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{logisticsSafePatrolId},
            #{logisticsSafeId},
            #{patrolTime},
            #{patrolContent},
            #{patrolResult},
            #{patrolPhoto},
            #{patrolVideo},
            #{remake},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除寄递物流安全巡查 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_logistics_safe_patrol
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            logistics_safe_patrol_id IN
        <foreach collection="logisticsSafePatrolIds" index="index" open="(" separator="," close=")">
            #{logisticsSafePatrolIds[${index}]}
        </foreach>
    </update>

    <!-- 删除寄递物流安全巡查（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_logistics_safe_patrol
        WHERE
            logistics_safe_patrol_id IN
        <foreach collection="logisticsSafePatrolIds" index="index" open="(" separator="," close=")">
            #{logisticsSafePatrolIds[${index}]}
        </foreach>
    </update>

    <!-- 修改寄递物流安全巡查 -->
    <update id="update" parameterType="map">
        UPDATE
            data_logistics_safe_patrol
        SET
        <if test="logisticsSafeId != null and logisticsSafeId != ''">
            logistics_safe_id = #{logisticsSafeId},
        </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>

        <if test="patrolTime == null or patrolTime == ''">
            patrol_time = '',
        </if>
        <if test="patrolContent == null or patrolContent == ''">
            patrol_content = '',
        </if>
        <if test="patrolResult == null or patrolResult == ''">
            patrol_result = '',
        </if>
        <if test="patrolPhoto == null or patrolPhoto == ''">
            patrol_photo = '',
        </if>
        <if test="patrolVideo == null or patrolVideo == ''">
            patrol_video = '',
        </if>
        <if test="remake == null or remake == ''">
            remake = '',
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            logistics_safe_patrol_id = logistics_safe_patrol_id
        WHERE
            logistics_safe_patrol_id = #{logisticsSafePatrolId}
    </update>

    <!-- 寄递物流安全巡查详情 -->
    <select id="get" parameterType="map" resultMap="logisticsSafePatrolDTO">
        SELECT
            t1.logistics_safe_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake,
            t1.logistics_safe_patrol_id
        FROM
            data_logistics_safe_patrol t1
        WHERE
            t1.is_delete = 0
            <if test="logisticsSafePatrolId != null and logisticsSafePatrolId != ''">
        AND
            t1.logistics_safe_patrol_id = #{logisticsSafePatrolId}
            </if>
    </select>

    <!-- 寄递物流安全巡查详情 -->
    <select id="getBO" parameterType="map" resultMap="logisticsSafePatrolBO">
        SELECT
            t1.logistics_safe_patrol_id,
            t1.logistics_safe_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake
        FROM
            data_logistics_safe_patrol t1
        WHERE
            t1.is_delete = 0
            <if test="logisticsSafePatrolId != null and logisticsSafePatrolId != ''">
        AND
            t1.logistics_safe_patrol_id = #{logisticsSafePatrolId}
            </if>
    </select>

    <!-- 寄递物流安全巡查详情 -->
    <select id="getPO" parameterType="map" resultMap="logisticsSafePatrolPO">
        SELECT
            t1.logistics_safe_patrol_id,
            t1.logistics_safe_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake
        FROM
            data_logistics_safe_patrol t1
        WHERE
            t1.is_delete = 0
            <if test="logisticsSafePatrolId != null and logisticsSafePatrolId != ''">
        AND
            t1.logistics_safe_patrol_id = #{logisticsSafePatrolId}
            </if>
    </select>

    <!-- 寄递物流安全巡查列表 -->
    <select id="list" parameterType="map" resultMap="logisticsSafePatrolDTO">
        SELECT
            t1.logistics_safe_patrol_id,
            t1.logistics_safe_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake,
            1
        FROM
            data_logistics_safe_patrol t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="logisticsSafeId != null and logisticsSafeId != ''">
        AND
            t1.logistics_safe_id = #{logisticsSafeId}
        </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="logisticsSafePatrolIds != null and logisticsSafePatrolIds.size > 0">
        AND
            t1.logistics_safe_patrol_id IN
            <foreach collection="logisticsSafePatrolIds" index="index" open="(" separator="," close=")">
                #{logisticsSafePatrolIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 寄递物流安全巡查列表 -->
    <select id="listBO" parameterType="map" resultMap="logisticsSafePatrolBO">
        SELECT
            t1.logistics_safe_patrol_id,
            t1.logistics_safe_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake
        FROM
            data_logistics_safe_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="logisticsSafePatrolIds != null and logisticsSafePatrolIds.size > 0">
        AND
            t1.logistics_safe_patrol_id IN
            <foreach collection="logisticsSafePatrolIds" index="index" open="(" separator="," close=")">
                #{logisticsSafePatrolIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 寄递物流安全巡查列表 -->
    <select id="listPO" parameterType="map" resultMap="logisticsSafePatrolPO">
        SELECT
            t1.logistics_safe_patrol_id,
            t1.logistics_safe_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake
        FROM
            data_logistics_safe_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="logisticsSafePatrolIds != null and logisticsSafePatrolIds.size > 0">
        AND
            t1.logistics_safe_patrol_id IN
            <foreach collection="logisticsSafePatrolIds" index="index" open="(" separator="," close=")">
                #{logisticsSafePatrolIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 寄递物流安全巡查统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_logistics_safe_patrol t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>