<?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.TREntBaseInfoTempMapper">

    <!-- 动态表名插入：根据实体reportYear字段值，自动匹配TREntBaseInfoTemp_2023/TREntBaseInfoTemp_2024 -->
    <insert id="insertTREntBaseInfo" parameterType="com.chinaweal.aiccs.aicepsqy.entity.datamove.TREntBaseInfoTemp">
        <![CDATA[
        insert into
            TREntBaseInfoTemp_${entity.reportYear}(
            EntID,EntityNo,RegistNo,EntName,IssueDeptID,EmpNumber,EntPhone,EntAddress,EntZip,EntEmail,EntState,
            IsWeb,IsInveInfo,RegistDate,EntType,ReportYear,IsTransferStock,EmpNumberIsShow,onAiccips,Relations,RelationsIsShow,
            issync,orgId,entityType,subEntityType,mainBusiact,womEmpNum,holdingsMsg,womEmpNumWhether,holdingsMsgWhether,
            isSocialSecurity,belongEnterprise,isGuarantee,ip,isPc,imstAndMac,createDate,updateDate
        )
        values
            (
                #{entity.entId}, #{entity.entityNo},#{entity.registNo},#{entity.entName,jdbcType=VARCHAR},
                #{entity.issueDeptID,jdbcType=VARCHAR},#{entity.empNumber,jdbcType=NUMERIC},
                #{entity.entPhone,jdbcType=VARCHAR},#{entity.entAddress,jdbcType=VARCHAR},
                #{entity.entZip,jdbcType=VARCHAR},#{entity.entEmail,jdbcType=VARCHAR},#{entity.entState,jdbcType=CHAR},
                #{entity.isWeb,jdbcType=CHAR},#{entity.isInveInfo,jdbcType=CHAR},#{entity.registDate,jdbcType=TIMESTAMP},
                #{entity.entType,jdbcType=CHAR},#{entity.reportYear,jdbcType=VARCHAR},#{entity.isTransferStock,jdbcType=CHAR},
                #{entity.empNumberIsShow,jdbcType=CHAR},#{entity.onAiccips,jdbcType=CHAR},#{entity.relations,jdbcType=VARCHAR},
                #{entity.relationsIsShow,jdbcType=CHAR},'wA',#{entity.orgId,jdbcType=VARCHAR},#{entity.entityType,jdbcType=VARCHAR},
                #{entity.subEntityType,jdbcType=VARCHAR},#{entity.mainBusiact,jdbcType=VARCHAR},#{entity.womEmpNum,jdbcType=INTEGER},
                #{entity.holdingsMsg,jdbcType=CHAR},#{entity.womEmpNumWhether,jdbcType=CHAR},#{entity.holdingsMsgWhether,jdbcType=CHAR},
                #{entity.isSocialSecurity,jdbcType=CHAR},#{entity.belongEnterprise,jdbcType=VARCHAR},#{entity.isGuarantee,jdbcType=VARCHAR},
                #{entity.ip,jdbcType=VARCHAR},#{entity.isPc,jdbcType=CHAR},#{entity.imstAndMac,jdbcType=VARCHAR},getdate(),getdate()
            )
        ]]>
    </insert>

    <insert id="insertTREntBaseInfozs" parameterType="com.chinaweal.aiccs.aicepsqy.entity.datamove.TREntBaseInfoTemp">
        <![CDATA[
        insert into
            TREntBaseInfo_${entity.reportYear}(
            EntID,EntityNo,RegistNo,EntName,IssueDeptID,EmpNumber,EntPhone,EntAddress,EntZip,EntEmail,EntState,
            IsWeb,IsInveInfo,RegistDate,EntType,ReportYear,IsTransferStock,EmpNumberIsShow,onAiccips,Relations,RelationsIsShow,
            issync,orgId,entityType,subEntityType,mainBusiact,womEmpNum,holdingsMsg,womEmpNumWhether,holdingsMsgWhether,
            isSocialSecurity,belongEnterprise,isGuarantee,ip,isPc,imstAndMac,createDate,updateDate
        )
        values
            (
                #{entity.entId}, #{entity.entityNo},#{entity.registNo},#{entity.entName,jdbcType=VARCHAR},
                #{entity.issueDeptID,jdbcType=VARCHAR},#{entity.empNumber,jdbcType=NUMERIC},
                #{entity.entPhone,jdbcType=VARCHAR},#{entity.entAddress,jdbcType=VARCHAR},
                #{entity.entZip,jdbcType=VARCHAR},#{entity.entEmail,jdbcType=VARCHAR},#{entity.entState,jdbcType=CHAR},
                #{entity.isWeb,jdbcType=CHAR},#{entity.isInveInfo,jdbcType=CHAR},#{entity.registDate,jdbcType=TIMESTAMP},
                #{entity.entType,jdbcType=CHAR},#{entity.reportYear,jdbcType=VARCHAR},#{entity.isTransferStock,jdbcType=CHAR},
                #{entity.empNumberIsShow,jdbcType=CHAR},#{entity.onAiccips,jdbcType=CHAR},#{entity.relations,jdbcType=VARCHAR},
                #{entity.relationsIsShow,jdbcType=CHAR},'wA',#{entity.orgId,jdbcType=VARCHAR},#{entity.entityType,jdbcType=VARCHAR},
                #{entity.subEntityType,jdbcType=VARCHAR},#{entity.mainBusiact,jdbcType=VARCHAR},#{entity.womEmpNum,jdbcType=INTEGER},
                #{entity.holdingsMsg,jdbcType=CHAR},#{entity.womEmpNumWhether,jdbcType=CHAR},#{entity.holdingsMsgWhether,jdbcType=CHAR},
                #{entity.isSocialSecurity,jdbcType=CHAR},#{entity.belongEnterprise,jdbcType=VARCHAR},#{entity.isGuarantee,jdbcType=VARCHAR},
                #{entity.ip,jdbcType=VARCHAR},#{entity.isPc,jdbcType=CHAR},#{entity.imstAndMac,jdbcType=VARCHAR},getdate(),getdate()
            )
        ]]>
    </insert>

    <!-- 动态表名更新：根据实体reportYear和EntID更新对应表数据 -->
    <update id="updateDynamicTable" parameterType="com.chinaweal.aiccs.aicepsqy.entity.datamove.TREntBaseInfoTemp">
        <![CDATA[
        update TREntBaseInfo_${entity.reportYear}
        set
            EntityNo = #{entity.entityNo},
            RegistNo = #{entity.registNo},
            EntName = #{entity.entName,jdbcType=VARCHAR},
            IssueDeptID = #{entity.issueDeptID,jdbcType=VARCHAR},
            EmpNumber = #{entity.empNumber,jdbcType=NUMERIC},
            EntPhone = #{entity.entPhone,jdbcType=VARCHAR},
            EntAddress = #{entity.entAddress,jdbcType=VARCHAR},
            EntZip = #{entity.entZip,jdbcType=VARCHAR},
            EntEmail = #{entity.entEmail,jdbcType=VARCHAR},
            EntState = #{entity.entState,jdbcType=CHAR},
            IsWeb = #{entity.isWeb,jdbcType=CHAR},
            IsInveInfo = #{entity.isInveInfo,jdbcType=CHAR},
            RegistDate = #{entity.registDate,jdbcType=TIMESTAMP},
            EntType = #{entity.entType,jdbcType=CHAR},
            ReportYear = #{entity.reportYear,jdbcType=VARCHAR},
            IsTransferStock = #{entity.isTransferStock,jdbcType=CHAR},
            EmpNumberIsShow = #{entity.empNumberIsShow,jdbcType=CHAR},
            onAiccips = #{entity.onAiccips,jdbcType=CHAR},
            Relations = #{entity.relations,jdbcType=VARCHAR},
            RelationsIsShow = #{entity.relationsIsShow,jdbcType=CHAR},
            issync = 'wA',
            orgId = #{entity.orgId,jdbcType=VARCHAR},
            entityType = #{entity.entityType,jdbcType=VARCHAR},
            subEntityType = #{entity.subEntityType,jdbcType=VARCHAR},
            mainBusiact = #{entity.mainBusiact,jdbcType=VARCHAR},
            womEmpNum = #{entity.womEmpNum,jdbcType=INTEGER},
            holdingsMsg = #{entity.holdingsMsg,jdbcType=CHAR},
            womEmpNumWhether = #{entity.womEmpNumWhether,jdbcType=CHAR},
            holdingsMsgWhether = #{entity.holdingsMsgWhether,jdbcType=CHAR},
            isSocialSecurity = #{entity.isSocialSecurity,jdbcType=CHAR},
            belongEnterprise = #{entity.belongEnterprise,jdbcType=VARCHAR},
            isGuarantee = #{entity.isGuarantee,jdbcType=VARCHAR},
            ip = #{entity.ip,jdbcType=VARCHAR},
            isPc = #{entity.isPc,jdbcType=CHAR},
            imstAndMac = #{entity.imstAndMac,jdbcType=VARCHAR},
            updateDate = getdate()
        where
            ReportYear = #{entity.reportYear}  and EntityNo = #{entity.entityNo} and Dstate !='2'
        ]]>
    </update>

    <!-- 动态表名查询：根据EntityNo和ReportYear查询记录 -->
    <select id="selectByEntityNoAndReportYear"
            resultType="com.chinaweal.aiccs.aicepsqy.entity.datamove.TREntBaseInfoTemp">
        <![CDATA[
        select
            EntID,EntityNo,RegistNo,EntName,IssueDeptID,EmpNumber,EntPhone,EntAddress,EntZip,EntEmail,EntState,
            IsWeb,IsInveInfo,RegistDate,EntType,ReportYear,IsTransferStock,EmpNumberIsShow,onAiccips,Relations,RelationsIsShow,
            issync,orgId,entityType,subEntityType,mainBusiact,womEmpNum,holdingsMsg,womEmpNumWhether,holdingsMsgWhether,
            isSocialSecurity,belongEnterprise,isGuarantee,ip,isPc,imstAndMac
        from TREntBaseInfo_${reportYear}
        where EntityNo = #{entityNo} and Dstate !='2'
        ]]>
    </select>

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

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