<?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.salarysob.SalarySobBackItemMapper">
    <sql id="Base_Column_List">
	id,
	salary_sob_id,
	salary_item_id,
	salary_item_code,
	data_type,
	rounding_mode,
	pattern,
	value_type,
	formula_id,
	back_calc_type,
	tenant_key,
	creator,
	delete_type,
	create_time,
	update_time
</sql><resultMap id="BaseResultMap" type="com.engine.salary.entity.salarysob.po.SalarySobBackItemPO">
        <result column="id" property="id" />
        <result column="salary_sob_id" property="salarySobId" />
        <result column="salary_item_id" property="salaryItemId" />
        <result column="salary_item_code" property="salaryItemCode" />
        <result column="data_type" property="dataType" />
        <result column="rounding_mode" property="roundingMode" />
        <result column="pattern" property="pattern" />
        <result column="value_type" property="valueType" />
        <result column="formula_id" property="formulaId" />
        <result column="back_calc_type" property="backCalcType" />
        <result column="tenant_key" property="tenantKey" />
        <result column="creator" property="creator" />
        <result column="delete_type" property="deleteType" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t.id
        , t.salary_sob_id
        , t.salary_item_id
        , t.salary_item_code
        , t.data_type
        , t.rounding_mode
        , t.pattern
        , t.value_type
        , t.formula_id
        , t.back_calc_type
        , t.tenant_key
        , t.creator
        , t.delete_type
        , t.create_time
        , t.update_time
        , t.default_value
    </sql>


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

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

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.entity.salarysob.po.SalarySobBackItemPO">
        SELECT
        <include refid="baseColumns" />
        FROM hrsa_salary_sob_back_item t
        WHERE delete_type = 0
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="salarySobId != null">
            AND salary_sob_id = #{salarySobId}
        </if>
        <if test="salaryItemId != null">
            AND salary_item_id = #{salaryItemId}
        </if>
        <if test="salaryItemCode != null">
            AND salary_item_code = #{salaryItemCode}
        </if>
        <if test="dataType != null">
            AND data_type = #{dataType}
        </if>
        <if test="roundingMode != null">
            AND rounding_mode = #{roundingMode}
        </if>
        <if test="pattern != null">
            AND pattern = #{pattern}
        </if>
        <if test="valueType != null">
            AND value_type = #{valueType}
        </if>
        <if test="formulaId != null">
            AND formula_id = #{formulaId}
        </if>
        <if test="backCalcType != null">
            AND back_calc_type = #{backCalcType}
        </if>
        <if test="tenantKey != null">
            AND tenant_key = #{tenantKey}
        </if>
        <if test="creator != null">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null">
            AND delete_type = #{deleteType}
        </if>
        <if test="createTime != null">
            AND create_time = #{createTime}
        </if>
        <if test="updateTime != null">
            AND update_time = #{updateTime}
        </if>
        <if test="salaryItemIds != null and salaryItemIds.size()>0">
            AND salary_item_id IN
            <foreach collection="salaryItemIds" open="(" item="salaryItemId" separator="," close=")">
                #{salaryItemId}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>

    <select id="count" resultType="java.lang.Integer">
        select  count(1) from hrsa_salary_sob_back_item;
    </select>






    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.salarysob.po.SalarySobBackItemPO">
        INSERT INTO hrsa_salary_sob_back_item
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="id != null">
                id,
            </if>
            <if test="salarySobId != null">
                salary_sob_id,
            </if>
            <if test="salaryItemId != null">
                salary_item_id,
            </if>
            <if test="salaryItemCode != null">
                salary_item_code,
            </if>
            <if test="dataType != null">
                data_type,
            </if>
            <if test="roundingMode != null">
                rounding_mode,
            </if>
            <if test="pattern != null">
                pattern,
            </if>
            <if test="valueType != null">
                value_type,
            </if>
            <if test="formulaId != null">
                formula_id,
            </if>
            <if test="backCalcType != null">
                back_calc_type,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null" >
                #{id},
            </if>
            <if test="salarySobId != null" >
                #{salarySobId},
            </if>
            <if test="salaryItemId != null" >
                #{salaryItemId},
            </if>
            <if test="salaryItemCode != null" >
                #{salaryItemCode},
            </if>
            <if test="dataType != null" >
                #{dataType},
            </if>
            <if test="roundingMode != null" >
                #{roundingMode},
            </if>
            <if test="pattern != null" >
                #{pattern},
            </if>
            <if test="valueType != null" >
                #{valueType},
            </if>
            <if test="formulaId != null" >
                #{formulaId},
            </if>
            <if test="backCalcType != null" >
                #{backCalcType},
            </if>
            <if test="tenantKey != null" >
                #{tenantKey},
            </if>
            <if test="creator != null" >
                #{creator},
            </if>
            <if test="deleteType != null" >
                #{deleteType},
            </if>
            <if test="createTime != null" >
                #{createTime},
            </if>
            <if test="updateTime != null" >
                #{updateTime},
            </if>
        </trim>
    </insert>

    <insert id="batchInsert">
        INSERT INTO hrsa_salary_sob_back_item
        (id, salary_sob_id, salary_item_id, salary_item_code, data_type, rounding_mode, pattern,
        value_type, formula_id, back_calc_type, tenant_key, creator, delete_type, create_time,
        update_time)
        VALUES
        <foreach collection="collection" item="item" separator=",">
            (#{item.id},#{item.salarySobId}, #{item.salaryItemId}, #{item.salaryItemCode}, #{item.dataType},
            #{item.roundingMode}, #{item.pattern}, #{item.valueType},
            #{item.formulaId},
            #{item.backCalcType}, #{item.tenantKey}, #{item.creator}, 0,
            #{item.createTime}, #{item.updateTime})
        </foreach>
    </insert>


    <insert id="batchInsert" databaseId="oracle">
        INSERT INTO hrsa_salary_sob_back_item
        (id, salary_sob_id, salary_item_id, salary_item_code, data_type, rounding_mode, pattern,
        value_type, formula_id, back_calc_type, tenant_key, creator, delete_type, create_time,
        update_time)
        <foreach collection="collection" item="item" separator="union all">
            select
            #{item.id,jdbcType=DOUBLE},#{item.salarySobId,jdbcType=DOUBLE}, #{item.salaryItemId,jdbcType=DOUBLE}, #{item.salaryItemCode,jdbcType=VARCHAR}, #{item.dataType,jdbcType=VARCHAR},
            #{item.roundingMode,jdbcType=INTEGER}, #{item.pattern,jdbcType=INTEGER}, #{item.valueType,jdbcType=INTEGER},
            #{item.formulaId,jdbcType=DOUBLE},
            #{item.backCalcType,jdbcType=INTEGER}, #{item.tenantKey,jdbcType=VARCHAR}, #{item.creator,jdbcType=DOUBLE}, 0,
            #{item.createTime,jdbcType=DATE}, #{item.updateTime,jdbcType=DATE}
            from dual
        </foreach>
    </insert>
    <insert id="batchInsert" databaseId="sqlserver">
        <foreach collection="collection" item="item" separator=";">
            INSERT INTO hrsa_salary_sob_back_item
            (id, salary_sob_id, salary_item_id, salary_item_code, data_type, rounding_mode, pattern,
            value_type, formula_id, back_calc_type, tenant_key, creator, delete_type, create_time,
            update_time)
            VALUES
            (#{item.id},#{item.salarySobId}, #{item.salaryItemId}, #{item.salaryItemCode}, #{item.dataType},
            #{item.roundingMode}, #{item.pattern}, #{item.valueType},
            #{item.formulaId},
            #{item.backCalcType}, #{item.tenantKey}, #{item.creator}, 0,
            #{item.createTime}, #{item.updateTime})
        </foreach>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.salarysob.po.SalarySobBackItemPO">
        UPDATE hrsa_salary_sob_back_item
        <set>
            salary_sob_id=#{salarySobId},
            salary_item_id=#{salaryItemId},
            salary_item_code=#{salaryItemCode},
            data_type=#{dataType},
            rounding_mode=#{roundingMode},
            pattern=#{pattern},
            value_type=#{valueType},
            formula_id=#{formulaId},
            back_calc_type=#{backCalcType},
            tenant_key=#{tenantKey},
            creator=#{creator},
            delete_type=#{deleteType},
            create_time=#{createTime},
            update_time=#{updateTime},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.salarysob.po.SalarySobBackItemPO">
        UPDATE hrsa_salary_sob_back_item
        <set>
            <if test="salarySobId != null" >
                salary_sob_id=#{salarySobId},
            </if>
            <if test="salaryItemId != null" >
                salary_item_id=#{salaryItemId},
            </if>
            <if test="salaryItemCode != null" >
                salary_item_code=#{salaryItemCode},
            </if>
            <if test="dataType != null" >
                data_type=#{dataType},
            </if>
            <if test="roundingMode != null" >
                rounding_mode=#{roundingMode},
            </if>
            <if test="pattern != null" >
                pattern=#{pattern},
            </if>
            <if test="valueType != null" >
                value_type=#{valueType},
            </if>
            <if test="formulaId != null" >
                formula_id=#{formulaId},
            </if>
            <if test="backCalcType != null" >
                back_calc_type=#{backCalcType},
            </if>
            <if test="tenantKey != null" >
                tenant_key=#{tenantKey},
            </if>
            <if test="creator != null" >
                creator=#{creator},
            </if>
            <if test="deleteType != null" >
                delete_type=#{deleteType},
            </if>
            <if test="createTime != null" >
                create_time=#{createTime},
            </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.salarysob.po.SalarySobBackItemPO">
        UPDATE hrsa_salary_sob_back_item
        SET delete_type=1
        WHERE id = #{id} AND delete_type = 0
    </delete>

    <!--根据薪资账套获取回算薪资项目数-->
    <select id="countBySalarySobIdIn" resultType="java.lang.Long">
        select count(1)
        from hrsa_salary_sob_back_item
        where salary_sob_id in
        <foreach item="item" index="index" collection="salarySobIdCollection"
                    open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <update id="deleteBySalarySobIds">
        update hrsa_salary_sob_back_item
        set delete_type = 1
        where
        salary_sob_id in
        <foreach collection="salarySobIdList" item="item" open="(" close=")" separator=",">
            #{item,jdbcType=NUMERIC}
        </foreach>
    </update>


</mapper>