<?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.datacollection.AddUpSituationMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.datacollection.AddUpSituation">
        <result column="add_up_accumulation_fund_total" property="addUpAccumulationFundTotal"/>
        <result column="add_up_advance_tax" property="addUpAdvanceTax"/>
        <result column="add_up_allowed_donation" property="addUpAllowedDonation"/>
        <result column="add_up_child_education" property="addUpChildEducation"/>
        <result column="add_up_continuing_education" property="addUpContinuingEducation"/>
        <result column="add_up_enterprise_and_other" property="addUpEnterpriseAndOther"/>
        <result column="add_up_housing_loan_interest" property="addUpHousingLoanInterest"/>
        <result column="add_up_housing_rent" property="addUpHousingRent"/>
        <result column="add_up_income" property="addUpIncome"/>
        <result column="add_up_other_deduction" property="addUpOtherDeduction"/>
        <result column="add_up_social_security_total" property="addUpSocialSecurityTotal"/>
        <result column="add_up_subtraction" property="addUpSubtraction"/>
        <result column="add_up_support_elderly" property="addUpSupportElderly"/>
        <result column="add_up_tax_exempt_income" property="addUpTaxExemptIncome"/>
        <result column="add_up_illness_medical" property="addUpIllnessMedical"/>
        <result column="add_up_tax_savings" property="addUpTaxSavings"/>
        <result column="add_up_infant_care" property="addUpInfantCare"/>
        <result column="add_up_private_pension" property="addUpPrivatePension"/>
        <result column="create_time" property="createTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="employee_id" property="employeeId"/>
        <result column="id" property="id"/>
        <result column="tax_agent_id" property="taxAgentId"/>
        <result column="tax_year_month" property="taxYearMonth"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="update_time" property="updateTime"/>
        <result column="year" property="year"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        add_up_accumulation_fund_total
        , t.add_up_advance_tax
        , t.add_up_allowed_donation
        , t.add_up_child_education
        , t.add_up_continuing_education
        , t.add_up_enterprise_and_other
        , t.add_up_housing_loan_interest
        , t.add_up_housing_rent
        , t.add_up_income
        , t.add_up_other_deduction
        , t.add_up_social_security_total
        , t.add_up_subtraction
        , t.add_up_support_elderly
        , t.add_up_tax_exempt_income
        , t.create_time
        , t.creator
        , t.delete_type
        , t.employee_id
        , t.id
        , t.tax_agent_id
        , t.tax_year_month
        , t.tenant_key
        , t.update_time
        , t.year
        , t.add_up_illness_medical
        , t.add_up_tax_savings
        , t.add_up_infant_care
        , t.add_up_private_pension
    </sql>

    <!--批量删除-->
    <update id="deleteData">
        UPDATE hrsa_add_up_situation
        SET delete_type = 1
        WHERE delete_type = 0
        AND id IN
        <foreach collection="collection" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </update>

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

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


    <sql id="addUpSituationColumn">
        t1
        .
        id
        ,
        t1.tax_year_month,
        t1.employee_id,
        e.lastname as username,
        d.departmentName AS departmentName,
        e.mobile,
        e.workcode as job_num,
        e.companystartdate as hiredate,
        e.certificatenum as idNo,
        t2.name AS tax_agent_name,
        t2.id AS tax_agent_id,
        t1.add_up_income,
        t1.add_up_subtraction,
        t1.add_up_social_security_total,
        t1.add_up_accumulation_fund_total,
        t1.add_up_child_education,
        t1.add_up_continuing_education,
        t1.add_up_housing_loan_interest,
        t1.add_up_housing_rent,
        t1.add_up_support_elderly,
        t1.add_up_illness_medical,
        t1.add_up_infant_care,
        t1.add_up_private_pension,
        t1.add_up_enterprise_and_other,
        t1.add_up_other_deduction,
        t1.add_up_tax_exempt_income,
        t1.add_up_allowed_donation,
        t1.add_up_tax_savings,
        t1.add_up_advance_tax
    </sql>

    <sql id="paramSql">
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="param.year != null">
            AND t1.year = #{param.year}
        </if>
        <if test="param.employeeId != null">
            AND t1.employee_id = #{param.employeeId}
        </if>
        <!-- 关键字（姓名、部门、工号 -->
        <if test="param.keyword != null and param.keyword != ''">
            AND
            (
            e.lastname like CONCAT('%',#{param.keyword},'%')
            OR d.departmentname like CONCAT('%',#{param.keyword},'%')
            OR e.workcode like CONCAT('%',#{param.keyword},'%')
            )
        </if>
        <!-- 税款所属期 -->
        <if test="param.taxYearMonthDate != null">
            <if test="param.taxYearMonthDate.size() == 1">
                AND t1.tax_year_month = #{param.taxYearMonthDate[0]}
            </if>
            <if test="param.taxYearMonthDate.size() == 2">
                AND (t1.tax_year_month BETWEEN #{param.taxYearMonthDate[0]} AND #{param.taxYearMonthDate[1]})
            </if>
        </if>
        <!-- 姓名 -->
        <if test="param.username != null and param.username != ''">
            AND e.lastname like CONCAT('%',#{param.username},'%')
        </if>
        <if test="param.taxAgentId != null">
            AND t1.tax_agent_id = #{param.taxAgentId}
        </if>
        <if test="param.taxAgentIds != null and param.taxAgentIds.size()>0">
            AND t1.tax_agent_id IN
            <foreach collection="param.taxAgentIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <!-- 部门 -->
        <if test="param.departmentIds != null and param.departmentIds.size()>0">
            AND d.id IN
            <foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <!-- 工号 -->
        <if test="param.jobNum != null and param.jobNum != ''">
            AND e.workcode like CONCAT('%',#{param.jobNum},'%')
        </if>
        <!-- 入职日期 -->
        <if test="param.hiredate != null and param.hiredate.size() == 2">
            AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
        </if>
        <!-- 手机号 -->
        <if test="param.mobile != null and param.mobile != ''">
            AND e.mobile like CONCAT('%',#{param.mobile},'%')
        </if>
    </sql>
    <sql id="paramSql" databaseId="oracle">
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="param.year != null">
            AND t1.year = #{param.year}
        </if>
        <if test="param.employeeId != null">
            AND t1.employee_id = #{param.employeeId}
        </if>

        <if test="param.keyword != null and param.keyword != ''">
            AND
            (
            e.lastname like '%'||#{param.keyword}||'%'
            OR d.departmentname like '%'||#{param.keyword}||'%'
            OR e.workcode like '%'||#{param.keyword}||'%'
            )
        </if>

        <if test="param.taxYearMonthDate != null">
            <if test="param.taxYearMonthDate.size() == 1">
                AND t1.tax_year_month = #{param.taxYearMonthDate[0]}
            </if>
            <if test="param.taxYearMonthDate.size() == 2">
                AND (t1.tax_year_month BETWEEN #{param.taxYearMonthDate[0]} AND #{param.taxYearMonthDate[1]})
            </if>
        </if>

        <if test="param.username != null and param.username != ''">
            AND e.lastname like '%'||#{param.username}||'%'
        </if>
        <if test="param.taxAgentId != null">
            AND t1.tax_agent_id = #{param.taxAgentId}
        </if>
        <if test="param.taxAgentIds != null and param.taxAgentIds.size()>0">
            AND t1.tax_agent_id IN
            <foreach collection="param.taxAgentIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="param.departmentIds != null and param.departmentIds.size()>0">
            AND d.id IN
            <foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.jobNum != null and param.jobNum != ''">
            AND e.workcode like '%'||#{param.jobNum}||'%'
        </if>

        <if test="param.hiredate != null and param.hiredate.size() == 2">
            AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
        </if>

        <if test="param.mobile != null and param.mobile != ''">
            AND e.mobile like '%'||#{param.mobile}||'%'
        </if>
    </sql>
    <sql id="paramSql" databaseId="sqlserver">
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="param.year != null">
            AND t1.year = #{param.year}
        </if>
        <if test="param.employeeId != null">
            AND t1.employee_id = #{param.employeeId}
        </if>

        <if test="param.keyword != null and param.keyword != ''">
            AND
            (
            e.lastname like '%'+#{param.keyword}+'%'
            OR d.departmentname like '%'+#{param.keyword}+'%'
            OR e.workcode like '%'+#{param.keyword}+'%'
            )
        </if>

        <if test="param.taxYearMonthDate != null">
            <if test="param.taxYearMonthDate.size() == 1">
                AND t1.tax_year_month = #{param.taxYearMonthDate[0]}
            </if>
            <if test="param.taxYearMonthDate.size() == 2">
                AND (t1.tax_year_month BETWEEN #{param.taxYearMonthDate[0]} AND #{param.taxYearMonthDate[1]})
            </if>
        </if>

        <if test="param.username != null and param.username != ''">
            AND e.lastname like '%'+#{param.username}+'%'
        </if>
        <if test="param.taxAgentId != null">
            AND t1.tax_agent_id = #{param.taxAgentId}
        </if>
        <if test="param.taxAgentIds != null and param.taxAgentIds.size()>0">
            AND t1.tax_agent_id IN
            <foreach collection="param.taxAgentIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="param.departmentIds != null and param.departmentIds.size()>0">
            AND d.id IN
            <foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.jobNum != null and param.jobNum != ''">
            AND e.workcode like '%'+#{param.jobNum}+'%'
        </if>

        <if test="param.hiredate != null and param.hiredate.size() == 2">
            AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
        </if>

        <if test="param.mobile != null and param.mobile != ''">
            AND e.mobile like '%'+#{param.mobile}+'%'
        </if>
    </sql>

    <select id="list" resultType="com.engine.salary.entity.datacollection.dto.AddUpSituationDTO">
        SELECT
        <include refid="addUpSituationColumn"/>
        FROM
        hrsa_add_up_situation t1
--         INNER JOIN
--         (SELECT employee_id, MAX(tax_year_month) tax_year_month FROM hrsa_add_up_situation WHERE delete_type = 0 GROUP BY employee_id) t ON
--         t.employee_id = t1.employee_id AND t.tax_year_month = t1.tax_year_month
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        LEFT JOIN hrmdepartment d ON d.id = e.departmentid
        LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
        LEFT JOIN hrmsubcompany c ON c.id = e.subcompanyid1
        WHERE
        t1.delete_type = 0
        AND t2.delete_type = 0
        AND e.status not in (7)

        <include refid="paramSql"/>
        <!-- 排序 -->
        <if test="param.orderRule != null">
            ORDER BY  ${param.orderRule.orderRule}  ${param.orderRule.ascOrDesc}
        </if>
    </select>
    <select id="list" resultType="com.engine.salary.entity.datacollection.dto.AddUpSituationDTO"
            databaseId="oracle">
        SELECT
        <include refid="addUpSituationColumn"/>
        FROM
        hrsa_add_up_situation t1
--         INNER JOIN
--         (SELECT employee_id, MAX(tax_year_month) tax_year_month FROM hrsa_add_up_situation WHERE delete_type = 0  GROUP BY employee_id) t ON
--         t.employee_id = t1.employee_id AND t.tax_year_month = t1.tax_year_month
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        LEFT JOIN hrmdepartment d ON d.id = e.departmentid
        LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
        LEFT JOIN hrmsubcompany c ON c.id = e.subcompanyid1
        WHERE
        t1.delete_type = 0
        AND t2.delete_type = 0
        AND e.status not in (7)

        <include refid="paramSql"/>
        <!-- 排序 -->
        <if test="param.orderRule != null">
            ORDER BY  ${param.orderRule.orderRule}  ${param.orderRule.ascOrDesc}
        </if>
    </select>
    <select id="list" resultType="com.engine.salary.entity.datacollection.dto.AddUpSituationDTO"
            databaseId="sqlserver">
        SELECT
        <include refid="addUpSituationColumn"/>
        FROM
        hrsa_add_up_situation t1
--         INNER JOIN
--         (SELECT employee_id, MAX(tax_year_month) tax_year_month FROM hrsa_add_up_situation  WHERE delete_type = 0 GROUP BY employee_id) t ON
--         t.employee_id = t1.employee_id AND t.tax_year_month = t1.tax_year_month
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        LEFT JOIN hrmdepartment d ON d.id = e.departmentid
        LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
        LEFT JOIN hrmsubcompany c ON c.id = e.subcompanyid1
        WHERE
        t1.delete_type = 0
        AND t2.delete_type = 0
        AND e.status not in (7)

        <include refid="paramSql"/>
        <!-- 排序 -->
        <if test="param.orderRule != null">
            ORDER BY  ${param.orderRule.orderRule}  ${param.orderRule.ascOrDesc}
        </if>
    </select>


    <select id="recordList" resultType="com.engine.salary.entity.datacollection.dto.AddUpSituationRecordDTO">
        SELECT
        <include refid="addUpSituationColumn"/>
        FROM
        hrsa_add_up_situation t1
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        LEFT JOIN hrmdepartment d ON d.id = e.departmentid
        LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
        WHERE
        t1.delete_type = 0
        AND t2.delete_type = 0
        AND e.status not in (7)

        <include refid="paramSql"/>
        ORDER BY t1.tax_year_month DESC
    </select>


    <insert id="insertData">
        INSERT INTO hrsa_add_up_situation(
        employee_id,
        tax_agent_id,
        tax_year_month,
        year,
        add_up_income,
        add_up_subtraction,
        add_up_social_security_total,
        add_up_accumulation_fund_total,
        add_up_child_education,
        add_up_continuing_education,
        add_up_housing_loan_interest,
        add_up_housing_rent,
        add_up_support_elderly,
        add_up_enterprise_and_other,
        add_up_other_deduction,
        add_up_tax_exempt_income,
        add_up_allowed_donation,
        add_up_advance_tax,
        create_time,
        update_time,
        creator,
        tenant_key,
        add_up_tax_savings,
        add_up_illness_medical,
        add_up_infant_care,
        add_up_private_pension
        )
        VALUES
        <foreach collection="collection" item="item" separator=",">
            (
            #{item.employeeId},
            #{item.taxAgentId},
            #{item.taxYearMonth},
            #{item.year},
            #{item.addUpIncome},
            #{item.addUpSubtraction},
            #{item.addUpSocialSecurityTotal},
            #{item.addUpAccumulationFundTotal},
            #{item.addUpChildEducation},
            #{item.addUpContinuingEducation},
            #{item.addUpHousingLoanInterest},
            #{item.addUpHousingRent},
            #{item.addUpSupportElderly},
            #{item.addUpEnterpriseAndOther},
            #{item.addUpOtherDeduction},
            #{item.addUpTaxExemptIncome},
            #{item.addUpAllowedDonation},
            #{item.addUpAdvanceTax},
            #{item.createTime},
            #{item.updateTime},
            #{item.creator},
            #{item.tenantKey},
            #{item.addUpTaxSavings},
            #{item.addUpIllnessMedical},
            #{item.addUpInfantCare},
            #{item.addUpPrivatePension}
            )
        </foreach>
    </insert>
    <insert id="insertData" databaseId="oracle">
        INSERT INTO hrsa_add_up_situation(
        employee_id,
        tax_agent_id,
        tax_year_month,
        year,
        add_up_income,
        add_up_subtraction,
        add_up_social_security_total,
        add_up_accumulation_fund_total,
        add_up_child_education,
        add_up_continuing_education,
        add_up_housing_loan_interest,
        add_up_housing_rent,
        add_up_support_elderly,
        add_up_enterprise_and_other,
        add_up_other_deduction,
        add_up_tax_exempt_income,
        add_up_allowed_donation,
        add_up_advance_tax,
        create_time,
        update_time,
        creator,
        tenant_key,
        add_up_tax_savings,
        add_up_illness_medical,
        add_up_infant_care,
        add_up_private_pension
        )

        <foreach collection="collection" item="item" separator="union all">
            select
            #{item.employeeId,jdbcType=DOUBLE},
            #{item.taxAgentId,jdbcType=DOUBLE},
            #{item.taxYearMonth,jdbcType=DATE},
            #{item.year,jdbcType=INTEGER},
            #{item.addUpIncome,jdbcType=VARCHAR},
            #{item.addUpSubtraction,jdbcType=VARCHAR},
            #{item.addUpSocialSecurityTotal,jdbcType=VARCHAR},
            #{item.addUpAccumulationFundTotal,jdbcType=VARCHAR},
            #{item.addUpChildEducation,jdbcType=VARCHAR},
            #{item.addUpContinuingEducation,jdbcType=VARCHAR},
            #{item.addUpHousingLoanInterest,jdbcType=VARCHAR},
            #{item.addUpHousingRent,jdbcType=VARCHAR},
            #{item.addUpSupportElderly,jdbcType=VARCHAR},
            #{item.addUpEnterpriseAndOther,jdbcType=VARCHAR},
            #{item.addUpOtherDeduction,jdbcType=VARCHAR},
            #{item.addUpTaxExemptIncome,jdbcType=VARCHAR},
            #{item.addUpAllowedDonation,jdbcType=VARCHAR},
            #{item.addUpAdvanceTax,jdbcType=VARCHAR},
            #{item.createTime,jdbcType=DATE},
            #{item.updateTime,jdbcType=DATE},
            #{item.creator,jdbcType=DOUBLE},
            #{item.tenantKey,jdbcType=VARCHAR},
            #{item.addUpTaxSavings,jdbcType=VARCHAR},
            #{item.addUpIllnessMedical,jdbcType=VARCHAR},
            #{item.addUpInfantCare,jdbcType=VARCHAR},
            #{item.addUpPrivatePension,jdbcType=VARCHAR}
            from dual
        </foreach>
    </insert>
    <insert id="insertData" databaseId="sqlserver">
        <foreach collection="collection" item="item" separator=";">
            INSERT INTO hrsa_add_up_situation(
            employee_id,
            tax_agent_id,
            tax_year_month,
            year,
            add_up_income,
            add_up_subtraction,
            add_up_social_security_total,
            add_up_accumulation_fund_total,
            add_up_child_education,
            add_up_continuing_education,
            add_up_housing_loan_interest,
            add_up_housing_rent,
            add_up_support_elderly,
            add_up_enterprise_and_other,
            add_up_other_deduction,
            add_up_tax_exempt_income,
            add_up_allowed_donation,
            add_up_advance_tax,
            create_time,
            update_time,
            creator,
            tenant_key,
            add_up_tax_savings,
            add_up_illness_medical,
            add_up_infant_care,
            add_up_private_pension
            )
            VALUES
            (
            #{item.employeeId},
            #{item.taxAgentId},
            #{item.taxYearMonth},
            #{item.year},
            #{item.addUpIncome},
            #{item.addUpSubtraction},
            #{item.addUpSocialSecurityTotal},
            #{item.addUpAccumulationFundTotal},
            #{item.addUpChildEducation},
            #{item.addUpContinuingEducation},
            #{item.addUpHousingLoanInterest},
            #{item.addUpHousingRent},
            #{item.addUpSupportElderly},
            #{item.addUpEnterpriseAndOther},
            #{item.addUpOtherDeduction},
            #{item.addUpTaxExemptIncome},
            #{item.addUpAllowedDonation},
            #{item.addUpAdvanceTax},
            #{item.createTime},
            #{item.updateTime},
            #{item.creator},
            #{item.tenantKey},
            #{item.addUpTaxSavings},
            #{item.addUpIllnessMedical},
            #{item.addUpInfantCare},
            #{item.addUpPrivatePension}
            )
        </foreach>
    </insert>

    <update id="updateData" parameterType="java.util.List">
        update hrsa_add_up_situation
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="add_up_income =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpIncome!=null">
                        when id=#{item.id} then #{item.addUpIncome}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_subtraction =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpSubtraction!=null">
                        when id=#{item.id} then #{item.addUpSubtraction}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_social_security_total =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpSocialSecurityTotal!=null">
                        when id=#{item.id} then #{item.addUpSocialSecurityTotal}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_accumulation_fund_total =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpAccumulationFundTotal!=null">
                        when id=#{item.id} then #{item.addUpAccumulationFundTotal}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_child_education =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpChildEducation!=null">
                        when id=#{item.id} then #{item.addUpChildEducation}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_continuing_education =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpContinuingEducation!=null">
                        when id=#{item.id} then #{item.addUpContinuingEducation}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_housing_loan_interest =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpHousingLoanInterest!=null">
                        when id=#{item.id} then #{item.addUpHousingLoanInterest}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_housing_rent =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpHousingRent!=null">
                        when id=#{item.id} then #{item.addUpHousingRent}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_support_elderly =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpSupportElderly!=null">
                        when id=#{item.id} then #{item.addUpSupportElderly}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_enterprise_and_other =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpEnterpriseAndOther!=null">
                        when id=#{item.id} then #{item.addUpEnterpriseAndOther}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_other_deduction =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpOtherDeduction!=null">
                        when id=#{item.id} then #{item.addUpOtherDeduction}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_tax_exempt_income =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpTaxExemptIncome!=null">
                        when id=#{item.id} then #{item.addUpTaxExemptIncome}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_allowed_donation =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpAllowedDonation!=null">
                        when id=#{item.id} then #{item.addUpAllowedDonation}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_advance_tax =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpAdvanceTax!=null">
                        when id=#{item.id} then #{item.addUpAdvanceTax}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_tax_savings =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpTaxSavings!=null">
                        when id=#{item.id} then #{item.addUpTaxSavings}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_illness_medical =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpIllnessMedical!=null">
                        when id=#{item.id} then #{item.addUpIllnessMedical}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_infant_care =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpInfantCare!=null">
                        when id=#{item.id} then #{item.addUpInfantCare}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_up_private_pension =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.addUpPrivatePension!=null">
                        when id=#{item.id} then #{item.addUpPrivatePension}
                    </if>
                </foreach>
            </trim>
        </trim>
        where
        id in
        <foreach collection="collection" item="item" index="index" separator="," open="(" close=")">
            #{item.id}
        </foreach>
    </update>

    <select id="listSome" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_add_up_situation t
        WHERE delete_type = 0
        <if test="param.taxYearMonth != null">
            and tax_year_month = #{param.taxYearMonth}
        </if>
        <if test="param.taxAgentId != null">
            and tax_agent_id = #{param.taxAgentId}
        </if>
        <if test="param.employeeIds != null and param.employeeIds.size()>0">
            AND employee_id IN
            <foreach collection="param.employeeIds" open="(" item="employeeId" separator="," close=")">
                #{employeeId}
            </foreach>
        </if>
        <if test="param.taxYearMonthRange != null and param.taxYearMonthRange.size() > 1">
            AND ( tax_year_month BETWEEN #{param.taxYearMonthRange[0]} AND #{param.taxYearMonthRange[1]})
        </if>
        <if test="param.taxAgentIds != null and param.taxAgentIds.size()>0">
            AND tax_agent_id IN
            <foreach collection="param.taxAgentIds" open="(" item="taxAgentId" separator="," close=")">
                #{taxAgentId}
            </foreach>
        </if>
    </select>



    <update id="deleteByTaxYearMonthAndTaxAgentIds">
        UPDATE hrsa_add_up_situation
        SET delete_type = 1
        WHERE delete_type = 0
        AND tax_year_month = #{param.taxYearMonth}
        <if test="param.taxAgentIds != null and param.taxAgentIds.size()>0">
            AND tax_agent_id IN
            <foreach collection="param.taxAgentIds" open="(" item="taxAgentId" separator="," close=")">
                #{taxAgentId}
            </foreach>
        </if>
    </update>

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

</mapper>