<?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.massprevention.IMassPreventionDao">

    <resultMap id="massPreventionDTO" type="cn.com.tenlion.systembase.pojo.dtos.massprevention.MassPreventionDTO">
        <result column="mass_prevention_id" property="massPreventionId"/>
        <result column="organize_name" property="organizeName"/>
        <result column="organize_type" property="organizeType"/>
        <result column="organize_type_name" property="organizeTypeName"/>
        <result column="organize_type_code" property="organizeTypeCode"/>
        <result column="organize_level" property="organizeLevel"/>
        <result column="organize_level_name" property="organizeLevelName"/>
        <result column="organize_level_code" property="organizeLevelCode"/>
        <result column="business_guidance_dept" property="businessGuidanceDept"/>
        <result column="user_count" property="userCount"/>
        <result column="main_function" property="mainFunction"/>
        <result column="location" property="location"/>
        <result column="location_code" property="locationCode"/>
        <result column="grid" property="grid"/>
    </resultMap>

    <resultMap id="massPreventionBO" type="cn.com.tenlion.systembase.pojo.bos.massprevention.MassPreventionBO">
        <result column="mass_prevention_id" property="massPreventionId"/>
        <result column="organize_name" property="organizeName"/>
        <result column="organize_type" property="organizeType"/>
        <result column="organize_type_name" property="organizeTypeName"/>
        <result column="organize_type_code" property="organizeTypeCode"/>
        <result column="organize_level" property="organizeLevel"/>
        <result column="organize_level_name" property="organizeLevelName"/>
        <result column="organize_level_code" property="organizeLevelCode"/>
        <result column="business_guidance_dept" property="businessGuidanceDept"/>
        <result column="user_count" property="userCount"/>
        <result column="main_function" property="mainFunction"/>
    </resultMap>

    <resultMap id="massPreventionPO" type="cn.com.tenlion.systembase.pojo.pos.massprevention.MassPreventionPO">
        <result column="mass_prevention_id" property="massPreventionId"/>
        <result column="organize_name" property="organizeName"/>
        <result column="organize_type" property="organizeType"/>
        <result column="organize_type_name" property="organizeTypeName"/>
        <result column="organize_type_code" property="organizeTypeCode"/>
        <result column="organize_level" property="organizeLevel"/>
        <result column="organize_level_name" property="organizeLevelName"/>
        <result column="organize_level_code" property="organizeLevelCode"/>
        <result column="business_guidance_dept" property="businessGuidanceDept"/>
        <result column="user_count" property="userCount"/>
        <result column="main_function" property="mainFunction"/>
    </resultMap>

    <!-- 新增群防群治组织 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_mass_prevention(
            mass_prevention_id,
            organize_name,
            organize_type,
            organize_type_name,
            organize_type_code,
            organize_level,
            organize_level_name,
            organize_level_code,
            business_guidance_dept,
            user_count,
            main_function,
            location,
            location_code,
            grid,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{massPreventionId},
            #{organizeName},
            #{organizeType},
            #{organizeTypeName},
            #{organizeTypeCode},
            #{organizeLevel},
            #{organizeLevelName},
            #{organizeLevelCode},
            #{businessGuidanceDept},
            #{userCount},
            #{mainFunction},
            #{location},
            #{locationCode},
            #{grid},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除群防群治组织 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_mass_prevention
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            mass_prevention_id IN
        <foreach collection="massPreventionIds" index="index" open="(" separator="," close=")">
            #{massPreventionIds[${index}]}
        </foreach>
    </update>

    <!-- 删除群防群治组织（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_mass_prevention
        WHERE
            mass_prevention_id IN
        <foreach collection="massPreventionIds" index="index" open="(" separator="," close=")">
            #{massPreventionIds[${index}]}
        </foreach>
    </update>

    <!-- 修改群防群治组织 -->
    <update id="update" parameterType="map">
        UPDATE
            data_mass_prevention
        SET
        <if test="organizeName != null and organizeName != ''">
            organize_name = #{organizeName},
        </if>
        <if test="organizeType != null">
            organize_type = #{organizeType},
        </if>
        <if test="organizeTypeName != null and organizeTypeName != ''">
            organize_type_name = #{organizeTypeName},
        </if>
        <if test="organizeTypeCode != null and organizeTypeCode != ''">
            organize_type_code = #{organizeTypeCode},
        </if>
        <if test="organizeLevel != null">
            organize_level = #{organizeLevel},
        </if>
        <if test="organizeLevelName != null and organizeLevelName != ''">
            organize_level_name = #{organizeLevelName},
        </if>
        <if test="organizeLevelCode != null and organizeLevelCode != ''">
            organize_level_code = #{organizeLevelCode},
        </if>
        <if test="businessGuidanceDept != null and businessGuidanceDept != ''">
            business_guidance_dept = #{businessGuidanceDept},
        </if>
        <if test="userCount != null">
            user_count = #{userCount},
        </if>
        <if test="mainFunction != null and mainFunction != ''">
            main_function = #{mainFunction},
        </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},
            mass_prevention_id = mass_prevention_id
        WHERE
            mass_prevention_id = #{massPreventionId}
    </update>

    <!-- 群防群治组织详情 -->
    <select id="get" parameterType="map" resultMap="massPreventionDTO">
        SELECT
            t1.organize_name,
            t1.organize_type,
            t1.organize_type_name,
            t1.organize_type_code,
            t1.organize_level,
            t1.organize_level_name,
            t1.organize_level_code,
            t1.business_guidance_dept,
            t1.user_count,
            t1.main_function,
            t1.location,
            t1.location_code,
            t1.grid,
            t1.mass_prevention_id
        FROM
            data_mass_prevention t1
        WHERE
            t1.is_delete = 0
            <if test="massPreventionId != null and massPreventionId != ''">
        AND
            t1.mass_prevention_id = #{massPreventionId}
            </if>
    </select>

    <!-- 群防群治组织详情 -->
    <select id="getBO" parameterType="map" resultMap="massPreventionBO">
        SELECT
            t1.mass_prevention_id,
            t1.organize_name,
            t1.organize_type,
            t1.organize_type_name,
            t1.organize_type_code,
            t1.organize_level,
            t1.organize_level_name,
            t1.organize_level_code,
            t1.business_guidance_dept,
            t1.user_count,
            t1.main_function
        FROM
            data_mass_prevention t1
        WHERE
            t1.is_delete = 0
            <if test="massPreventionId != null and massPreventionId != ''">
        AND
            t1.mass_prevention_id = #{massPreventionId}
            </if>
    </select>

    <!-- 群防群治组织详情 -->
    <select id="getPO" parameterType="map" resultMap="massPreventionPO">
        SELECT
            t1.mass_prevention_id,
            t1.organize_name,
            t1.organize_type,
            t1.organize_type_name,
            t1.organize_type_code,
            t1.organize_level,
            t1.organize_level_name,
            t1.organize_level_code,
            t1.business_guidance_dept,
            t1.user_count,
            t1.main_function
        FROM
            data_mass_prevention t1
        WHERE
            t1.is_delete = 0
            <if test="massPreventionId != null and massPreventionId != ''">
        AND
            t1.mass_prevention_id = #{massPreventionId}
            </if>
    </select>

    <!-- 群防群治组织列表 -->
    <select id="list" parameterType="map" resultMap="massPreventionDTO">
        SELECT
            t1.mass_prevention_id,
            t1.organize_name,
            t1.organize_type,
            t1.organize_type_name,
            t1.organize_type_code,
            t1.organize_level,
            t1.organize_level_name,
            t1.organize_level_code,
            t1.business_guidance_dept,
            t1.user_count,
            t1.main_function,
            t1.location,
            t1.location_code,
            t1.grid,
            1
        FROM
            data_mass_prevention t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.organize_name 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="massPreventionIds != null and massPreventionIds.size > 0">
        AND
            t1.mass_prevention_id IN
            <foreach collection="massPreventionIds" index="index" open="(" separator="," close=")">
                #{massPreventionIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 群防群治组织列表 -->
    <select id="listBO" parameterType="map" resultMap="massPreventionBO">
        SELECT
            t1.mass_prevention_id,
            t1.organize_name,
            t1.organize_type,
            t1.organize_type_name,
            t1.organize_type_code,
            t1.organize_level,
            t1.organize_level_name,
            t1.organize_level_code,
            t1.business_guidance_dept,
            t1.user_count,
            t1.main_function
        FROM
            data_mass_prevention t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.organize_name 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="massPreventionIds != null and massPreventionIds.size > 0">
        AND
            t1.mass_prevention_id IN
            <foreach collection="massPreventionIds" index="index" open="(" separator="," close=")">
                #{massPreventionIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 群防群治组织列表 -->
    <select id="listPO" parameterType="map" resultMap="massPreventionPO">
        SELECT
            t1.mass_prevention_id,
            t1.organize_name,
            t1.organize_type,
            t1.organize_type_name,
            t1.organize_type_code,
            t1.organize_level,
            t1.organize_level_name,
            t1.organize_level_code,
            t1.business_guidance_dept,
            t1.user_count,
            t1.main_function
        FROM
            data_mass_prevention t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.organize_name 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="massPreventionIds != null and massPreventionIds.size > 0">
        AND
            t1.mass_prevention_id IN
            <foreach collection="massPreventionIds" index="index" open="(" separator="," close=")">
                #{massPreventionIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 群防群治组织统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_mass_prevention t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>