<?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.chinaweal.aiccs.aicepsqy.mapper.datamove.SocialSecurityMapper">

    <!-- 动态插入社保信息 -->
    <insert id="insertSocialSecurityModel" parameterType="com.chinaweal.aiccs.aicepsqy.entity.datamove.SocialSecurityModel" useGeneratedKeys="false">
        <![CDATA[
        insert into
            TRSocialSecurityTemp_${entity.reportYear}(
            socialSecurityId,entId,regNo,socialInsuranceTpte,socialInsuranceTpteNo,totalWages,totalPayment,
            unpaidSocialins,totalWagesWhether,totalPaymentWhether,unpaidSocialinsWhether,
            dstate,createDate,updateDate,
            townNum,unemploymentNum,medicalNum,injuryNum,birthNum,entityNo,reportYear,
            TOTALWAGES_SO110,TOTALWAGES_SO210,TOTALWAGES_SO310,TOTALWAGES_SO510,
            TOTALPAYMENT_SO110,TOTALPAYMENT_SO210,TOTALPAYMENT_SO310,TOTALPAYMENT_SO410,TOTALPAYMENT_SO510,
            UNPAIDSOCIALINS_SO110,UNPAIDSOCIALINS_SO210,UNPAIDSOCIALINS_SO310,UNPAIDSOCIALINS_SO410,UNPAIDSOCIALINS_SO510
        )
        values
            (
                #{entity.socialSecurityId,jdbcType=VARCHAR},#{entity.entId,jdbcType=VARCHAR},#{entity.regNo,jdbcType=VARCHAR},
                #{entity.socialInsuranceTpte,jdbcType=VARCHAR},
                #{entity.socialInsuranceTpteNo,jdbcType=NUMERIC},
                #{entity.totalWages,jdbcType=NUMERIC},
                #{entity.totalPayment,jdbcType=NUMERIC},
                #{entity.unpaidSocialins,jdbcType=NUMERIC},
                #{entity.totalWagesWhether,jdbcType=CHAR},
                #{entity.totalPaymentWhether,jdbcType=CHAR},
                #{entity.unpaidSocialinsWhether,jdbcType=CHAR},
                #{entity.dstate,jdbcType=VARCHAR},
                #{entity.createDate,jdbcType=TIMESTAMP},
                #{entity.updateDate,jdbcType=TIMESTAMP},

                #{entity.townNum,jdbcType=NUMERIC},
                #{entity.unemploymentNum,jdbcType=NUMERIC},
                #{entity.medicalNum,jdbcType=NUMERIC},
                #{entity.injuryNum,jdbcType=NUMERIC},
                #{entity.birthNum,jdbcType=NUMERIC},
                #{entity.entityNo,jdbcType=VARCHAR},
                #{entity.reportYear,jdbcType=VARCHAR},
                #{entity.TOTALWAGES_SO110,jdbcType=NUMERIC},
                #{entity.TOTALWAGES_SO210,jdbcType=NUMERIC},
                #{entity.TOTALWAGES_SO310,jdbcType=NUMERIC},
                #{entity.TOTALWAGES_SO510,jdbcType=NUMERIC},

                #{entity.TOTALPAYMENT_SO110,jdbcType=NUMERIC},
                #{entity.TOTALPAYMENT_SO210,jdbcType=NUMERIC},
                #{entity.TOTALPAYMENT_SO310,jdbcType=NUMERIC},
                #{entity.TOTALPAYMENT_SO410,jdbcType=NUMERIC},
                #{entity.TOTALPAYMENT_SO510,jdbcType=NUMERIC},

                #{entity.UNPAIDSOCIALINS_SO110,jdbcType=NUMERIC},
                #{entity.UNPAIDSOCIALINS_SO210,jdbcType=NUMERIC},
                #{entity.UNPAIDSOCIALINS_SO310,jdbcType=NUMERIC},
                #{entity.UNPAIDSOCIALINS_SO410,jdbcType=NUMERIC},
                #{entity.UNPAIDSOCIALINS_SO510,jdbcType=NUMERIC}
            )
        ]]>
    </insert>


    <insert id="insertSocialSecurityModelzs" parameterType="com.chinaweal.aiccs.aicepsqy.entity.datamove.SocialSecurityModel" useGeneratedKeys="false">
        <![CDATA[
        insert into
            TRSocialSecurity_${entity.reportYear}(
            socialSecurityId,entId,regNo,socialInsuranceTpte,socialInsuranceTpteNo,totalWages,totalPayment,
            unpaidSocialins,totalWagesWhether,totalPaymentWhether,unpaidSocialinsWhether,
            dstate,createDate,updateDate,
            townNum,unemploymentNum,medicalNum,injuryNum,birthNum,entityNo,reportYear,
            TOTALWAGES_SO110,TOTALWAGES_SO210,TOTALWAGES_SO310,TOTALWAGES_SO510,
            TOTALPAYMENT_SO110,TOTALPAYMENT_SO210,TOTALPAYMENT_SO310,TOTALPAYMENT_SO410,TOTALPAYMENT_SO510,
            UNPAIDSOCIALINS_SO110,UNPAIDSOCIALINS_SO210,UNPAIDSOCIALINS_SO310,UNPAIDSOCIALINS_SO410,UNPAIDSOCIALINS_SO510
        )
        values
            (
                #{entity.socialSecurityId,jdbcType=VARCHAR},#{entity.entId,jdbcType=VARCHAR},#{entity.regNo,jdbcType=VARCHAR},
                #{entity.socialInsuranceTpte,jdbcType=VARCHAR},
                #{entity.socialInsuranceTpteNo,jdbcType=NUMERIC},
                #{entity.totalWages,jdbcType=NUMERIC},
                #{entity.totalPayment,jdbcType=NUMERIC},
                #{entity.unpaidSocialins,jdbcType=NUMERIC},
                #{entity.totalWagesWhether,jdbcType=CHAR},
                #{entity.totalPaymentWhether,jdbcType=CHAR},
                #{entity.unpaidSocialinsWhether,jdbcType=CHAR},
                #{entity.dstate,jdbcType=VARCHAR},
                #{entity.createDate,jdbcType=TIMESTAMP},
                #{entity.updateDate,jdbcType=TIMESTAMP},

                #{entity.townNum,jdbcType=NUMERIC},
                #{entity.unemploymentNum,jdbcType=NUMERIC},
                #{entity.medicalNum,jdbcType=NUMERIC},
                #{entity.injuryNum,jdbcType=NUMERIC},
                #{entity.birthNum,jdbcType=NUMERIC},
                #{entity.entityNo,jdbcType=VARCHAR},
                #{entity.reportYear,jdbcType=VARCHAR},
                #{entity.TOTALWAGES_SO110,jdbcType=NUMERIC},
                #{entity.TOTALWAGES_SO210,jdbcType=NUMERIC},
                #{entity.TOTALWAGES_SO310,jdbcType=NUMERIC},
                #{entity.TOTALWAGES_SO510,jdbcType=NUMERIC},

                #{entity.TOTALPAYMENT_SO110,jdbcType=NUMERIC},
                #{entity.TOTALPAYMENT_SO210,jdbcType=NUMERIC},
                #{entity.TOTALPAYMENT_SO310,jdbcType=NUMERIC},
                #{entity.TOTALPAYMENT_SO410,jdbcType=NUMERIC},
                #{entity.TOTALPAYMENT_SO510,jdbcType=NUMERIC},

                #{entity.UNPAIDSOCIALINS_SO110,jdbcType=NUMERIC},
                #{entity.UNPAIDSOCIALINS_SO210,jdbcType=NUMERIC},
                #{entity.UNPAIDSOCIALINS_SO310,jdbcType=NUMERIC},
                #{entity.UNPAIDSOCIALINS_SO410,jdbcType=NUMERIC},
                #{entity.UNPAIDSOCIALINS_SO510,jdbcType=NUMERIC}
            )
        ]]>
    </insert>

    <!-- 动态查询：根据EntityNo和ReportYear -->
    <select id="selectSocialSecurityByEntityNoAndReportYear"
            resultType="com.chinaweal.aiccs.aicepsqy.entity.datamove.SocialSecurityModel">
        <![CDATA[
        select
            socialSecurityId,entId,regNo,socialInsuranceTpte,socialInsuranceTpteNo,totalWages,totalPayment,
            unpaidSocialins,totalWagesWhether,totalPaymentWhether,unpaidSocialinsWhether,
            dstate,createDate,updateDate,
            townNum,unemploymentNum,medicalNum,injuryNum,birthNum,entityNo,reportYear,
            TOTALWAGES_SO110,TOTALWAGES_SO210,TOTALWAGES_SO310,TOTALWAGES_SO510,
            TOTALPAYMENT_SO110,TOTALPAYMENT_SO210,TOTALPAYMENT_SO310,TOTALPAYMENT_SO410,TOTALPAYMENT_SO510,
            UNPAIDSOCIALINS_SO110,UNPAIDSOCIALINS_SO210,UNPAIDSOCIALINS_SO310,UNPAIDSOCIALINS_SO410,UNPAIDSOCIALINS_SO510
        from TRSocialSecurity_${reportYear}
        where EntityNo = #{entityNo}
          and ReportYear = #{reportYear} and Dstate !='2'
        ]]>
    </select>

    <!-- 动态更新：根据EntityNo和ReportYear -->
    <update id="updateSocialSecurityByEntityNoAndReportYear"
            parameterType="com.chinaweal.aiccs.aicepsqy.entity.datamove.SocialSecurityModel">
        <![CDATA[
        update TRSocialSecurity_${reportYear}
        set
            socialSecurityId = #{entity.socialSecurityId,jdbcType=VARCHAR},
            entId = #{entity.entId,jdbcType=VARCHAR},
            regNo = #{entity.regNo,jdbcType=VARCHAR},
            socialInsuranceTpte = #{entity.socialInsuranceTpte,jdbcType=VARCHAR},
            socialInsuranceTpteNo = #{entity.socialInsuranceTpteNo,jdbcType=NUMERIC},
            totalWages = #{entity.totalWages,jdbcType=NUMERIC},
            totalPayment = #{entity.totalPayment,jdbcType=NUMERIC},
            unpaidSocialins = #{entity.unpaidSocialins,jdbcType=NUMERIC},
            totalWagesWhether = #{entity.totalWagesWhether,jdbcType=CHAR},
            totalPaymentWhether = #{entity.totalPaymentWhether,jdbcType=CHAR},
            unpaidSocialinsWhether = #{entity.unpaidSocialinsWhether,jdbcType=CHAR},
            dstate = #{entity.dstate,jdbcType=VARCHAR},
            createDate = #{entity.createDate,jdbcType=TIMESTAMP},
            townNum = #{entity.townNum,jdbcType=NUMERIC},
            unemploymentNum = #{entity.unemploymentNum,jdbcType=NUMERIC},
            medicalNum = #{entity.medicalNum,jdbcType=NUMERIC},
            injuryNum = #{entity.injuryNum,jdbcType=NUMERIC},
            birthNum = #{entity.birthNum,jdbcType=NUMERIC},
            reportYear = #{entity.reportYear,jdbcType=VARCHAR},
            TOTALWAGES_SO110 = #{entity.TOTALWAGES_SO110,jdbcType=NUMERIC},
            TOTALWAGES_SO210 = #{entity.TOTALWAGES_SO210,jdbcType=NUMERIC},
            TOTALWAGES_SO310 = #{entity.TOTALWAGES_SO310,jdbcType=NUMERIC},
            TOTALWAGES_SO510 = #{entity.TOTALWAGES_SO510,jdbcType=NUMERIC},
            TOTALPAYMENT_SO110 = #{entity.TOTALPAYMENT_SO110,jdbcType=NUMERIC},
            TOTALPAYMENT_SO210 = #{entity.TOTALPAYMENT_SO210,jdbcType=NUMERIC},
            TOTALPAYMENT_SO310 = #{entity.TOTALPAYMENT_SO310,jdbcType=NUMERIC},
            TOTALPAYMENT_SO410 = #{entity.TOTALPAYMENT_SO410,jdbcType=NUMERIC},
            TOTALPAYMENT_SO510 = #{entity.TOTALPAYMENT_SO510,jdbcType=NUMERIC},
            UNPAIDSOCIALINS_SO110 = #{entity.UNPAIDSOCIALINS_SO110,jdbcType=NUMERIC},
            UNPAIDSOCIALINS_SO210 = #{entity.UNPAIDSOCIALINS_SO210,jdbcType=NUMERIC},
            UNPAIDSOCIALINS_SO310 = #{entity.UNPAIDSOCIALINS_SO310,jdbcType=NUMERIC},
            UNPAIDSOCIALINS_SO410 = #{entity.UNPAIDSOCIALINS_SO410,jdbcType=NUMERIC},
            UNPAIDSOCIALINS_SO510 = #{entity.UNPAIDSOCIALINS_SO510,jdbcType=NUMERIC},
            updateDate = getdate()
        where
            EntityNo = #{entityNo}
          and ReportYear = #{reportYear} and Dstate !='2'
        ]]>
    </update>

    <delete id="deleteBySocialSecurityId">
    <![CDATA[
        delete from TRSocialSecurityTemp_${reportYear}
        where  EntID = #{entid}
        ]]>
    </delete>

    <delete id="deleteBySocialSecurityIdzs">
    <![CDATA[
        delete from TRSocialSecurity_${reportYear}
        where  EntID = #{entid}
        ]]>
    </delete>

</mapper>
