<?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.masspreventionrank.IMassPreventionRankDao">

    <resultMap id="massPreventionRankDTO" type="cn.com.tenlion.systembase.pojo.dtos.masspreventionrank.MassPreventionRankDTO">
        <result column="mass_prevention_rank_id" property="massPreventionRankId"/>
        <result column="mass_prevention_id" property="massPreventionId"/>
        <result column="organize_name" property="organizeName"/>
        <result column="name" property="name"/>
        <result column="sex" property="sex"/>
        <result column="sex_name" property="sexName"/>
        <result column="sex_code" property="sexCode"/>
        <result column="nation" property="nation"/>
        <result column="nation_name" property="nationName"/>
        <result column="nation_code" property="nationCode"/>
        <result column="political_outlook" property="politicalOutlook"/>
        <result column="political_outlook_name" property="politicalOutlookName"/>
        <result column="political_outlook_code" property="politicalOutlookCode"/>
        <result column="card_code" property="cardCode"/>
        <result column="card_code_name" property="cardCodeName"/>
        <result column="card_code_code" property="cardCodeCode"/>
        <result column="card_num" property="cardNum"/>
        <result column="birthday" property="birthday"/>
        <result column="post" property="post"/>
        <result column="professional_expertise" property="professionalExpertise"/>
        <result column="professional_expertise_name" property="professionalExpertiseName"/>
        <result column="professional_expertise_code" property="professionalExpertiseCode"/>
        <result column="education" property="education"/>
        <result column="education_name" property="educationName"/>
        <result column="education_code" property="educationCode"/>
        <result column="phone" property="phone"/>
        <result column="fixed_phone" property="fixedPhone"/>
    </resultMap>

    <resultMap id="massPreventionRankBO" type="cn.com.tenlion.systembase.pojo.bos.masspreventionrank.MassPreventionRankBO">
        <result column="mass_prevention_rank_id" property="massPreventionRankId"/>
        <result column="mass_prevention_id" property="massPreventionId"/>
        <result column="organize_name" property="organizeName"/>
        <result column="name" property="name"/>
        <result column="sex" property="sex"/>
        <result column="sex_name" property="sexName"/>
        <result column="sex_code" property="sexCode"/>
        <result column="nation" property="nation"/>
        <result column="nation_name" property="nationName"/>
        <result column="nation_code" property="nationCode"/>
        <result column="political_outlook" property="politicalOutlook"/>
        <result column="political_outlook_name" property="politicalOutlookName"/>
        <result column="political_outlook_code" property="politicalOutlookCode"/>
        <result column="card_code" property="cardCode"/>
        <result column="card_code_name" property="cardCodeName"/>
        <result column="card_code_code" property="cardCodeCode"/>
        <result column="card_num" property="cardNum"/>
        <result column="birthday" property="birthday"/>
        <result column="post" property="post"/>
        <result column="professional_expertise" property="professionalExpertise"/>
        <result column="professional_expertise_name" property="professionalExpertiseName"/>
        <result column="professional_expertise_code" property="professionalExpertiseCode"/>
        <result column="education" property="education"/>
        <result column="education_name" property="educationName"/>
        <result column="education_code" property="educationCode"/>
        <result column="phone" property="phone"/>
        <result column="fixed_phone" property="fixedPhone"/>
    </resultMap>

    <resultMap id="massPreventionRankPO" type="cn.com.tenlion.systembase.pojo.pos.masspreventionrank.MassPreventionRankPO">
        <result column="mass_prevention_rank_id" property="massPreventionRankId"/>
        <result column="mass_prevention_id" property="massPreventionId"/>
        <result column="organize_name" property="organizeName"/>
        <result column="name" property="name"/>
        <result column="sex" property="sex"/>
        <result column="sex_name" property="sexName"/>
        <result column="sex_code" property="sexCode"/>
        <result column="nation" property="nation"/>
        <result column="nation_name" property="nationName"/>
        <result column="nation_code" property="nationCode"/>
        <result column="political_outlook" property="politicalOutlook"/>
        <result column="political_outlook_name" property="politicalOutlookName"/>
        <result column="political_outlook_code" property="politicalOutlookCode"/>
        <result column="card_code" property="cardCode"/>
        <result column="card_code_name" property="cardCodeName"/>
        <result column="card_code_code" property="cardCodeCode"/>
        <result column="card_num" property="cardNum"/>
        <result column="birthday" property="birthday"/>
        <result column="post" property="post"/>
        <result column="professional_expertise" property="professionalExpertise"/>
        <result column="professional_expertise_name" property="professionalExpertiseName"/>
        <result column="professional_expertise_code" property="professionalExpertiseCode"/>
        <result column="education" property="education"/>
        <result column="education_name" property="educationName"/>
        <result column="education_code" property="educationCode"/>
        <result column="phone" property="phone"/>
        <result column="fixed_phone" property="fixedPhone"/>
    </resultMap>

    <!-- 新增群防群治队伍 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_mass_prevention_rank(
            mass_prevention_rank_id,
            mass_prevention_id,
            organize_name,
            name,
            sex,
            sex_name,
            sex_code,
            nation,
            nation_name,
            nation_code,
            political_outlook,
            political_outlook_name,
            political_outlook_code,
            card_code,
            card_code_name,
            card_code_code,
            card_num,
            birthday,
            post,
            professional_expertise,
            professional_expertise_name,
            professional_expertise_code,
            education,
            education_name,
            education_code,
            phone,
            fixed_phone,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{massPreventionRankId},
            #{massPreventionId},
            #{organizeName},
            #{name},
            #{sex},
            #{sexName},
            #{sexCode},
            #{nation},
            #{nationName},
            #{nationCode},
            #{politicalOutlook},
            #{politicalOutlookName},
            #{politicalOutlookCode},
            #{cardCode},
            #{cardCodeName},
            #{cardCodeCode},
            #{cardNum},
            #{birthday},
            #{post},
            #{professionalExpertise},
            #{professionalExpertiseName},
            #{professionalExpertiseCode},
            #{education},
            #{educationName},
            #{educationCode},
            #{phone},
            #{fixedPhone},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

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

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

    <!-- 修改群防群治队伍 -->
    <update id="update" parameterType="map">
        UPDATE
            data_mass_prevention_rank
        SET
        <if test="massPreventionId != null and massPreventionId != ''">
            mass_prevention_id = #{massPreventionId},
        </if>
        <if test="organizeName != null and organizeName != ''">
            organize_name = #{organizeName},
        </if>
        <if test="name != null and name != ''">
            name = #{name},
        </if>
        <if test="sex != null">
            sex = #{sex},
        </if>
        <if test="sexName != null and sexName != ''">
            sex_name = #{sexName},
        </if>
        <if test="sexCode != null and sexCode != ''">
            sex_code = #{sexCode},
        </if>
        <if test="nation != null">
            nation = #{nation},
        </if>
        <if test="nationName != null and nationName != ''">
            nation_name = #{nationName},
        </if>
        <if test="nationCode != null and nationCode != ''">
            nation_code = #{nationCode},
        </if>
        <if test="politicalOutlook != null">
            political_outlook = #{politicalOutlook},
        </if>
        <if test="politicalOutlookName != null and politicalOutlookName != ''">
            political_outlook_name = #{politicalOutlookName},
        </if>
        <if test="politicalOutlookCode != null and politicalOutlookCode != ''">
            political_outlook_code = #{politicalOutlookCode},
        </if>
        <if test="cardCode != null">
            card_code = #{cardCode},
        </if>
        <if test="cardCodeName != null and cardCodeName != ''">
            card_code_name = #{cardCodeName},
        </if>
        <if test="cardCodeCode != null and cardCodeCode != ''">
            card_code_code = #{cardCodeCode},
        </if>
        <if test="cardNum != null and cardNum != ''">
            card_num = #{cardNum},
        </if>
        <if test="birthday != null and birthday != ''">
            birthday = #{birthday},
        </if>
        <if test="post != null and post != ''">
            post = #{post},
        </if>
        <if test="professionalExpertise != null and professionalExpertise != ''">
            professional_expertise = #{professionalExpertise},
        </if>
        <if test="professionalExpertiseName != null and professionalExpertiseName != ''">
            professional_expertise_name = #{professionalExpertiseName},
        </if>
        <if test="professionalExpertiseCode != null and professionalExpertiseCode != ''">
            professional_expertise_code = #{professionalExpertiseCode},
        </if>
        <if test="education != null">
            education = #{education},
        </if>
        <if test="educationName != null and educationName != ''">
            education_name = #{educationName},
        </if>
        <if test="educationCode != null and educationCode != ''">
            education_code = #{educationCode},
        </if>
        <if test="phone != null and phone != ''">
            phone = #{phone},
        </if>
        <if test="fixedPhone != null and fixedPhone != ''">
            fixed_phone = #{fixedPhone},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            mass_prevention_rank_id = mass_prevention_rank_id
        WHERE
            mass_prevention_rank_id = #{massPreventionRankId}
    </update>

    <!-- 群防群治队伍详情 -->
    <select id="get" parameterType="map" resultMap="massPreventionRankDTO">
        SELECT
            t1.mass_prevention_id,
            t1.organize_name,
            t1.name,
            t1.sex,
            t1.sex_name,
            t1.sex_code,
            t1.nation,
            t1.nation_name,
            t1.nation_code,
            t1.political_outlook,
            t1.political_outlook_name,
            t1.political_outlook_code,
            t1.card_code,
            t1.card_code_name,
            t1.card_code_code,
            t1.card_num,
            t1.birthday,
            t1.post,
            t1.professional_expertise,
            t1.professional_expertise_name,
            t1.professional_expertise_code,
            t1.education,
            t1.education_name,
            t1.education_code,
            t1.phone,
            t1.fixed_phone,
            t1.mass_prevention_rank_id
        FROM
            data_mass_prevention_rank t1
        WHERE
            t1.is_delete = 0
            <if test="massPreventionRankId != null and massPreventionRankId != ''">
        AND
            t1.mass_prevention_rank_id = #{massPreventionRankId}
            </if>
    </select>

    <!-- 群防群治队伍详情 -->
    <select id="getBO" parameterType="map" resultMap="massPreventionRankBO">
        SELECT
            t1.mass_prevention_rank_id,
            t1.mass_prevention_id,
            t1.organize_name,
            t1.name,
            t1.sex,
            t1.sex_name,
            t1.sex_code,
            t1.nation,
            t1.nation_name,
            t1.nation_code,
            t1.political_outlook,
            t1.political_outlook_name,
            t1.political_outlook_code,
            t1.card_code,
            t1.card_code_name,
            t1.card_code_code,
            t1.card_num,
            t1.birthday,
            t1.post,
            t1.professional_expertise,
            t1.professional_expertise_name,
            t1.professional_expertise_code,
            t1.education,
            t1.education_name,
            t1.education_code,
            t1.phone,
            t1.fixed_phone
        FROM
            data_mass_prevention_rank t1
        WHERE
            t1.is_delete = 0
            <if test="massPreventionRankId != null and massPreventionRankId != ''">
        AND
            t1.mass_prevention_rank_id = #{massPreventionRankId}
            </if>
    </select>

    <!-- 群防群治队伍详情 -->
    <select id="getPO" parameterType="map" resultMap="massPreventionRankPO">
        SELECT
            t1.mass_prevention_rank_id,
            t1.mass_prevention_id,
            t1.organize_name,
            t1.name,
            t1.sex,
            t1.sex_name,
            t1.sex_code,
            t1.nation,
            t1.nation_name,
            t1.nation_code,
            t1.political_outlook,
            t1.political_outlook_name,
            t1.political_outlook_code,
            t1.card_code,
            t1.card_code_name,
            t1.card_code_code,
            t1.card_num,
            t1.birthday,
            t1.post,
            t1.professional_expertise,
            t1.professional_expertise_name,
            t1.professional_expertise_code,
            t1.education,
            t1.education_name,
            t1.education_code,
            t1.phone,
            t1.fixed_phone
        FROM
            data_mass_prevention_rank t1
        WHERE
            t1.is_delete = 0
            <if test="massPreventionRankId != null and massPreventionRankId != ''">
        AND
            t1.mass_prevention_rank_id = #{massPreventionRankId}
            </if>
    </select>

    <!-- 群防群治队伍列表 -->
    <select id="list" parameterType="map" resultMap="massPreventionRankDTO">
        SELECT
            t1.mass_prevention_rank_id,
            t1.mass_prevention_id,
            t1.organize_name,
            t1.name,
            t1.sex,
            t1.sex_name,
            t1.sex_code,
            t1.nation,
            t1.nation_name,
            t1.nation_code,
            t1.political_outlook,
            t1.political_outlook_name,
            t1.political_outlook_code,
            t1.card_code,
            t1.card_code_name,
            t1.card_code_code,
            t1.card_num,
            t1.birthday,
            t1.post,
            t1.professional_expertise,
            t1.professional_expertise_name,
            t1.professional_expertise_code,
            t1.education,
            t1.education_name,
            t1.education_code,
            t1.phone,
            t1.fixed_phone,
            1
        FROM
            data_mass_prevention_rank t1
        WHERE
            t1.is_delete = 0
        <if test="massPreventionId != null and massPreventionId != ''">
            AND t1.mass_prevention_id = #{massPreventionId}
        </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="massPreventionRankIds != null and massPreventionRankIds.size > 0">
        AND
            t1.mass_prevention_rank_id IN
            <foreach collection="massPreventionRankIds" index="index" open="(" separator="," close=")">
                #{massPreventionRankIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 群防群治队伍列表 -->
    <select id="listBO" parameterType="map" resultMap="massPreventionRankBO">
        SELECT
            t1.mass_prevention_rank_id,
            t1.mass_prevention_id,
            t1.organize_name,
            t1.name,
            t1.sex,
            t1.sex_name,
            t1.sex_code,
            t1.nation,
            t1.nation_name,
            t1.nation_code,
            t1.political_outlook,
            t1.political_outlook_name,
            t1.political_outlook_code,
            t1.card_code,
            t1.card_code_name,
            t1.card_code_code,
            t1.card_num,
            t1.birthday,
            t1.post,
            t1.professional_expertise,
            t1.professional_expertise_name,
            t1.professional_expertise_code,
            t1.education,
            t1.education_name,
            t1.education_code,
            t1.phone,
            t1.fixed_phone
        FROM
            data_mass_prevention_rank 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="massPreventionRankIds != null and massPreventionRankIds.size > 0">
        AND
            t1.mass_prevention_rank_id IN
            <foreach collection="massPreventionRankIds" index="index" open="(" separator="," close=")">
                #{massPreventionRankIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 群防群治队伍列表 -->
    <select id="listPO" parameterType="map" resultMap="massPreventionRankPO">
        SELECT
            t1.mass_prevention_rank_id,
            t1.mass_prevention_id,
            t1.organize_name,
            t1.name,
            t1.sex,
            t1.sex_name,
            t1.sex_code,
            t1.nation,
            t1.nation_name,
            t1.nation_code,
            t1.political_outlook,
            t1.political_outlook_name,
            t1.political_outlook_code,
            t1.card_code,
            t1.card_code_name,
            t1.card_code_code,
            t1.card_num,
            t1.birthday,
            t1.post,
            t1.professional_expertise,
            t1.professional_expertise_name,
            t1.professional_expertise_code,
            t1.education,
            t1.education_name,
            t1.education_code,
            t1.phone,
            t1.fixed_phone
        FROM
            data_mass_prevention_rank 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="massPreventionRankIds != null and massPreventionRankIds.size > 0">
        AND
            t1.mass_prevention_rank_id IN
            <foreach collection="massPreventionRankIds" index="index" open="(" separator="," close=")">
                #{massPreventionRankIds[${index}]}
            </foreach>
        </if>
    </select>

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

</mapper>