<?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="com.sundot.airport.blocked.mapper.BlockedBootPersonnelTenureMapper">

    <resultMap type="BlockedBootPersonnelTenure" id="BlockedBootPersonnelTenureResult">
        <result property="tenantId" column="tenant_id"/>
        <result property="revision" column="revision"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="id" column="id"/>
        <result property="brigadeId" column="brigade_id"/>
        <result property="brigadeName" column="brigade_name"/>
        <result property="cntGe5Year" column="cnt_ge_5_year"/>
        <result property="cnt4Years" column="cnt_4_years"/>
        <result property="cnt3Years" column="cnt_3_years"/>
        <result property="cnt2Years" column="cnt_2_years"/>
        <result property="cnt1Years" column="cnt_1_years"/>
        <result property="cntLt1Year" column="cnt_lt_1_year"/>
    </resultMap>

    <sql id="selectBlockedBootPersonnelTenureVo">
        select tenant_id,
               revision,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               id,
               brigade_id,
               brigade_name,
               cnt_ge_5_year,
               cnt_4_years,
               cnt_3_years,
               cnt_2_years,
               cnt_1_years,
               cnt_lt_1_year
        from blocked_boot_personnel_tenure
    </sql>

    <select id="selectBlockedBootPersonnelTenureList" parameterType="BlockedBootPersonnelTenure"
            resultMap="BlockedBootPersonnelTenureResult">
        <include refid="selectBlockedBootPersonnelTenureVo"/>
        <where>
            <if test="tenantId != null  and tenantId != ''">and tenant_id = #{tenantId}</if>
            <if test="revision != null ">and revision = #{revision}</if>
            <if test="brigadeId != null ">and brigade_id = #{brigadeId}</if>
            <if test="brigadeName != null  and brigadeName != ''">and brigade_name like concat('%', #{brigadeName},
                '%')
            </if>
            <if test="cntGe5Year != null ">and cnt_ge_5_year = #{cntGe5Year}</if>
            <if test="cnt4Years != null ">and cnt_4_years = #{cnt4Years}</if>
            <if test="cnt3Years != null ">and cnt_3_years = #{cnt3Years}</if>
            <if test="cnt2Years != null ">and cnt_2_years = #{cnt2Years}</if>
            <if test="cnt1Years != null ">and cnt_1_years = #{cnt1Years}</if>
            <if test="cntLt1Year != null ">and cnt_lt_1_year = #{cntLt1Year}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectBlockedBootPersonnelTenureById" parameterType="Long" resultMap="BlockedBootPersonnelTenureResult">
        <include refid="selectBlockedBootPersonnelTenureVo"/>
        where id = #{id}
    </select>

    <insert id="insertBlockedBootPersonnelTenure" parameterType="BlockedBootPersonnelTenure" useGeneratedKeys="true"
            keyProperty="id">
        insert into blocked_boot_personnel_tenure
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">tenant_id,</if>
            <if test="revision != null">revision,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="brigadeId != null">brigade_id,</if>
            <if test="brigadeName != null and brigadeName != ''">brigade_name,</if>
            <if test="cntGe5Year != null">cnt_ge_5_year,</if>
            <if test="cnt4Years != null">cnt_4_years,</if>
            <if test="cnt3Years != null">cnt_3_years,</if>
            <if test="cnt2Years != null">cnt_2_years,</if>
            <if test="cnt1Years != null">cnt_1_years,</if>
            <if test="cntLt1Year != null">cnt_lt_1_year,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">#{tenantId},</if>
            <if test="revision != null">#{revision},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="brigadeId != null">#{brigadeId},</if>
            <if test="brigadeName != null and brigadeName != ''">#{brigadeName},</if>
            <if test="cntGe5Year != null">#{cntGe5Year},</if>
            <if test="cnt4Years != null">#{cnt4Years},</if>
            <if test="cnt3Years != null">#{cnt3Years},</if>
            <if test="cnt2Years != null">#{cnt2Years},</if>
            <if test="cnt1Years != null">#{cnt1Years},</if>
            <if test="cntLt1Year != null">#{cntLt1Year},</if>
        </trim>
    </insert>

    <update id="updateBlockedBootPersonnelTenure" parameterType="BlockedBootPersonnelTenure">
        update blocked_boot_personnel_tenure
        <trim prefix="SET" suffixOverrides=",">
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="revision != null">revision = #{revision},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="brigadeId != null">brigade_id = #{brigadeId},</if>
            <if test="brigadeName != null and brigadeName != ''">brigade_name = #{brigadeName},</if>
            <if test="cntGe5Year != null">cnt_ge_5_year = #{cntGe5Year},</if>
            <if test="cnt4Years != null">cnt_4_years = #{cnt4Years},</if>
            <if test="cnt3Years != null">cnt_3_years = #{cnt3Years},</if>
            <if test="cnt2Years != null">cnt_2_years = #{cnt2Years},</if>
            <if test="cnt1Years != null">cnt_1_years = #{cnt1Years},</if>
            <if test="cntLt1Year != null">cnt_lt_1_year = #{cntLt1Year},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBlockedBootPersonnelTenureById" parameterType="Long">
        delete
        from blocked_boot_personnel_tenure
        where id = #{id}
    </delete>

    <delete id="deleteBlockedBootPersonnelTenureByIds" parameterType="String">
        delete from blocked_boot_personnel_tenure where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>