<?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.SpecialAddDeductionMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO">
        <!--@mbg.generated-->
        <!--@Table hrsa_special_add_deduction-->
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="employee_id" jdbcType="BIGINT" property="employeeId"/>
        <result column="tax_agent_id" jdbcType="BIGINT" property="taxAgentId"/>
        <result column="children_education" jdbcType="VARCHAR" property="childrenEducation"/>
        <result column="continuing_education" jdbcType="VARCHAR" property="continuingEducation"/>
        <result column="housing_loan_interest" jdbcType="VARCHAR" property="housingLoanInterest"/>
        <result column="housing_rent" jdbcType="VARCHAR" property="housingRent"/>
        <result column="supporting_elder" jdbcType="VARCHAR" property="supportingElder"/>
        <result column="serious_illness_treatment" jdbcType="VARCHAR" property="seriousIllnessTreatment"/>
        <result column="infant_care" jdbcType="VARCHAR" property="infantCare"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="creator" jdbcType="BIGINT" property="creator"/>
        <result column="delete_type" jdbcType="INTEGER" property="deleteType"/>
        <result column="tenant_key" jdbcType="VARCHAR" property="tenantKey"/>
    </resultMap>

    <sql id="Base_Column_List">
        t1.id,
        t1.employee_id,
        t1.tax_agent_id,
        t1.children_education,
        t1.continuing_education,
        t1.housing_loan_interest,
        t1.housing_rent,
        t1.supporting_elder,
        t1.serious_illness_treatment,
        t1.infant_care,
        t1.create_time,
        t1.update_time,
        t1.creator,
        t1.delete_type,
        t1.tenant_key
    </sql>

    <sql id="Special_Column_List">
        t1.id,
        t1.employee_id,
        t2.id              AS tax_agent_id,
        t2.name            AS tax_agent_name,
        e.lastname         as username,
        e.certificatenum   as idNo,
        d.departmentname   AS departmentName,
        e.mobile,
        e.workcode         as job_num,
        e.companystartdate as hiredate,
        t1.children_education,
        t1.continuing_education,
        t1.housing_loan_interest,
        t1.housing_rent,
        t1.serious_illness_treatment,
        t1.supporting_elder,
        t1.infant_care
    </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.specialAddDeductionId != null">
            AND t1.id = #{param.specialAddDeductionId}
        </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.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.specialAddDeductionId != null">
            AND t1.id = #{param.specialAddDeductionId}
        </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.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.specialAddDeductionId != null">
            AND t1.id = #{param.specialAddDeductionId}
        </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.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="getById" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from hrsa_special_add_deduction t1
        where id = #{id,jdbcType=BIGINT}
    </select>
    <insert id="insertSelective" keyColumn="id" keyProperty="id"
            parameterType="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO" useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into hrsa_special_add_deduction
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="employeeId != null">
                employee_id,
            </if>
            <if test="taxAgentId != null">
                tax_agent_id,
            </if>
            <if test="childrenEducation != null">
                children_education,
            </if>
            <if test="continuingEducation != null">
                continuing_education,
            </if>
            <if test="housingLoanInterest != null">
                housing_loan_interest,
            </if>
            <if test="housingRent != null">
                housing_rent,
            </if>
            <if test="supportingElder != null">
                supporting_elder,
            </if>
            <if test="seriousIllnessTreatment != null">
                serious_illness_treatment,
            </if>
            <if test="infantCare != null">
                infant_care,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            delete_type,
            <if test="tenantKey != null">
                tenant_key,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="employeeId != null">
                #{employeeId,jdbcType=BIGINT},
            </if>
            <if test="taxAgentId != null">
                #{taxAgentId,jdbcType=BIGINT},
            </if>
            <if test="childrenEducation != null">
                #{childrenEducation,jdbcType=VARCHAR},
            </if>
            <if test="continuingEducation != null">
                #{continuingEducation,jdbcType=VARCHAR},
            </if>
            <if test="housingLoanInterest != null">
                #{housingLoanInterest,jdbcType=VARCHAR},
            </if>
            <if test="housingRent != null">
                #{housingRent,jdbcType=VARCHAR},
            </if>
            <if test="supportingElder != null">
                #{supportingElder,jdbcType=VARCHAR},
            </if>
            <if test="seriousIllnessTreatment != null">
                #{seriousIllnessTreatment,jdbcType=VARCHAR},
            </if>
            <if test="infantCare != null">
                #{infantCare,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="creator != null">
                #{creator,jdbcType=BIGINT},
            </if>
            0,
            <if test="tenantKey != null">
                #{tenantKey,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <insert id="insertSelective" databaseId="oracle"
            parameterType="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO">
        <selectKey  keyProperty="id" resultType="long" order="AFTER">
            select hrsa_special_a_d_id.currval from dual
        </selectKey>
        insert into hrsa_special_add_deduction
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="employeeId != null">
                employee_id,
            </if>
            <if test="taxAgentId != null">
                tax_agent_id,
            </if>
            <if test="childrenEducation != null">
                children_education,
            </if>
            <if test="continuingEducation != null">
                continuing_education,
            </if>
            <if test="housingLoanInterest != null">
                housing_loan_interest,
            </if>
            <if test="housingRent != null">
                housing_rent,
            </if>
            <if test="supportingElder != null">
                supporting_elder,
            </if>
            <if test="seriousIllnessTreatment != null">
                serious_illness_treatment,
            </if>
            <if test="infantCare != null">
                infant_care,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            delete_type,
            <if test="tenantKey != null">
                tenant_key,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="employeeId != null">
                #{employeeId,jdbcType=BIGINT},
            </if>
            <if test="taxAgentId != null">
                #{taxAgentId,jdbcType=BIGINT},
            </if>
            <if test="childrenEducation != null">
                #{childrenEducation,jdbcType=VARCHAR},
            </if>
            <if test="continuingEducation != null">
                #{continuingEducation,jdbcType=VARCHAR},
            </if>
            <if test="housingLoanInterest != null">
                #{housingLoanInterest,jdbcType=VARCHAR},
            </if>
            <if test="housingRent != null">
                #{housingRent,jdbcType=VARCHAR},
            </if>
            <if test="supportingElder != null">
                #{supportingElder,jdbcType=VARCHAR},
            </if>
            <if test="seriousIllnessTreatment != null">
                #{seriousIllnessTreatment,jdbcType=VARCHAR},
            </if>
            <if test="infantCare != null">
                #{infantCare,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="creator != null">
                #{creator,jdbcType=BIGINT},
            </if>
            0,
            <if test="tenantKey != null">
                #{tenantKey,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective"
            parameterType="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO">
        <!--@mbg.generated-->
        update hrsa_special_add_deduction
        <set>
            <if test="employeeId != null">
                employee_id = #{employeeId,jdbcType=BIGINT},
            </if>
            <if test="taxAgentId != null">
                tax_agent_id = #{taxAgentId,jdbcType=BIGINT},
            </if>
            <if test="childrenEducation != null">
                children_education = #{childrenEducation,jdbcType=VARCHAR},
            </if>
            <if test="continuingEducation != null">
                continuing_education = #{continuingEducation,jdbcType=VARCHAR},
            </if>
            <if test="housingLoanInterest != null">
                housing_loan_interest = #{housingLoanInterest,jdbcType=VARCHAR},
            </if>
            <if test="housingRent != null">
                housing_rent = #{housingRent,jdbcType=VARCHAR},
            </if>
            <if test="supportingElder != null">
                supporting_elder = #{supportingElder,jdbcType=VARCHAR},
            </if>
            <if test="seriousIllnessTreatment != null">
                serious_illness_treatment = #{seriousIllnessTreatment,jdbcType=VARCHAR},
            </if>
            <if test="infantCare != null">
                infant_care = #{infantCare,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="creator != null">
                creator = #{creator,jdbcType=BIGINT},
            </if>
            <if test="deleteType != null">
                delete_type = #{deleteType,jdbcType=INTEGER},
            </if>
            <if test="tenantKey != null">
                tenant_key = #{tenantKey,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

    <update id="updateBatchSelective" parameterType="java.util.List">
        <!--@mbg.generated-->
        update hrsa_special_add_deduction
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="employee_id = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.employeeId != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.employeeId,jdbcType=BIGINT}
                    </if>
                </foreach>
            </trim>
            <trim prefix="tax_agent_id = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.taxAgentId != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.taxAgentId,jdbcType=BIGINT}
                    </if>
                </foreach>
            </trim>
            <trim prefix="children_education = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.childrenEducation != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.childrenEducation,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="continuing_education = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.continuingEducation != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.continuingEducation,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="housing_loan_interest = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.housingLoanInterest != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.housingLoanInterest,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="housing_rent = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.housingRent != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.housingRent,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="supporting_elder = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.supportingElder != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.supportingElder,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="serious_illness_treatment = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.seriousIllnessTreatment != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.seriousIllnessTreatment,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="infant_care = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.infantCare != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.infantCare,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="create_time = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.createTime != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.createTime,jdbcType=TIMESTAMP}
                    </if>
                </foreach>
            </trim>
            <trim prefix="update_time = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.updateTime != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.updateTime,jdbcType=TIMESTAMP}
                    </if>
                </foreach>
            </trim>
            <trim prefix="creator = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.creator != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.creator,jdbcType=BIGINT}
                    </if>
                </foreach>
            </trim>
            <trim prefix="delete_type = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.deleteType != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.deleteType,jdbcType=INTEGER}
                    </if>
                </foreach>
            </trim>
            <trim prefix="tenant_key = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.tenantKey != null">
                        when id = #{item.id,jdbcType=BIGINT} then #{item.tenantKey,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
        </trim>
        where id in
        <foreach close=")" collection="list" item="item" open="(" separator=", ">
            #{item.id,jdbcType=BIGINT}
        </foreach>
    </update>

    <insert id="batchInsert" parameterType="map">
        <!--@mbg.generated-->
        insert into hrsa_special_add_deduction
        (employee_id, tax_agent_id, children_education, continuing_education,
         housing_loan_interest, housing_rent, supporting_elder, serious_illness_treatment,
         infant_care, create_time, update_time, creator, delete_type, tenant_key)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.employeeId,jdbcType=BIGINT}, #{item.taxAgentId,jdbcType=BIGINT},
             #{item.childrenEducation,jdbcType=VARCHAR}, #{item.continuingEducation,jdbcType=VARCHAR},
             #{item.housingLoanInterest,jdbcType=VARCHAR}, #{item.housingRent,jdbcType=VARCHAR},
             #{item.supportingElder,jdbcType=VARCHAR}, #{item.seriousIllnessTreatment,jdbcType=VARCHAR},
             #{item.infantCare,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
             #{item.updateTime,jdbcType=TIMESTAMP},
             #{item.creator,jdbcType=BIGINT}, 0, #{item.tenantKey,jdbcType=VARCHAR})
        </foreach>
    </insert>

    <insert id="batchInsert" parameterType="map" databaseId="oracle">
        insert into hrsa_special_add_deduction
        (employee_id, tax_agent_id, children_education, continuing_education,
        housing_loan_interest, housing_rent, supporting_elder, serious_illness_treatment,
        infant_care, create_time, update_time, creator, delete_type, tenant_key)
        <foreach collection="list" item="item" separator=" union all ">
            select
            #{item.employeeId,jdbcType=BIGINT}, #{item.taxAgentId,jdbcType=BIGINT},
            #{item.childrenEducation,jdbcType=VARCHAR}, #{item.continuingEducation,jdbcType=VARCHAR},
            #{item.housingLoanInterest,jdbcType=VARCHAR}, #{item.housingRent,jdbcType=VARCHAR},
            #{item.supportingElder,jdbcType=VARCHAR}, #{item.seriousIllnessTreatment,jdbcType=VARCHAR},
            #{item.infantCare,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
            #{item.updateTime,jdbcType=TIMESTAMP},
            #{item.creator,jdbcType=BIGINT}, 0, #{item.tenantKey,jdbcType=VARCHAR}
            from dual
        </foreach>
    </insert>

    <select id="listDtoByParam" resultType="com.engine.salary.entity.datacollection.dto.SpecialAddDeductionRecordDTO">
        select
        <include refid="Special_Column_List"/>
        from hrsa_special_add_deduction t1
        LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        LEFT JOIN hrmdepartment d ON d.id = e.departmentid
        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"/>
        ORDER BY  t1.create_time desc
    </select>

    <select id="listByTaxAgentIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from hrsa_special_add_deduction t1
        LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        WHERE
        t1.delete_type = 0 AND t2.delete_type = 0
        AND e.status not in (7)

        <if test="taxAgentIds != null and taxAgentIds.size() != 0">
            AND t1.tax_agent_id IN
            <foreach collection="taxAgentIds" open="(" item="taxAgentId" separator="," close=")">
                #{taxAgentId}
            </foreach>
        </if>
    </select>

    <select id="listByParam" resultType="com.engine.salary.entity.datacollection.dto.SpecialAddDeductionListDTO">
        select
        <include refid="Special_Column_List"/>
        from hrsa_special_add_deduction t1
        LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        LEFT JOIN hrmdepartment d ON d.id = e.departmentid
        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>

    <delete id="deleteByIds">
        update hrsa_special_add_deduction
        set delete_type = 1
        where id in (
            <foreach collection="ids" item="id" separator=",">
                #{id}
            </foreach>
            ) and delete_type = 0
    </delete>

    <select id="getByEmployeeIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from hrsa_special_add_deduction t1
        <where>
            <if test="employeeIds != null and employeeIds.size() != 0">
                <foreach collection="employeeIds" item="employeeId" separator="," open="employee_id in (" close=") ">
                    #{employeeId}
                </foreach>
            </if>
            and tax_agent_id = #{taxAgentId}
            and delete_type = 0
        </where>
    </select>

    <select id="listAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from hrsa_special_add_deduction t1
    </select>

    <select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO">
        SELECT
        <include refid="Base_Column_List" />
        FROM hrsa_special_add_deduction t1
        WHERE delete_type = 0
        <if test="childrenEducation != null">
            AND children_education = #{childrenEducation}
        </if>
        <if test="continuingEducation != null">
            AND continuing_education = #{continuingEducation}
        </if>
        <if test="createTime != null">
            AND create_time = #{createTime}
        </if>
        <if test="creator != null">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null">
            AND delete_type = #{deleteType}
        </if>
        <if test="employeeId != null">
            AND employee_id = #{employeeId}
        </if>
        <if test="housingLoanInterest != null">
            AND housing_loan_interest = #{housingLoanInterest}
        </if>
        <if test="housingRent != null">
            AND housing_rent = #{housingRent}
        </if>
        <if test="infantCare != null">
            AND infant_care = #{infantCare}
        </if>
        <if test="seriousIllnessTreatment != null">
            AND serious_illness_treatment = #{seriousIllnessTreatment}
        </if>
        <if test="supportingElder != null">
            AND supporting_elder = #{supportingElder}
        </if>
        <if test="taxAgentId != null">
            AND tax_agent_id = #{taxAgentId}
        </if>
        <if test="tenantKey != null">
            AND tenant_key = #{tenantKey}
        </if>
        <if test="updateTime != null">
            AND update_time = #{updateTime}
        </if>
        <if test="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="employeeIds != null and employeeIds.size()>0">
            AND employee_id IN
            <foreach collection="employeeIds" open="(" item="empId" separator="," close=")">
                #{empId}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>
</mapper>