<?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.report.SalaryAcctResultReportMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.report.po.SalaryAcctResultReportPO">
        <result column="id" property="id"/>
        <result column="salary_sob_id" property="salarySobId"/>
        <result column="salary_acct_emp_id" property="salaryAcctEmpId"/>
        <result column="salary_acct_record_id" property="salaryAcctRecordId"/>
        <result column="employee_id" property="employeeId"/>
        <result column="tax_agent_id" property="taxAgentId"/>
        <result column="salary_item_id" property="salaryItemId"/>
        <result column="result_value" property="resultValue"/>
        <result column="creator" property="creator"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="delete_type" property="deleteType"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="department_id" property="departmentId"/>
        <result column="subcompany_id" property="subcompanyId"/>
        <result column="costcenter_id" property="costcenterId"/>
        <result column="jobtitle_id" property="jobtitleId"/>
        <result column="location_id" property="locationId"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.salary_sob_id
        , t.salary_acct_emp_id
        , t.salary_acct_record_id
        , t.employee_id
        , t.tax_agent_id
        , t.salary_item_id
        , t.result_value
        , t.creator
        , t.create_time
        , t.update_time
        , t.delete_type
        , t.tenant_key
        , t.department_id
        , t.subcompany_id
        , t.costcenter_id
        , t.jobtitle_id
        , t.location_id
    </sql>


    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.report.po.SalaryAcctResultReportPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_acct_result_report t
        WHERE delete_type = 0
        <if test="salarySobId != null">
            AND salary_sob_id = #{salarySobId}
        </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="employeeId != null">
            AND employee_id = #{employeeId}
        </if>
        <if test="taxAgentId != null">
            AND tax_agent_id = #{taxAgentId}
        </if>
        <if test="salaryItemId != null">
            AND salary_item_id = #{salaryItemId}
        </if>
        <if test="resultValue != null">
            AND result_value = #{resultValue}
        </if>
        <if test="creator != null">
            AND creator = #{creator}
        </if>
        <if test="createTime != null">
            AND create_time = #{createTime}
        </if>
        <if test="updateTime != null">
            AND update_time = #{updateTime}
        </if>
        <if test="deleteType != null">
            AND delete_type = #{deleteType}
        </if>
        <if test="tenantKey != null">
            AND tenant_key = #{tenantKey}
        </if>
        <if test="departmentId != null">
            AND department_id = #{departmentId}
        </if>
        <if test="subcompanyId != null">
            AND subcompany_id = #{subcompanyId}
        </if>
        <if test="costcenterId != null">
            AND costcenter_id = #{costcenterId}
        </if>
        <if test="jobtitleId != null">
            AND jobtitle_id = #{jobtitleId}
        </if>
        <if test="locationId != null">
            AND location_id = #{locationId}
        </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>


    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.report.po.SalaryAcctResultReportPO">
        INSERT INTO hrsa_salary_acct_result_report
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="costcenterId != null">
                costcenter_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="departmentId != null">
                department_id,
            </if>
            <if test="employeeId != null">
                employee_id,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="jobtitleId != null">
                jobtitle_id,
            </if>
            <if test="locationId != null">
                location_id,
            </if>
            <if test="resultValue != null">
                result_value,
            </if>
            <if test="originResultValue != null">
                origin_result_value,
            </if>
            <if test="salaryAcctEmpId != null">
                salary_acct_emp_id,
            </if>
            <if test="salaryAcctRecordId != null">
                salary_acct_record_id,
            </if>
            <if test="salaryItemId != null">
                salary_item_id,
            </if>
            <if test="salarySobId != null">
                salary_sob_id,
            </if>
            <if test="subcompanyId != null">
                subcompany_id,
            </if>
            <if test="taxAgentId != null">
                tax_agent_id,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="costcenterId != null">
                #{costcenterId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="departmentId != null">
                #{departmentId},
            </if>
            <if test="employeeId != null">
                #{employeeId},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="jobtitleId != null">
                #{jobtitleId},
            </if>
            <if test="locationId != null">
                #{locationId},
            </if>
            <if test="resultValue != null">
                #{resultValue},
            </if>
            <if test="originResultValue != null">
                #{originResultValue},
            </if>
            <if test="salaryAcctEmpId != null">
                #{salaryAcctEmpId},
            </if>
            <if test="salaryAcctRecordId != null">
                #{salaryAcctRecordId},
            </if>
            <if test="salaryItemId != null">
                #{salaryItemId},
            </if>
            <if test="salarySobId != null">
                #{salarySobId},
            </if>
            <if test="subcompanyId != null">
                #{subcompanyId},
            </if>
            <if test="taxAgentId != null">
                #{taxAgentId},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>


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

    <insert id="batchInsert">
        INSERT INTO hrsa_salary_acct_result_report(
        id
        , salary_sob_id
        , salary_acct_emp_id
        , salary_acct_record_id
        , employee_id
        , tax_agent_id
        , salary_item_id
        , result_value
        , creator
        , create_time
        , update_time
        , delete_type
        , tenant_key
        , department_id
        , subcompany_id
        , costcenter_id
        , jobtitle_id
        , location_id)
        VALUES
        <foreach collection="collection" item="item" separator=",">
            (
            #{item.id}
            , #{item.salarySobId}
            , #{item.salaryAcctEmpId}
            , #{item.salaryAcctRecordId}
            , #{item.employeeId}
            , #{item.taxAgentId}
            , #{item.salaryItemId}
            , #{item.resultValue}
            , #{item.creator}
            , #{item.createTime}
            , #{item.updateTime}
            , #{item.deleteType}
            , #{item.tenantKey}
            , #{item.departmentId}
            , #{item.subcompanyId}
            , #{item.costcenterId}
            , #{item.jobtitleId}
            , #{item.locationId}
            )
        </foreach>
    </insert>

    <insert id="batchInsert" databaseId="oracle">
        INSERT INTO hrsa_salary_acct_result_report(
        id
        , salary_sob_id
        , salary_acct_emp_id
        , salary_acct_record_id
        , employee_id
        , tax_agent_id
        , salary_item_id
        , result_value
        , creator
        , create_time
        , update_time
        , delete_type
        , tenant_key
        , department_id
        , subcompany_id
        , costcenter_id
        , jobtitle_id
        , location_id)
        <foreach collection="collection" item="item" separator="union all">
            select
            #{item.id,jdbcType=DOUBLE}
            , #{item.salarySobId,jdbcType=DOUBLE}
            , #{item.salaryAcctEmpId,jdbcType=VARCHAR}
            , #{item.salaryAcctRecordId,jdbcType=DOUBLE}
            , #{item.employeeId,jdbcType=VARCHAR}
            , #{item.taxAgentId,jdbcType=DOUBLE}
            , #{item.salaryItemId,jdbcType=DOUBLE}
            , #{item.resultValue,jdbcType=VARCHAR}
            , #{item.creator,jdbcType=DOUBLE}
            , #{item.createTime,jdbcType=DATE}
            , #{item.updateTime,jdbcType=DATE}
            , #{item.deleteType,jdbcType=INTEGER}
            , #{item.tenantKey,jdbcType=VARCHAR}
            , #{item.departmentId,jdbcType=DOUBLE}
            , #{item.subcompanyId,jdbcType=DOUBLE}
            , #{item.costcenterId,jdbcType=DOUBLE}
            , #{item.jobtitleId,jdbcType=DOUBLE}
            , #{item.locationId,jdbcType=DOUBLE}
            from dual
        </foreach>
    </insert>

    <insert id="batchInsert" databaseId="sqlserver">
        <foreach collection="collection" item="item" separator=";">
            INSERT INTO hrsa_salary_acct_result_report
            (
            id
            , salary_sob_id
            , salary_acct_emp_id
            , salary_acct_record_id
            , employee_id
            , tax_agent_id
            , salary_item_id
            , result_value
            , creator
            , create_time
            , update_time
            , delete_type
            , tenant_key
            , department_id
            , subcompany_id
            , costcenter_id
            , jobtitle_id
            , location_id)
            VALUES
            (
            #{item.id}
            , #{item.salarySobId}
            , #{item.salaryAcctEmpId}
            , #{item.salaryAcctRecordId}
            , #{item.employeeId}
            , #{item.taxAgentId}
            , #{item.salaryItemId}
            , #{item.resultValue}
            , #{item.creator}
            , #{item.createTime}
            , #{item.updateTime}
            , #{item.deleteType}
            , #{item.tenantKey}
            , #{item.departmentId}
            , #{item.subcompanyId}
            , #{item.costcenterId}
            , #{item.jobtitleId}
            , #{item.locationId}
            )
        </foreach>
    </insert>


    <delete id="deleteBySalaryAcctRecordIds">
        DELETE FROM hrsa_salary_acct_result_report
        WHERE delete_type = 0
        AND salary_acct_record_id IN
        <foreach collection="list" open="(" item="salaryAcctRecordId" separator="," close=")">
            #{salaryAcctRecordId}
        </foreach>
    </delete>

    <delete id="deleteBySalaryAcctRecordId">
        DELETE
        FROM hrsa_salary_acct_result_report
        WHERE delete_type = 0
          AND salary_acct_record_id = #{salaryAcctRecordId}
    </delete>

    <delete id="deleteBySalaryAcctEmpIds">
        DELETE FROM hrsa_salary_acct_result_report
        WHERE delete_type = 0
        AND salary_acct_emp_id IN
        <foreach collection="list" open="(" item="salaryAcctEmpId" separator="," close=")">
            #{salaryAcctEmpId}
        </foreach>
    </delete>


    <delete id="deleteByAcctEmpIdsAndSalaryItemIds">
        DELETE FROM hrsa_salary_acct_result_report
        WHERE delete_type = 0
        AND salary_acct_emp_id IN
        <foreach collection="salaryAcctEmpIds" open="(" item="salaryAcctEmpId" separator="," close=")">
            #{salaryAcctEmpId}
        </foreach>
        AND salary_item_id IN
        <foreach collection="salaryItemIds" open="(" item="salaryItemId" separator="," close=")">
            #{salaryItemId}
        </foreach>
    </delete>

</mapper>