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

    <!-- 动态插入（沿用原SQL的id="insertToZS"） -->
    <insert id="insertToAssetModel" parameterType="com.chinaweal.aiccs.aicepsqy.entity.datamove.AssetModel" useGeneratedKeys="false">
        <![CDATA[
        insert into
            TREntAssetsTemp_${entity.reportYear}(
            AssetID,EntityNo,EntID,AssetsTotalAmount,AssetsIsShow,LiabilitiesAmount,LiabilitiesIsShow,
            SalesAmount,SalesIsShow,ProfitsAmount,ProfitsIsShow,NetProfitAmount,NetProfitIsShow,TaxAmount,TaxIsShow,
            EquityAmount,EquityIsShow,BusinessAmount,BusinessIsShow,coinid, ReportYear
        )
        values
            (
                #{entity.assetId,jdbcType=CHAR},#{entity.entityNo,jdbcType=CHAR},#{entity.entId,jdbcType=CHAR},
                #{entity.assetsTotalAmount,jdbcType=NUMERIC},
                #{entity.assetsIsShow,jdbcType=CHAR},
                #{entity.liabilitiesAmount,jdbcType=NUMERIC},
                #{entity.liabilitiesIsShow,jdbcType=CHAR},
                #{entity.salesAmount,jdbcType=NUMERIC},
                #{entity.salesIsShow,jdbcType=CHAR},
                #{entity.profitsAmount,jdbcType=NUMERIC},
                #{entity.profitsIsShow,jdbcType=CHAR},
                #{entity.netProfitAmount,jdbcType=NUMERIC},
                #{entity.netProfitIsShow,jdbcType=CHAR},
                #{entity.taxAmount,jdbcType=NUMERIC},
                #{entity.taxIsShow,jdbcType=CHAR},
                #{entity.equityAmount,jdbcType=NUMERIC},
                #{entity.equityIsShow,jdbcType=CHAR},
                #{entity.businessAmount,jdbcType=NUMERIC},
                #{entity.businessIsShow,jdbcType=CHAR},#{entity.coinid,jdbcType=VARCHAR},
                #{entity.reportYear}
            )
        ]]>
    </insert>

    <insert id="insertToAssetModelzs" parameterType="com.chinaweal.aiccs.aicepsqy.entity.datamove.AssetModel" useGeneratedKeys="false">
        <![CDATA[
        insert into
            TREntAssets_${entity.reportYear}(
            AssetID,EntityNo,EntID,AssetsTotalAmount,AssetsIsShow,LiabilitiesAmount,LiabilitiesIsShow,
            SalesAmount,SalesIsShow,ProfitsAmount,ProfitsIsShow,NetProfitAmount,NetProfitIsShow,TaxAmount,TaxIsShow,
            EquityAmount,EquityIsShow,BusinessAmount,BusinessIsShow,coinid, ReportYear
        )
        values
            (
                #{entity.assetId,jdbcType=CHAR},#{entity.entityNo,jdbcType=CHAR},#{entity.entId,jdbcType=CHAR},
                #{entity.assetsTotalAmount,jdbcType=NUMERIC},
                #{entity.assetsIsShow,jdbcType=CHAR},
                #{entity.liabilitiesAmount,jdbcType=NUMERIC},
                #{entity.liabilitiesIsShow,jdbcType=CHAR},
                #{entity.salesAmount,jdbcType=NUMERIC},
                #{entity.salesIsShow,jdbcType=CHAR},
                #{entity.profitsAmount,jdbcType=NUMERIC},
                #{entity.profitsIsShow,jdbcType=CHAR},
                #{entity.netProfitAmount,jdbcType=NUMERIC},
                #{entity.netProfitIsShow,jdbcType=CHAR},
                #{entity.taxAmount,jdbcType=NUMERIC},
                #{entity.taxIsShow,jdbcType=CHAR},
                #{entity.equityAmount,jdbcType=NUMERIC},
                #{entity.equityIsShow,jdbcType=CHAR},
                #{entity.businessAmount,jdbcType=NUMERIC},
                #{entity.businessIsShow,jdbcType=CHAR},#{entity.coinid,jdbcType=VARCHAR},
                #{entity.reportYear}
            )
        ]]>
    </insert>

    <!-- 动态查询：根据EntityNo和ReportYear -->
    <select id="selectAssetModelByEntityNoAndReportYear"
            resultType="com.chinaweal.aiccs.aicepsqy.entity.datamove.AssetModel">
        <![CDATA[
        select
            AssetID,EntityNo,EntID,AssetsTotalAmount,AssetsIsShow,LiabilitiesAmount,LiabilitiesIsShow,
            SalesAmount,SalesIsShow,ProfitsAmount,ProfitsIsShow,NetProfitAmount,NetProfitIsShow,TaxAmount,TaxIsShow,
            EquityAmount,EquityIsShow,BusinessAmount,BusinessIsShow,coinid, ReportYear
        from TREntAssets_${reportYear}
        where EntityNo = #{entityNo}
          and ReportYear = #{reportYear} and Dstate !='2'
        ]]>
    </select>

    <!-- 动态更新：根据EntityNo和ReportYear -->
    <update id="updateAssetModelByEntityNoAndReportYear"
            parameterType="com.chinaweal.aiccs.aicepsqy.entity.datamove.AssetModel">
        <![CDATA[
        update TREntAssets_${reportYear}
        set
            AssetID = #{entity.assetId,jdbcType=CHAR},
            EntID = #{entity.entId,jdbcType=CHAR},
            AssetsTotalAmount = #{entity.assetsTotalAmount,jdbcType=NUMERIC},
            AssetsIsShow = #{entity.assetsIsShow,jdbcType=CHAR},
            LiabilitiesAmount = #{entity.liabilitiesAmount,jdbcType=NUMERIC},
            LiabilitiesIsShow = #{entity.liabilitiesIsShow,jdbcType=CHAR},
            SalesAmount = #{entity.salesAmount,jdbcType=NUMERIC},
            SalesIsShow = #{entity.salesIsShow,jdbcType=CHAR},
            ProfitsAmount = #{entity.profitsAmount,jdbcType=NUMERIC},
            ProfitsIsShow = #{entity.profitsIsShow,jdbcType=CHAR},
            NetProfitAmount = #{entity.netProfitAmount,jdbcType=NUMERIC},
            NetProfitIsShow = #{entity.netProfitIsShow,jdbcType=CHAR},
            TaxAmount = #{entity.taxAmount,jdbcType=NUMERIC},
            TaxIsShow = #{entity.taxIsShow,jdbcType=CHAR},
            EquityAmount = #{entity.equityAmount,jdbcType=NUMERIC},
            EquityIsShow = #{entity.equityIsShow,jdbcType=CHAR},
            BusinessAmount = #{entity.businessAmount,jdbcType=NUMERIC},
            BusinessIsShow = #{entity.businessIsShow,jdbcType=CHAR},
            coinid = #{entity.coinid,jdbcType=VARCHAR},
            ReportYear = #{entity.reportYear},
            updateDate = getdate()
        where
            EntityNo = #{entityNo}
          and ReportYear = #{reportYear} and Dstate !='2'
        ]]>
    </update>

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

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