<?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.keyareacheckrenovation.IKeyAreaCheckRenovationDao">

    <resultMap id="keyAreaCheckRenovationDTO" type="cn.com.tenlion.systembase.pojo.dtos.keyareacheckrenovation.KeyAreaCheckRenovationDTO">
        <result column="key_area_check_renovation_id" property="keyAreaCheckRenovationId"/>
        <result column="security_area" property="securityArea"/>
        <result column="security_question" property="securityQuestion"/>
        <result column="security_question_name" property="securityQuestionName"/>
        <result column="security_question_code" property="securityQuestionCode"/>
        <result column="involve_area_type" property="involveAreaType"/>
        <result column="involve_area_type_name" property="involveAreaTypeName"/>
        <result column="involve_area_type_code" property="involveAreaTypeCode"/>
        <result column="involve_area_range" property="involveAreaRange"/>
        <result column="renovation_lead_dept" property="renovationLeadDept"/>
        <result column="renovation_join_dept" property="renovationJoinDept"/>
        <result column="lead_dept_man" property="leadDeptMan"/>
        <result column="lead_dept_phone" property="leadDeptPhone"/>
        <result column="rectification_time" property="rectificationTime"/>
        <result column="renovation_criminal_count" property="renovationCriminalCount"/>
        <result column="renovation_security_count" property="renovationSecurityCount"/>
        <result column="renovation_situationw" property="renovationSituationw"/>
        <result column="effect_evaluation" property="effectEvaluation"/>
        <result column="effect_evaluation_name" property="effectEvaluationName"/>
        <result column="effect_evaluation_code" property="effectEvaluationCode"/>
        <result column="location" property="location"/>
        <result column="location_code" property="locationCode"/>
        <result column="grid" property="grid"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
    </resultMap>

    <resultMap id="keyAreaCheckRenovationBO" type="cn.com.tenlion.systembase.pojo.bos.keyareacheckrenovation.KeyAreaCheckRenovationBO">
        <result column="key_area_check_renovation_id" property="keyAreaCheckRenovationId"/>
        <result column="security_area" property="securityArea"/>
        <result column="security_question" property="securityQuestion"/>
        <result column="security_question_name" property="securityQuestionName"/>
        <result column="security_question_code" property="securityQuestionCode"/>
        <result column="involve_area_type" property="involveAreaType"/>
        <result column="involve_area_type_name" property="involveAreaTypeName"/>
        <result column="involve_area_type_code" property="involveAreaTypeCode"/>
        <result column="involve_area_range" property="involveAreaRange"/>
        <result column="renovation_lead_dept" property="renovationLeadDept"/>
        <result column="renovation_join_dept" property="renovationJoinDept"/>
        <result column="lead_dept_man" property="leadDeptMan"/>
        <result column="lead_dept_phone" property="leadDeptPhone"/>
        <result column="rectification_time" property="rectificationTime"/>
        <result column="renovation_criminal_count" property="renovationCriminalCount"/>
        <result column="renovation_security_count" property="renovationSecurityCount"/>
        <result column="renovation_situationw" property="renovationSituationw"/>
        <result column="effect_evaluation" property="effectEvaluation"/>
        <result column="effect_evaluation_name" property="effectEvaluationName"/>
        <result column="effect_evaluation_code" property="effectEvaluationCode"/>
    </resultMap>

    <resultMap id="keyAreaCheckRenovationPO" type="cn.com.tenlion.systembase.pojo.pos.keyareacheckrenovation.KeyAreaCheckRenovationPO">
        <result column="key_area_check_renovation_id" property="keyAreaCheckRenovationId"/>
        <result column="security_area" property="securityArea"/>
        <result column="security_question" property="securityQuestion"/>
        <result column="security_question_name" property="securityQuestionName"/>
        <result column="security_question_code" property="securityQuestionCode"/>
        <result column="involve_area_type" property="involveAreaType"/>
        <result column="involve_area_type_name" property="involveAreaTypeName"/>
        <result column="involve_area_type_code" property="involveAreaTypeCode"/>
        <result column="involve_area_range" property="involveAreaRange"/>
        <result column="renovation_lead_dept" property="renovationLeadDept"/>
        <result column="renovation_join_dept" property="renovationJoinDept"/>
        <result column="lead_dept_man" property="leadDeptMan"/>
        <result column="lead_dept_phone" property="leadDeptPhone"/>
        <result column="rectification_time" property="rectificationTime"/>
        <result column="renovation_criminal_count" property="renovationCriminalCount"/>
        <result column="renovation_security_count" property="renovationSecurityCount"/>
        <result column="renovation_situationw" property="renovationSituationw"/>
        <result column="effect_evaluation" property="effectEvaluation"/>
        <result column="effect_evaluation_name" property="effectEvaluationName"/>
        <result column="effect_evaluation_code" property="effectEvaluationCode"/>
    </resultMap>

    <!-- 新增重点地区排查整治 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_key_area_check_renovation(
            key_area_check_renovation_id,
            security_area,
            security_question,
            security_question_name,
            security_question_code,
            involve_area_type,
            involve_area_type_name,
            involve_area_type_code,
            involve_area_range,
            renovation_lead_dept,
            renovation_join_dept,
            lead_dept_man,
            lead_dept_phone,
            rectification_time,
            renovation_criminal_count,
            renovation_security_count,
            renovation_situationw,
            effect_evaluation,
            effect_evaluation_name,
            effect_evaluation_code,
            location,
            location_code,
            grid,
            longitude,
            latitude,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{keyAreaCheckRenovationId},
            #{securityArea},
            #{securityQuestion},
            #{securityQuestionName},
            #{securityQuestionCode},
            #{involveAreaType},
            #{involveAreaTypeName},
            #{involveAreaTypeCode},
            #{involveAreaRange},
            #{renovationLeadDept},
            #{renovationJoinDept},
            #{leadDeptMan},
            #{leadDeptPhone},
            #{rectificationTime},
            #{renovationCriminalCount},
            #{renovationSecurityCount},
            #{renovationSituationw},
            #{effectEvaluation},
            #{effectEvaluationName},
            #{effectEvaluationCode},
            #{location},
            #{locationCode},
            #{grid},
            #{longitude},
            #{latitude},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除重点地区排查整治 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_key_area_check_renovation
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            key_area_check_renovation_id IN
        <foreach collection="keyAreaCheckRenovationIds" index="index" open="(" separator="," close=")">
            #{keyAreaCheckRenovationIds[${index}]}
        </foreach>
    </update>

    <!-- 删除重点地区排查整治（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_key_area_check_renovation
        WHERE
            key_area_check_renovation_id IN
        <foreach collection="keyAreaCheckRenovationIds" index="index" open="(" separator="," close=")">
            #{keyAreaCheckRenovationIds[${index}]}
        </foreach>
    </update>

    <!-- 修改重点地区排查整治 -->
    <update id="update" parameterType="map">
        UPDATE
            data_key_area_check_renovation
        SET
        <if test="securityArea != null and securityArea != ''">
            security_area = #{securityArea},
        </if>
        <if test="securityQuestion != null">
            security_question = #{securityQuestion},
        </if>
        <if test="securityQuestionName != null and securityQuestionName != ''">
            security_question_name = #{securityQuestionName},
        </if>
        <if test="securityQuestionCode != null and securityQuestionCode != ''">
            security_question_code = #{securityQuestionCode},
        </if>
        <if test="involveAreaType != null">
            involve_area_type = #{involveAreaType},
        </if>
        <if test="involveAreaTypeName != null and involveAreaTypeName != ''">
            involve_area_type_name = #{involveAreaTypeName},
        </if>
        <if test="involveAreaTypeCode != null and involveAreaTypeCode != ''">
            involve_area_type_code = #{involveAreaTypeCode},
        </if>
        <if test="involveAreaRange != null and involveAreaRange != ''">
            involve_area_range = #{involveAreaRange},
        </if>
        <if test="renovationLeadDept != null and renovationLeadDept != ''">
            renovation_lead_dept = #{renovationLeadDept},
        </if>
        <if test="renovationJoinDept != null and renovationJoinDept != ''">
            renovation_join_dept = #{renovationJoinDept},
        </if>
        <if test="leadDeptMan != null and leadDeptMan != ''">
            lead_dept_man = #{leadDeptMan},
        </if>
        <if test="leadDeptPhone != null and leadDeptPhone != ''">
            lead_dept_phone = #{leadDeptPhone},
        </if>
        <if test="rectificationTime != null and rectificationTime != ''">
            rectification_time = #{rectificationTime},
        </if>
        <if test="renovationCriminalCount != null">
            renovation_criminal_count = #{renovationCriminalCount},
        </if>
        <if test="renovationSecurityCount != null">
            renovation_security_count = #{renovationSecurityCount},
        </if>
        <if test="renovationSituationw != null and renovationSituationw != ''">
            renovation_situationw = #{renovationSituationw},
        </if>
        <if test="effectEvaluation != null">
            effect_evaluation = #{effectEvaluation},
        </if>
        <if test="effectEvaluationName != null and effectEvaluationName != ''">
            effect_evaluation_name = #{effectEvaluationName},
        </if>
        <if test="effectEvaluationCode != null and effectEvaluationCode != ''">
            effect_evaluation_code = #{effectEvaluationCode},
        </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>
        <if test="longitude != null and longitude != ''">
            longitude = #{longitude},
        </if>
        <if test="latitude != null and latitude != ''">
            latitude = #{latitude},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            key_area_check_renovation_id = key_area_check_renovation_id
        WHERE
            key_area_check_renovation_id = #{keyAreaCheckRenovationId}
    </update>

    <!-- 重点地区排查整治详情 -->
    <select id="get" parameterType="map" resultMap="keyAreaCheckRenovationDTO">
        SELECT
            t1.security_area,
            t1.security_question,
            t1.security_question_name,
            t1.security_question_code,
            t1.involve_area_type,
            t1.involve_area_type_name,
            t1.involve_area_type_code,
            t1.involve_area_range,
            t1.renovation_lead_dept,
            t1.renovation_join_dept,
            t1.lead_dept_man,
            t1.lead_dept_phone,
            t1.rectification_time,
            t1.renovation_criminal_count,
            t1.renovation_security_count,
            t1.renovation_situationw,
            t1.effect_evaluation,
            t1.effect_evaluation_name,
            t1.effect_evaluation_code,
            t1.location,
            t1.location_code,
            t1.grid,
            t1.longitude,
            t1.latitude,
            t1.creator,
            t1.key_area_check_renovation_id
        FROM
            data_key_area_check_renovation t1
        WHERE
            t1.is_delete = 0
            <if test="keyAreaCheckRenovationId != null and keyAreaCheckRenovationId != ''">
        AND
            t1.key_area_check_renovation_id = #{keyAreaCheckRenovationId}
            </if>
    </select>

    <!-- 重点地区排查整治详情 -->
    <select id="getBO" parameterType="map" resultMap="keyAreaCheckRenovationBO">
        SELECT
            t1.key_area_check_renovation_id,
            t1.security_area,
            t1.security_question,
            t1.security_question_name,
            t1.security_question_code,
            t1.involve_area_type,
            t1.involve_area_type_name,
            t1.involve_area_type_code,
            t1.involve_area_range,
            t1.renovation_lead_dept,
            t1.renovation_join_dept,
            t1.lead_dept_man,
            t1.lead_dept_phone,
            t1.rectification_time,
            t1.renovation_criminal_count,
            t1.renovation_security_count,
            t1.renovation_situationw,
            t1.effect_evaluation,
            t1.effect_evaluation_name,
            t1.effect_evaluation_code
        FROM
            data_key_area_check_renovation t1
        WHERE
            t1.is_delete = 0
            <if test="keyAreaCheckRenovationId != null and keyAreaCheckRenovationId != ''">
        AND
            t1.key_area_check_renovation_id = #{keyAreaCheckRenovationId}
            </if>
    </select>

    <!-- 重点地区排查整治详情 -->
    <select id="getPO" parameterType="map" resultMap="keyAreaCheckRenovationPO">
        SELECT
            t1.key_area_check_renovation_id,
            t1.security_area,
            t1.security_question,
            t1.security_question_name,
            t1.security_question_code,
            t1.involve_area_type,
            t1.involve_area_type_name,
            t1.involve_area_type_code,
            t1.involve_area_range,
            t1.renovation_lead_dept,
            t1.renovation_join_dept,
            t1.lead_dept_man,
            t1.lead_dept_phone,
            t1.rectification_time,
            t1.renovation_criminal_count,
            t1.renovation_security_count,
            t1.renovation_situationw,
            t1.effect_evaluation,
            t1.effect_evaluation_name,
            t1.effect_evaluation_code
        FROM
            data_key_area_check_renovation t1
        WHERE
            t1.is_delete = 0
            <if test="keyAreaCheckRenovationId != null and keyAreaCheckRenovationId != ''">
        AND
            t1.key_area_check_renovation_id = #{keyAreaCheckRenovationId}
            </if>
    </select>

    <!-- 重点地区排查整治列表 -->
    <select id="list" parameterType="map" resultMap="keyAreaCheckRenovationDTO">
        SELECT
            t1.key_area_check_renovation_id,
            t1.security_area,
            t1.security_question,
            t1.security_question_name,
            t1.security_question_code,
            t1.involve_area_type,
            t1.involve_area_type_name,
            t1.involve_area_type_code,
            t1.involve_area_range,
            t1.renovation_lead_dept,
            t1.renovation_join_dept,
            t1.lead_dept_man,
            t1.lead_dept_phone,
            t1.rectification_time,
            t1.renovation_criminal_count,
            t1.renovation_security_count,
            t1.renovation_situationw,
            t1.effect_evaluation,
            t1.effect_evaluation_name,
            t1.effect_evaluation_code,
            t1.location,
            t1.location_code,
            t1.grid,
            t1.longitude,
            t1.latitude,
            1
        FROM
            data_key_area_check_renovation t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.security_area LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="locationCode != null and locationCode != ''">
            AND t1.location_code = #{locationCode}
        </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="keyAreaCheckRenovationIds != null and keyAreaCheckRenovationIds.size > 0">
        AND
            t1.key_area_check_renovation_id IN
            <foreach collection="keyAreaCheckRenovationIds" index="index" open="(" separator="," close=")">
                #{keyAreaCheckRenovationIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 重点地区排查整治列表 -->
    <select id="listBO" parameterType="map" resultMap="keyAreaCheckRenovationBO">
        SELECT
            t1.key_area_check_renovation_id,
            t1.security_area,
            t1.security_question,
            t1.security_question_name,
            t1.security_question_code,
            t1.involve_area_type,
            t1.involve_area_type_name,
            t1.involve_area_type_code,
            t1.involve_area_range,
            t1.renovation_lead_dept,
            t1.renovation_join_dept,
            t1.lead_dept_man,
            t1.lead_dept_phone,
            t1.rectification_time,
            t1.renovation_criminal_count,
            t1.renovation_security_count,
            t1.renovation_situationw,
            t1.effect_evaluation,
            t1.effect_evaluation_name,
            t1.effect_evaluation_code
        FROM
            data_key_area_check_renovation 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="keyAreaCheckRenovationIds != null and keyAreaCheckRenovationIds.size > 0">
        AND
            t1.key_area_check_renovation_id IN
            <foreach collection="keyAreaCheckRenovationIds" index="index" open="(" separator="," close=")">
                #{keyAreaCheckRenovationIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 重点地区排查整治列表 -->
    <select id="listPO" parameterType="map" resultMap="keyAreaCheckRenovationPO">
        SELECT
            t1.key_area_check_renovation_id,
            t1.security_area,
            t1.security_question,
            t1.security_question_name,
            t1.security_question_code,
            t1.involve_area_type,
            t1.involve_area_type_name,
            t1.involve_area_type_code,
            t1.involve_area_range,
            t1.renovation_lead_dept,
            t1.renovation_join_dept,
            t1.lead_dept_man,
            t1.lead_dept_phone,
            t1.rectification_time,
            t1.renovation_criminal_count,
            t1.renovation_security_count,
            t1.renovation_situationw,
            t1.effect_evaluation,
            t1.effect_evaluation_name,
            t1.effect_evaluation_code
        FROM
            data_key_area_check_renovation 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="keyAreaCheckRenovationIds != null and keyAreaCheckRenovationIds.size > 0">
        AND
            t1.key_area_check_renovation_id IN
            <foreach collection="keyAreaCheckRenovationIds" index="index" open="(" separator="," close=")">
                #{keyAreaCheckRenovationIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 重点地区排查整治统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_key_area_check_renovation t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>