<?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.engine.salary.mapper.TaxRateDetailMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.taxrate.TaxRateDetail">
        <result column="base_id" property="baseId"/>
        <result column="create_time" property="createTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="duty_free_rate" property="dutyFreeRate"/>
        <result column="duty_free_value" property="dutyFreeValue"/>
        <result column="id" property="id"/>
        <result column="income_lower_limit" property="incomeLowerLimit"/>
        <result column="income_upper_limit" property="incomeUpperLimit"/>
        <result column="index_num" property="indexNum"/>
        <result column="tax_deduction" property="taxDeduction"/>
        <result column="tax_rate" property="taxRate"/>
        <result column="taxable_income_ll" property="taxableIncomeLl"/>
        <result column="taxable_income_ul" property="taxableIncomeUl"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t.base_id
        , t.create_time
        , t.creator
        , t.delete_type
        , t.duty_free_rate
        , t.duty_free_value
        , t.id
        , t.income_lower_limit
        , t.income_upper_limit
        , t.index_num
        , t.tax_deduction
        , t.tax_rate
        , t.taxable_income_ll
        , t.taxable_income_ul
        , t.tenant_key
        , t.update_time
    </sql>

    <!-- 查询全部 -->
    <select id="listAll" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_tax_rate_detail t
        WHERE delete_type = 0
    </select>

    <!-- 根据主键获取单条记录 -->
    <select id="getById" resultMap="BaseResultMap" parameterType="Long">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_tax_rate_detail t
        WHERE id = #{id} AND delete_type = 0
    </select>

    <!-- 插入全部字段 -->
    <insert id="insert" parameterType="com.engine.salary.entity.taxrate.TaxRateDetail"
            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
    >
        INSERT INTO hrsa_tax_rate_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            base_id,
            create_time,
            creator,
            delete_type,
            duty_free_rate,
            duty_free_value,
            id,
            income_lower_limit,
            income_upper_limit,
            index_num,
            tax_deduction,
            tax_rate,
            taxable_income_ll,
            taxable_income_ul,
            tenant_key,
            update_time,
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            #{baseId},
            #{createTime},
            #{creator},
            #{deleteType},
            #{dutyFreeRate},
            #{dutyFreeValue},
            #{id},
            #{incomeLowerLimit},
            #{incomeUpperLimit},
            #{indexNum},
            #{taxDeduction},
            #{taxRate},
            #{taxableIncomeLl},
            #{taxableIncomeUl},
            #{tenantKey},
            #{updateTime},
        </trim>
    </insert>

    <insert id="insert" parameterType="com.engine.salary.entity.taxrate.TaxRateDetail" databaseId="oracle"
    >
        <selectKey  keyProperty="id" resultType="long" order="AFTER">
            select hrsa_tax_rate_detail_id.currval from dual
        </selectKey>
        INSERT INTO hrsa_tax_rate_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            base_id,
            create_time,
            creator,
            delete_type,
            duty_free_rate,
            duty_free_value,
            id,
            income_lower_limit,
            income_upper_limit,
            index_num,
            tax_deduction,
            tax_rate,
            taxable_income_ll,
            taxable_income_ul,
            tenant_key,
            update_time,
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            #{baseId},
            #{createTime},
            #{creator},
            #{deleteType},
            #{dutyFreeRate},
            #{dutyFreeValue},
            #{id},
            #{incomeLowerLimit},
            #{incomeUpperLimit},
            #{indexNum},
            #{taxDeduction},
            #{taxRate},
            #{taxableIncomeLl},
            #{taxableIncomeUl},
            #{tenantKey},
            #{updateTime},
        </trim>
    </insert>

    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.taxrate.TaxRateDetail"
            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
    >
        INSERT INTO hrsa_tax_rate_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="baseId != null">
                base_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="dutyFreeRate != null">
                duty_free_rate,
            </if>
            <if test="dutyFreeValue != null">
                duty_free_value,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="incomeLowerLimit != null">
                income_lower_limit,
            </if>
            <if test="incomeUpperLimit != null">
                income_upper_limit,
            </if>
            <if test="indexNum != null">
                index_num,
            </if>
            <if test="taxDeduction != null">
                tax_deduction,
            </if>
            <if test="taxRate != null">
                tax_rate,
            </if>
            <if test="taxableIncomeLl != null">
                taxable_income_ll,
            </if>
            <if test="taxableIncomeUl != null">
                taxable_income_ul,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="baseId != null">
                #{baseId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="dutyFreeRate != null">
                #{dutyFreeRate},
            </if>
            <if test="dutyFreeValue != null">
                #{dutyFreeValue},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="incomeLowerLimit != null">
                #{incomeLowerLimit},
            </if>
            <if test="incomeUpperLimit != null">
                #{incomeUpperLimit},
            </if>
            <if test="indexNum != null">
                #{indexNum},
            </if>
            <if test="taxDeduction != null">
                #{taxDeduction},
            </if>
            <if test="taxRate != null">
                #{taxRate},
            </if>
            <if test="taxableIncomeLl != null">
                #{taxableIncomeLl},
            </if>
            <if test="taxableIncomeUl != null">
                #{taxableIncomeUl},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.taxrate.TaxRateDetail" databaseId="oracle"
    >
        <selectKey  keyProperty="id" resultType="long" order="AFTER">
            select hrsa_tax_rate_detail_id.currval from dual
        </selectKey>
        INSERT INTO hrsa_tax_rate_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="baseId != null">
                base_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="dutyFreeRate != null">
                duty_free_rate,
            </if>
            <if test="dutyFreeValue != null">
                duty_free_value,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="incomeLowerLimit != null">
                income_lower_limit,
            </if>
            <if test="incomeUpperLimit != null">
                income_upper_limit,
            </if>
            <if test="indexNum != null">
                index_num,
            </if>
            <if test="taxDeduction != null">
                tax_deduction,
            </if>
            <if test="taxRate != null">
                tax_rate,
            </if>
            <if test="taxableIncomeLl != null">
                taxable_income_ll,
            </if>
            <if test="taxableIncomeUl != null">
                taxable_income_ul,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="baseId != null">
                #{baseId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="dutyFreeRate != null">
                #{dutyFreeRate},
            </if>
            <if test="dutyFreeValue != null">
                #{dutyFreeValue},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="incomeLowerLimit != null">
                #{incomeLowerLimit},
            </if>
            <if test="incomeUpperLimit != null">
                #{incomeUpperLimit},
            </if>
            <if test="indexNum != null">
                #{indexNum},
            </if>
            <if test="taxDeduction != null">
                #{taxDeduction},
            </if>
            <if test="taxRate != null">
                #{taxRate},
            </if>
            <if test="taxableIncomeLl != null">
                #{taxableIncomeLl},
            </if>
            <if test="taxableIncomeUl != null">
                #{taxableIncomeUl},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>



    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.taxrate.TaxRateDetail">
        UPDATE hrsa_tax_rate_detail
        <set>
            base_id=#{baseId},
            create_time=#{createTime},
            creator=#{creator},
            delete_type=#{deleteType},
            duty_free_rate=#{dutyFreeRate},
            duty_free_value=#{dutyFreeValue},
            income_lower_limit=#{incomeLowerLimit},
            income_upper_limit=#{incomeUpperLimit},
            index_num=#{indexNum},
            tax_deduction=#{taxDeduction},
            tax_rate=#{taxRate},
            taxable_income_ll=#{taxableIncomeLl},
            taxable_income_ul=#{taxableIncomeUl},
            tenant_key=#{tenantKey},
            update_time=#{updateTime},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.taxrate.TaxRateDetail">
        UPDATE hrsa_tax_rate_detail
        <set>
            <if test="baseId != null">
                base_id=#{baseId},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="creator != null">
                creator=#{creator},
            </if>
            <if test="deleteType != null">
                delete_type=#{deleteType},
            </if>
            <if test="dutyFreeRate != null">
                duty_free_rate=#{dutyFreeRate},
            </if>
            <if test="dutyFreeValue != null">
                duty_free_value=#{dutyFreeValue},
            </if>
            <if test="incomeLowerLimit != null">
                income_lower_limit=#{incomeLowerLimit},
            </if>
            <if test="incomeUpperLimit != null">
                income_upper_limit=#{incomeUpperLimit},
            </if>
            <if test="indexNum != null">
                index_num=#{indexNum},
            </if>
            <if test="taxDeduction != null">
                tax_deduction=#{taxDeduction},
            </if>
            <if test="taxRate != null">
                tax_rate=#{taxRate},
            </if>
            <if test="taxableIncomeLl != null">
                taxable_income_ll=#{taxableIncomeLl},
            </if>
            <if test="taxableIncomeUl != null">
                taxable_income_ul=#{taxableIncomeUl},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 根据主键删除记录 -->
    <delete id="delete" parameterType="com.engine.salary.entity.taxrate.TaxRateDetail">
        UPDATE hrsa_tax_rate_detail
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>

    <update id="deleteByBatchIds">
        UPDATE hrsa_tax_rate_detail
        SET delete_type = 1
        WHERE delete_type = 0
        AND base_id IN
        <foreach collection="baseIds" open="(" item="baseId" separator="," close=")">
            #{baseId}
        </foreach>
    </update>

    <select id="listByBaseId" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_tax_rate_detail t
        WHERE delete_type = 0 AND t.base_id = #{baseId}
    </select>




</mapper>