<?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.TaxRateBaseMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.taxrate.TaxRateBase">
        <result column="create_time" property="createTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="description" property="description"/>
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="system_type" property="systemType"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        create_time
        , t.creator
        , t.delete_type
        , t.description
        , t.id
        , t.name
        , t.system_type
        , t.tenant_key
        , t.update_time
    </sql>

    <sql id="paramSql">
        <if test="param.ids != null and param.ids.size()>0">
            AND id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="param.name != null and param.name != ''">
            AND name like CONCAT('%',#{param.name},'%')
        </if>
    </sql>


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

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

    <!-- 插入全部字段 -->
    <insert id="insert" parameterType="com.engine.salary.entity.taxrate.TaxRateBase"
            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
    >
        INSERT INTO hrsa_tax_rate_base
        <trim prefix="(" suffix=")" suffixOverrides=",">
            create_time,
            creator,
            delete_type,
            description,
            id,
            name,
            system_type,
            tenant_key,
            update_time,
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            #{createTime},
            #{creator},
            #{deleteType},
            #{description},
            #{id},
            #{name},
            #{systemType},
            #{tenantKey},
            #{updateTime},
        </trim>
    </insert>

    <insert id="insert" parameterType="com.engine.salary.entity.taxrate.TaxRateBase" databaseId="oracle"
    >
        <selectKey  keyProperty="id" resultType="long" order="AFTER">
            select hrsa_tax_rate_base_id.currval from dual
        </selectKey>
        INSERT INTO hrsa_tax_rate_base
        <trim prefix="(" suffix=")" suffixOverrides=",">
            create_time,
            creator,
            delete_type,
            description,
            id,
            name,
            system_type,
            tenant_key,
            update_time,
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            #{createTime},
            #{creator},
            #{deleteType},
            #{description},
            #{id},
            #{name},
            #{systemType},
            #{tenantKey},
            #{updateTime},
        </trim>
    </insert>

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

            <if test="createTime != null">
                create_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="systemType != null">
                system_type,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="description != null">
                #{description},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="name != null">
                #{name},
            </if>
            <if test="systemType != null">
                #{systemType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.taxrate.TaxRateBase">
        UPDATE hrsa_tax_rate_base
        <set>
            create_time=#{createTime},
            creator=#{creator},
            delete_type=#{deleteType},
            description=#{description},
            name=#{name},
            system_type=#{systemType},
            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.TaxRateBase">
        UPDATE hrsa_tax_rate_base
        <set>
            <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="description != null">
                description=#{description},
            </if>
            <if test="name != null">
                name=#{name},
            </if>
            <if test="systemType != null">
                system_type=#{systemType},
            </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.TaxRateBase">
        UPDATE hrsa_tax_rate_base
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>


    <select id="selectByIds" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_tax_rate_base t
        WHERE delete_type = 0
        <if test="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>

    <select id="listBySome" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_tax_rate_base t
        WHERE delete_type = 0
        <include refid="paramSql"/>
        ORDER BY id DESC
    </select>

    <update id="deleteByIds">
        UPDATE hrsa_tax_rate_base
        SET delete_type = 1
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>