<?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.enterprisepatrol.IEnterprisePatrolDao">

    <resultMap id="enterprisePatrolDTO" type="cn.com.tenlion.systembase.pojo.dtos.enterprisepatrol.EnterprisePatrolDTO">
        <result column="enterprise_patrol_id" property="enterprisePatrolId"/>
        <result column="enterprise_id" property="enterpriseId"/>
        <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="enterprisePatrolBO" type="cn.com.tenlion.systembase.pojo.bos.enterprisepatrol.EnterprisePatrolBO">
        <result column="enterprise_patrol_id" property="enterprisePatrolId"/>
        <result column="enterprise_id" property="enterpriseId"/>
        <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="enterprisePatrolPO" type="cn.com.tenlion.systembase.pojo.pos.enterprisepatrol.EnterprisePatrolPO">
        <result column="enterprise_patrol_id" property="enterprisePatrolId"/>
        <result column="enterprise_id" property="enterpriseId"/>
        <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 org_enterprise_patrol(
            enterprise_patrol_id,
            enterprise_id,
            patrol_time,
            patrol_content,
            patrol_result,
            patrol_photo,
            patrol_video,
            remake,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{enterprisePatrolId},
            #{enterpriseId},
            #{patrolTime},
            #{patrolContent},
            #{patrolResult},
            #{patrolPhoto},
            #{patrolVideo},
            #{remake},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除企业巡查记录 -->
    <update id="remove" parameterType="map">
        UPDATE
            org_enterprise_patrol
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            enterprise_patrol_id IN
        <foreach collection="enterprisePatrolIds" index="index" open="(" separator="," close=")">
            #{enterprisePatrolIds[${index}]}
        </foreach>
    </update>

    <!-- 删除企业巡查记录（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            org_enterprise_patrol
        WHERE
            enterprise_patrol_id IN
        <foreach collection="enterprisePatrolIds" index="index" open="(" separator="," close=")">
            #{enterprisePatrolIds[${index}]}
        </foreach>
    </update>

    <!-- 修改企业巡查记录 -->
    <update id="update" parameterType="map">
        UPDATE
            org_enterprise_patrol
        SET
        <if test="enterpriseId != null and enterpriseId != ''">
            enterprise_id = #{enterpriseId},
        </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},
            enterprise_patrol_id = enterprise_patrol_id
        WHERE
            enterprise_patrol_id = #{enterprisePatrolId}
    </update>

    <!-- 企业巡查记录详情 -->
    <select id="get" parameterType="map" resultMap="enterprisePatrolDTO">
        SELECT
            t1.enterprise_id,
            t1.patrol_time,
            t1.patrol_content,
            t1.patrol_result,
            t1.patrol_photo,
            t1.patrol_video,
            t1.remake,
            t1.enterprise_patrol_id
        FROM
            org_enterprise_patrol t1
        WHERE
            t1.is_delete = 0
            <if test="enterprisePatrolId != null and enterprisePatrolId != ''">
        AND
            t1.enterprise_patrol_id = #{enterprisePatrolId}
            </if>
    </select>

    <!-- 企业巡查记录详情 -->
    <select id="getBO" parameterType="map" resultMap="enterprisePatrolBO">
        SELECT
            t1.enterprise_patrol_id,
            t1.enterprise_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
            org_enterprise_patrol t1
        WHERE
            t1.is_delete = 0
            <if test="enterprisePatrolId != null and enterprisePatrolId != ''">
        AND
            t1.enterprise_patrol_id = #{enterprisePatrolId}
            </if>
    </select>

    <!-- 企业巡查记录详情 -->
    <select id="getPO" parameterType="map" resultMap="enterprisePatrolPO">
        SELECT
            t1.enterprise_patrol_id,
            t1.enterprise_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
            org_enterprise_patrol t1
        WHERE
            t1.is_delete = 0
            <if test="enterprisePatrolId != null and enterprisePatrolId != ''">
        AND
            t1.enterprise_patrol_id = #{enterprisePatrolId}
            </if>
    </select>

    <!-- 企业巡查记录列表 -->
    <select id="list" parameterType="map" resultMap="enterprisePatrolDTO">
        SELECT
            t1.enterprise_patrol_id,
            t1.enterprise_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
            org_enterprise_patrol t1
        WHERE
            t1.is_delete = 0
        <if test="enterpriseId != null and enterpriseId != ''">
            AND t1.enterprise_id = #{enterpriseId}
        </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="enterprisePatrolIds != null and enterprisePatrolIds.size > 0">
        AND
            t1.enterprise_patrol_id IN
            <foreach collection="enterprisePatrolIds" index="index" open="(" separator="," close=")">
                #{enterprisePatrolIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 企业巡查记录列表 -->
    <select id="listBO" parameterType="map" resultMap="enterprisePatrolBO">
        SELECT
            t1.enterprise_patrol_id,
            t1.enterprise_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
            org_enterprise_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="enterprisePatrolIds != null and enterprisePatrolIds.size > 0">
        AND
            t1.enterprise_patrol_id IN
            <foreach collection="enterprisePatrolIds" index="index" open="(" separator="," close=")">
                #{enterprisePatrolIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 企业巡查记录列表 -->
    <select id="listPO" parameterType="map" resultMap="enterprisePatrolPO">
        SELECT
            t1.enterprise_patrol_id,
            t1.enterprise_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
            org_enterprise_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="enterprisePatrolIds != null and enterprisePatrolIds.size > 0">
        AND
            t1.enterprise_patrol_id IN
            <foreach collection="enterprisePatrolIds" index="index" open="(" separator="," close=")">
                #{enterprisePatrolIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 企业巡查记录统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            org_enterprise_patrol t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>