<?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.yifu.cloud.plus.v1.yifu.salary.mapper.TSpecialDeducationSumMapper">

    <resultMap id="tSpecialDeducationSumMap" type="com.yifu.cloud.plus.v1.yifu.salary.entity.TSpecialDeducationSum">
        <id property="id" column="id"/>
        <result property="createBy" column="CREATE_BY"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createMonth" column="CREATE_MONTH"/>
        <result property="declareTitle" column="DECLARE_TITLE"/>
        <result property="jobNumber" column="JOB_NUMBER"/>
        <result property="name" column="NAME"/>
        <result property="type" column="TYPE"/>
        <result property="idNumber" column="ID_NUMBER"/>
        <result property="createStart" column="CREATE_START"/>
        <result property="createEnd" column="CREATE_END"/>
        <result property="currentIncome" column="CURRENT_INCOME"/>
        <result property="currentIncomeTaxFree" column="CURRENT_INCOME_TAX_FREE"/>
        <result property="insurancePension" column="INSURANCE_PENSION"/>
        <result property="insuranceMedical" column="INSURANCE_MEDICAL"/>
        <result property="insuranceUnemployment" column="INSURANCE_UNEMPLOYMENT"/>
        <result property="fund" column="FUND"/>
        <result property="sumChildEduMoney" column="SUM_CHILD_EDU_MONEY"/>
        <result property="sumHousingLoanMoney" column="SUM_HOUSING_LOAN_MONEY"/>
        <result property="sumHousingRentMoney" column="SUM_HOUSING_RENT_MONEY"/>
        <result property="sumSupportElderlyMoney" column="SUM_SUPPORT_ELDERLY_MONEY"/>
        <result property="sumContinuingEducationMoney" column="SUM_CONTINUING_EDUCATION_MONEY"/>
        <result property="sumBabyMoney" column="SUM_BABY_MONEY"/>
        <result property="sumPrivatePension" column="SUM_PRIVATE_PENSION"/>
        <result property="enterpriseAnnuity" column="ENTERPRISE_ANNUITY"/>
        <result property="takingRisks" column="TAKING_RISKS"/>
        <result property="taxDeferredInsurance" column="TAX_DEFERRED_INSURANCE"/>
        <result property="otherMoney" column="OTHER_MONEY"/>
        <result property="donationAmount" column="DONATION_AMOUNT"/>
        <result property="preTaxDeduction" column="PRE_TAX_DEDUCTION"/>
        <result property="taxSavings" column="TAX_SAVINGS"/>
        <result property="costReduction" column="COST_REDUCTION"/>
        <result property="taxesWithheld" column="TAXES_WITHHELD"/>
        <result property="remark" column="REMARK"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,
        CREATE_BY,
        CREATE_TIME,
        CREATE_MONTH,
        DECLARE_TITLE,
        JOB_NUMBER,
        NAME,
        TYPE,
        ID_NUMBER,
        CREATE_START,
        CREATE_END,
        CURRENT_INCOME,
        CURRENT_INCOME_TAX_FREE,
        INSURANCE_PENSION,
        INSURANCE_MEDICAL,
        INSURANCE_UNEMPLOYMENT,
        FUND,
        SUM_CHILD_EDU_MONEY,
        SUM_HOUSING_LOAN_MONEY,
        SUM_HOUSING_RENT_MONEY,
        SUM_SUPPORT_ELDERLY_MONEY,
        SUM_CONTINUING_EDUCATION_MONEY,
        SUM_BABY_MONEY,
        SUM_PRIVATE_PENSION,
        ENTERPRISE_ANNUITY,
        TAKING_RISKS,
        TAX_DEFERRED_INSURANCE,
        OTHER_MONEY,
        DONATION_AMOUNT,
        PRE_TAX_DEDUCTION,
        TAX_SAVINGS,
        COST_REDUCTION,
        TAXES_WITHHELD,
        REMARK
    </sql>

    <sql id="tSpecialDeducationSum_where">
        <if test="tSpecialDeducationSum != null">
            <if test="tSpecialDeducationSum.id != null and tSpecialDeducationSum.id.trim() != ''">
                AND id = #{tSpecialDeducationSum.id}
            </if>
            <if test="tSpecialDeducationSum.createBy != null and tSpecialDeducationSum.createBy.trim() != ''">
                AND CREATE_BY = #{tSpecialDeducationSum.createBy}
            </if>
            <if test="tSpecialDeducationSum.createTime != null">
                AND CREATE_TIME = #{tSpecialDeducationSum.createTime}
            </if>
            <if test="tSpecialDeducationSum.createMonth != null and tSpecialDeducationSum.createMonth.trim() != ''">
                AND CREATE_MONTH = #{tSpecialDeducationSum.createMonth}
            </if>
            <if test="tSpecialDeducationSum.declareTitle != null and tSpecialDeducationSum.declareTitle.trim() != ''">
                AND DECLARE_TITLE like '%${tSpecialDeducationSum.declareTitle}%'
            </if>
            <if test="tSpecialDeducationSum.jobNumber != null and tSpecialDeducationSum.jobNumber.trim() != ''">
                AND JOB_NUMBER = #{tSpecialDeducationSum.jobNumber}
            </if>
            <if test="tSpecialDeducationSum.name != null and tSpecialDeducationSum.name.trim() != ''">
                AND NAME like '%${tSpecialDeducationSum.name}%'
            </if>
            <if test="tSpecialDeducationSum.type != null and tSpecialDeducationSum.type.trim() != ''">
                AND TYPE = #{tSpecialDeducationSum.type}
            </if>
            <if test="tSpecialDeducationSum.idNumber != null and tSpecialDeducationSum.idNumber.trim() != ''">
                AND ID_NUMBER = #{tSpecialDeducationSum.idNumber}
            </if>
            <if test="tSpecialDeducationSum.createStart != null and tSpecialDeducationSum.createStart.trim() != ''">
                AND CREATE_START = #{tSpecialDeducationSum.createStart}
            </if>
            <if test="tSpecialDeducationSum.createEnd != null and tSpecialDeducationSum.createEnd.trim() != ''">
                AND CREATE_END = #{tSpecialDeducationSum.createEnd}
            </if>
            <if test="tSpecialDeducationSum.currentIncome != null">
                AND CURRENT_INCOME = #{tSpecialDeducationSum.currentIncome}
            </if>
            <if test="tSpecialDeducationSum.currentIncomeTaxFree != null">
                AND CURRENT_INCOME_TAX_FREE = #{tSpecialDeducationSum.currentIncomeTaxFree}
            </if>
            <if test="tSpecialDeducationSum.insurancePension != null">
                AND INSURANCE_PENSION = #{tSpecialDeducationSum.insurancePension}
            </if>
            <if test="tSpecialDeducationSum.insuranceMedical != null">
                AND INSURANCE_MEDICAL = #{tSpecialDeducationSum.insuranceMedical}
            </if>
            <if test="tSpecialDeducationSum.insuranceUnemployment != null">
                AND INSURANCE_UNEMPLOYMENT = #{tSpecialDeducationSum.insuranceUnemployment}
            </if>
            <if test="tSpecialDeducationSum.fund != null">
                AND FUND = #{tSpecialDeducationSum.fund}
            </if>
            <if test="tSpecialDeducationSum.sumChildEduMoney != null">
                AND SUM_CHILD_EDU_MONEY = #{tSpecialDeducationSum.sumChildEduMoney}
            </if>
            <if test="tSpecialDeducationSum.sumHousingLoanMoney != null">
                AND SUM_HOUSING_LOAN_MONEY = #{tSpecialDeducationSum.sumHousingLoanMoney}
            </if>
            <if test="tSpecialDeducationSum.sumHousingRentMoney != null">
                AND SUM_HOUSING_RENT_MONEY = #{tSpecialDeducationSum.sumHousingRentMoney}
            </if>
            <if test="tSpecialDeducationSum.sumSupportElderlyMoney != null">
                AND SUM_SUPPORT_ELDERLY_MONEY = #{tSpecialDeducationSum.sumSupportElderlyMoney}
            </if>
            <if test="tSpecialDeducationSum.sumContinuingEducationMoney != null">
                AND SUM_CONTINUING_EDUCATION_MONEY = #{tSpecialDeducationSum.sumContinuingEducationMoney}
            </if>
            <if test="tSpecialDeducationSum.sumBabyMoney != null">
                AND SUM_BABY_MONEY = #{tSpecialDeducationSum.sumBabyMoney}
            </if>
            <if test="tSpecialDeducationSum.enterpriseAnnuity != null">
                AND ENTERPRISE_ANNUITY = #{tSpecialDeducationSum.enterpriseAnnuity}
            </if>
            <if test="tSpecialDeducationSum.takingRisks != null">
                AND TAKING_RISKS = #{tSpecialDeducationSum.takingRisks}
            </if>
            <if test="tSpecialDeducationSum.taxDeferredInsurance != null">
                AND TAX_DEFERRED_INSURANCE = #{tSpecialDeducationSum.taxDeferredInsurance}
            </if>
            <if test="tSpecialDeducationSum.otherMoney != null">
                AND OTHER_MONEY = #{tSpecialDeducationSum.otherMoney}
            </if>
            <if test="tSpecialDeducationSum.donationAmount != null">
                AND DONATION_AMOUNT = #{tSpecialDeducationSum.donationAmount}
            </if>
            <if test="tSpecialDeducationSum.preTaxDeduction != null">
                AND PRE_TAX_DEDUCTION = #{tSpecialDeducationSum.preTaxDeduction}
            </if>
            <if test="tSpecialDeducationSum.taxSavings != null">
                AND TAX_SAVINGS = #{tSpecialDeducationSum.taxSavings}
            </if>
            <if test="tSpecialDeducationSum.costReduction != null">
                AND COST_REDUCTION = #{tSpecialDeducationSum.costReduction}
            </if>
            <if test="tSpecialDeducationSum.taxesWithheld != null">
                AND TAXES_WITHHELD = #{tSpecialDeducationSum.taxesWithheld}
            </if>
            <if test="tSpecialDeducationSum.remark != null and tSpecialDeducationSum.remark.trim() != ''">
                AND REMARK = #{tSpecialDeducationSum.remark}
            </if>
        </if>
    </sql>

    <!--tSpecialDeducationSum简单分页查询-->
    <select id="getTSpecialDeducationSumPage" resultMap="tSpecialDeducationSumMap">
        SELECT
            <include refid="Base_Column_List"/>
        FROM t_special_deducation_sum
        <where>
            1=1
            <include refid="tSpecialDeducationSum_where"/>
			ORDER BY CREATE_TIME
        </where>
    </select>

    <select id="getTSpecialDeducationSumList" resultMap="tSpecialDeducationSumMap">
        SELECT
            <include refid="Base_Column_List"/>
        FROM t_special_deducation_sum
        <where>
            1=1
            <include refid="tSpecialDeducationSum_where"/>
        </where>
        order by CREATE_TIME desc
    </select>

    <select id="getTSpecialDeducationSum" resultMap="tSpecialDeducationSumMap">
        SELECT
            <include refid="Base_Column_List"/>
        FROM t_special_deducation_sum
        <where>
            1=1
            <if test="yearMonth != null and yearMonth.trim() != ''">
                AND CREATE_MONTH = #{yearMonth}
            </if>
            <if test="idNumber != null and idNumber.trim() != ''">
                AND ID_NUMBER = #{idNumber}
            </if>
            <if test="invoiceTitle != null and invoiceTitle.trim() != ''">
                AND DECLARE_TITLE = #{invoiceTitle}
            </if>
        </where>
        limit 1
    </select>

    <!-- 工资查询所需的全部list，组装Map来使用 -->
    <select id="getListByIdCardList" resultMap="tSpecialDeducationSumMap">
        SELECT
            <include refid="Base_Column_List"/>
        FROM t_special_deducation_sum
        <where>
            1=1
            <if test="yearMonth != null and yearMonth.trim() != ''">
                AND CREATE_MONTH = #{yearMonth}
            </if>
            <if test="idCardList != null">
                and ID_NUMBER in
                <foreach item="item" index="index" collection="idCardList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <!--删除专项扣除-->
    <delete id="deleteByUnitAndMonth">
		DELETE FROM t_special_deducation_sum WHERE CREATE_MONTH = #{yearMonth} AND DECLARE_TITLE = #{invoiceTitle}
	</delete>


</mapper>
