<?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.salaryacct.SalaryAcctResultLogMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.salaryacct.po.SalaryAcctResultLogPO">
        <result column="datasource" property="datasource" />
        <result column="delete_type" property="deleteType" />
        <result column="employee_id" property="employeeId" />
        <result column="id" property="id" />
        <result column="operate_time" property="operateTime" />
        <result column="operator" property="operator" />
        <result column="salary_acct_emp_id" property="salaryAcctEmpId" />
        <result column="salary_acct_record_id" property="salaryAcctRecordId" />
        <result column="salary_acct_result_id" property="salaryAcctResultId" />
        <result column="salary_item_id" property="salaryItemId" />
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t.datasource
        , t.delete_type
        , t.employee_id
        , t.id
        , t.operate_time
        , t.operator
        , t.salary_acct_emp_id
        , t.salary_acct_record_id
        , t.salary_acct_result_id
        , t.salary_item_id
    </sql>

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

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

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.entity.salaryacct.param.SalaryAcctResultLogQueryParam">
        SELECT
        <include refid="baseColumns" />
        FROM hrsa_salary_acct_result_log t
        WHERE delete_type = 0
        <if test="datasource != null">
            AND datasource = #{datasource}
        </if>
        <if test="deleteType != null">
            AND delete_type = #{deleteType}
        </if>
        <if test="employeeId != null">
            AND employee_id = #{employeeId}
        </if>
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="operateTime != null">
            AND operate_time = #{operateTime}
        </if>
        <if test="operator != null">
            AND operator = #{operator}
        </if>
        <if test="salaryAcctEmpId != null">
            AND salary_acct_emp_id = #{salaryAcctEmpId}
        </if>
        <if test="salaryAcctRecordId != null">
            AND salary_acct_record_id = #{salaryAcctRecordId}
        </if>
        <if test="salaryAcctResultId != null">
            AND salary_acct_result_id = #{salaryAcctResultId}
        </if>
        <if test="salaryItemId != null">
            AND salary_item_id = #{salaryItemId}
        </if>
        <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>


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

            <if test="datasource != null">
                datasource,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="employeeId != null">
                employee_id,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="operateTime != null">
                operate_time,
            </if>
            <if test="operator != null">
                operator,
            </if>
            <if test="salaryAcctEmpId != null">
                salary_acct_emp_id,
            </if>
            <if test="salaryAcctRecordId != null">
                salary_acct_record_id,
            </if>
            <if test="salaryAcctResultId != null">
                salary_acct_result_id,
            </if>
            <if test="salaryItemId != null">
                salary_item_id,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="datasource != null" >
                #{datasource},
            </if>
            <if test="deleteType != null" >
                #{deleteType},
            </if>
            <if test="employeeId != null" >
                #{employeeId},
            </if>
            <if test="id != null" >
                #{id},
            </if>
            <if test="operateTime != null" >
                #{operateTime},
            </if>
            <if test="operator != null" >
                #{operator},
            </if>
            <if test="salaryAcctEmpId != null" >
                #{salaryAcctEmpId},
            </if>
            <if test="salaryAcctRecordId != null" >
                #{salaryAcctRecordId},
            </if>
            <if test="salaryAcctResultId != null" >
                #{salaryAcctResultId},
            </if>
            <if test="salaryItemId != null" >
                #{salaryItemId},
            </if>
        </trim>
    </insert>

    <insert id="batchInsert">
        INSERT INTO hrsa_salary_acct_result_log(id, datasource, salary_acct_record_id, salary_acct_result_id, salary_acct_emp_id,
        salary_item_id, employee_id, operator, operate_time, delete_type, update_time)
        VALUES
        <foreach collection="collection" separator="," item="item">
            (
            #{item.id},
            #{item.datasource},
            #{item.salaryAcctRecordId},
            #{item.salaryAcctResultId},
            #{item.salaryAcctEmpId},
            #{item.salaryItemId},
            #{item.employeeId},
            #{item.operator},
            #{item.operateTime},
            #{item.deleteType},
            #{item.updateTime}
            )
        </foreach>
    </insert>
    <insert id="batchInsert" databaseId="oracle">
        INSERT INTO hrsa_salary_acct_result_log(id, datasource, salary_acct_record_id, salary_acct_result_id, salary_acct_emp_id,
        salary_item_id, employee_id, operator, operate_time, delete_type, update_time)
        <foreach collection="collection" separator="union all" item="item">
            select
            #{item.id,jdbcType=DOUBLE},
            #{item.datasource,jdbcType=INTEGER},
            #{item.salaryAcctRecordId,jdbcType=DOUBLE},
            #{item.salaryAcctResultId,jdbcType=DOUBLE},
            #{item.salaryAcctEmpId,jdbcType=DOUBLE},
            #{item.salaryItemId,jdbcType=DOUBLE},
            #{item.employeeId,jdbcType=DOUBLE},
            #{item.operator,jdbcType=,jdbcType=DOUBLE},
            #{item.operateTime,jdbcType=DATE},
            #{item.deleteType,jdbcType=INTEGER},
            #{item.updateTime,jdbcType=DATE}
            from dual
        </foreach>
    </insert>
    <insert id="batchInsert" databaseId="sqlserver">
        <foreach collection="collection" separator=";" item="item">
            INSERT INTO hrsa_salary_acct_result_log(id, datasource, salary_acct_record_id, salary_acct_result_id, salary_acct_emp_id,
            salary_item_id, employee_id, operator, operate_time, delete_type, update_time)
            VALUES
            (
            #{item.id},
            #{item.datasource},
            #{item.salaryAcctRecordId},
            #{item.salaryAcctResultId},
            #{item.salaryAcctEmpId},
            #{item.salaryItemId},
            #{item.employeeId},
            #{item.operator},
            #{item.operateTime},
            #{item.deleteType},
             #{item.updateTime}
            )
        </foreach>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.salaryacct.po.SalaryAcctResultLogPO">
        UPDATE hrsa_salary_acct_result_log
        <set>
            datasource=#{datasource},
            delete_type=#{deleteType},
            employee_id=#{employeeId},
            operate_time=#{operateTime},
            operator=#{operator},
            salary_acct_emp_id=#{salaryAcctEmpId},
            salary_acct_record_id=#{salaryAcctRecordId},
            salary_acct_result_id=#{salaryAcctResultId},
            salary_item_id=#{salaryItemId},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.salaryacct.po.SalaryAcctResultLogPO">
        UPDATE hrsa_salary_acct_result_log
        <set>
            <if test="datasource != null" >
                datasource=#{datasource},
            </if>
            <if test="deleteType != null" >
                delete_type=#{deleteType},
            </if>
            <if test="employeeId != null" >
                employee_id=#{employeeId},
            </if>
            <if test="operateTime != null" >
                operate_time=#{operateTime},
            </if>
            <if test="operator != null" >
                operator=#{operator},
            </if>
            <if test="salaryAcctEmpId != null" >
                salary_acct_emp_id=#{salaryAcctEmpId},
            </if>
            <if test="salaryAcctRecordId != null" >
                salary_acct_record_id=#{salaryAcctRecordId},
            </if>
            <if test="salaryAcctResultId != null" >
                salary_acct_result_id=#{salaryAcctResultId},
            </if>
            <if test="salaryItemId != null" >
                salary_item_id=#{salaryItemId},
            </if>
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


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


    <update id="deleteBySalaryAcctEmpIdExceptItemIds">
        UPDATE hrsa_salary_acct_result_log
        SET delete_type=1, update_time = #{updateTime}
        WHERE delete_type = 0
        <if test="salaryAcctEmployeeIds != null and salaryAcctEmployeeIds.size()>0">
            AND salary_acct_emp_id  IN
            <foreach collection="salaryAcctEmployeeIds" open="(" item="acctEmpId" separator="," close=")">
                #{acctEmpId}
            </foreach>
        </if>

        <if test="exceptItems != null and exceptItems.size()>0">
            AND salary_item_id NOT IN
            <foreach collection="exceptItems" open="(" item="itemId" separator="," close=")">
                #{itemId}
            </foreach>
        </if>

    </update>


</mapper>