<?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="pwc.taxtech.atms.vat.dao.OutputVATInvoiceMapper">
    <resultMap id="BaseResultMap" type="pwc.taxtech.atms.vat.entity.OutputVATInvoice">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <id column="InvoiceID" jdbcType="VARCHAR" property="invoiceID"/>
        <result column="InvoiceType" jdbcType="INTEGER" property="invoiceType"/>
        <result column="ClassCode" jdbcType="VARCHAR" property="classCode"/>
        <result column="InvoiceNumber" jdbcType="VARCHAR" property="invoiceNumber"/>
        <result column="BuyerName" jdbcType="VARCHAR" property="buyerName"/>
        <result column="BuyerTaxNumber" jdbcType="VARCHAR" property="buyerTaxNumber"/>
        <result column="BankAccount" jdbcType="VARCHAR" property="bankAccount"/>
        <result column="PhoneNum" jdbcType="VARCHAR" property="phoneNum"/>
        <result column="InvoiceDate" jdbcType="TIMESTAMP" property="invoiceDate"/>
        <result column="SeqNo" jdbcType="INTEGER" property="seqNo"/>
        <result column="PeriodID" jdbcType="INTEGER" property="periodID"/>
        <result column="Status" jdbcType="INTEGER" property="status"/>
        <result column="CreatorID" jdbcType="VARCHAR" property="creatorID"/>
        <result column="CreateTime" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="PartAccntedPeriod" jdbcType="INTEGER" property="partAccntedPeriod"/>
        <result column="AccntedPeriod" jdbcType="INTEGER" property="accntedPeriod"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        InvoiceID, InvoiceType, ClassCode, InvoiceNumber, BuyerName, BuyerTaxNumber, BankAccount,
        PhoneNum, InvoiceDate, SeqNo, PeriodID, `Status`, CreatorID, CreateTime, PartAccntedPeriod,
        AccntedPeriod
    </sql>
    <select id="selectByExample" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample"
            resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from OutputVATInvoice
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <include refid="Base_Column_List"/>
        from OutputVATInvoice
        where InvoiceID = #{invoiceID,jdbcType=VARCHAR}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from OutputVATInvoice
        where InvoiceID = #{invoiceID,jdbcType=VARCHAR}
    </delete>
    <delete id="deleteByExample" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from OutputVATInvoice
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoice">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        insert into OutputVATInvoice (InvoiceID, InvoiceType, ClassCode,
        InvoiceNumber, BuyerName, BuyerTaxNumber,
        BankAccount, PhoneNum, InvoiceDate,
        SeqNo, PeriodID, `Status`,
        CreatorID, CreateTime, PartAccntedPeriod,
        AccntedPeriod)
        values (#{invoiceID,jdbcType=VARCHAR}, #{invoiceType,jdbcType=INTEGER}, #{classCode,jdbcType=VARCHAR},
        #{invoiceNumber,jdbcType=VARCHAR}, #{buyerName,jdbcType=VARCHAR}, #{buyerTaxNumber,jdbcType=VARCHAR},
        #{bankAccount,jdbcType=VARCHAR}, #{phoneNum,jdbcType=VARCHAR}, #{invoiceDate,jdbcType=TIMESTAMP},
        #{seqNo,jdbcType=INTEGER}, #{periodID,jdbcType=INTEGER}, #{status,jdbcType=INTEGER},
        #{creatorID,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{partAccntedPeriod,jdbcType=INTEGER},
        #{accntedPeriod,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoice">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        insert into OutputVATInvoice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="invoiceID != null">
                InvoiceID,
            </if>
            <if test="invoiceType != null">
                InvoiceType,
            </if>
            <if test="classCode != null">
                ClassCode,
            </if>
            <if test="invoiceNumber != null">
                InvoiceNumber,
            </if>
            <if test="buyerName != null">
                BuyerName,
            </if>
            <if test="buyerTaxNumber != null">
                BuyerTaxNumber,
            </if>
            <if test="bankAccount != null">
                BankAccount,
            </if>
            <if test="phoneNum != null">
                PhoneNum,
            </if>
            <if test="invoiceDate != null">
                InvoiceDate,
            </if>
            <if test="seqNo != null">
                SeqNo,
            </if>
            <if test="periodID != null">
                PeriodID,
            </if>
            <if test="status != null">
                `Status`,
            </if>
            <if test="creatorID != null">
                CreatorID,
            </if>
            <if test="createTime != null">
                CreateTime,
            </if>
            <if test="partAccntedPeriod != null">
                PartAccntedPeriod,
            </if>
            <if test="accntedPeriod != null">
                AccntedPeriod,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="invoiceID != null">
                #{invoiceID,jdbcType=VARCHAR},
            </if>
            <if test="invoiceType != null">
                #{invoiceType,jdbcType=INTEGER},
            </if>
            <if test="classCode != null">
                #{classCode,jdbcType=VARCHAR},
            </if>
            <if test="invoiceNumber != null">
                #{invoiceNumber,jdbcType=VARCHAR},
            </if>
            <if test="buyerName != null">
                #{buyerName,jdbcType=VARCHAR},
            </if>
            <if test="buyerTaxNumber != null">
                #{buyerTaxNumber,jdbcType=VARCHAR},
            </if>
            <if test="bankAccount != null">
                #{bankAccount,jdbcType=VARCHAR},
            </if>
            <if test="phoneNum != null">
                #{phoneNum,jdbcType=VARCHAR},
            </if>
            <if test="invoiceDate != null">
                #{invoiceDate,jdbcType=TIMESTAMP},
            </if>
            <if test="seqNo != null">
                #{seqNo,jdbcType=INTEGER},
            </if>
            <if test="periodID != null">
                #{periodID,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="creatorID != null">
                #{creatorID,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="partAccntedPeriod != null">
                #{partAccntedPeriod,jdbcType=INTEGER},
            </if>
            <if test="accntedPeriod != null">
                #{accntedPeriod,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <select id="countByExample" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample"
            resultType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select count(*) from OutputVATInvoice
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update OutputVATInvoice
        <set>
            <if test="record.invoiceID != null">
                InvoiceID = #{record.invoiceID,jdbcType=VARCHAR},
            </if>
            <if test="record.invoiceType != null">
                InvoiceType = #{record.invoiceType,jdbcType=INTEGER},
            </if>
            <if test="record.classCode != null">
                ClassCode = #{record.classCode,jdbcType=VARCHAR},
            </if>
            <if test="record.invoiceNumber != null">
                InvoiceNumber = #{record.invoiceNumber,jdbcType=VARCHAR},
            </if>
            <if test="record.buyerName != null">
                BuyerName = #{record.buyerName,jdbcType=VARCHAR},
            </if>
            <if test="record.buyerTaxNumber != null">
                BuyerTaxNumber = #{record.buyerTaxNumber,jdbcType=VARCHAR},
            </if>
            <if test="record.bankAccount != null">
                BankAccount = #{record.bankAccount,jdbcType=VARCHAR},
            </if>
            <if test="record.phoneNum != null">
                PhoneNum = #{record.phoneNum,jdbcType=VARCHAR},
            </if>
            <if test="record.invoiceDate != null">
                InvoiceDate = #{record.invoiceDate,jdbcType=TIMESTAMP},
            </if>
            <if test="record.seqNo != null">
                SeqNo = #{record.seqNo,jdbcType=INTEGER},
            </if>
            <if test="record.periodID != null">
                PeriodID = #{record.periodID,jdbcType=INTEGER},
            </if>
            <if test="record.status != null">
                `Status` = #{record.status,jdbcType=INTEGER},
            </if>
            <if test="record.creatorID != null">
                CreatorID = #{record.creatorID,jdbcType=VARCHAR},
            </if>
            <if test="record.createTime != null">
                CreateTime = #{record.createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.partAccntedPeriod != null">
                PartAccntedPeriod = #{record.partAccntedPeriod,jdbcType=INTEGER},
            </if>
            <if test="record.accntedPeriod != null">
                AccntedPeriod = #{record.accntedPeriod,jdbcType=INTEGER},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update OutputVATInvoice
        set InvoiceID = #{record.invoiceID,jdbcType=VARCHAR},
        InvoiceType = #{record.invoiceType,jdbcType=INTEGER},
        ClassCode = #{record.classCode,jdbcType=VARCHAR},
        InvoiceNumber = #{record.invoiceNumber,jdbcType=VARCHAR},
        BuyerName = #{record.buyerName,jdbcType=VARCHAR},
        BuyerTaxNumber = #{record.buyerTaxNumber,jdbcType=VARCHAR},
        BankAccount = #{record.bankAccount,jdbcType=VARCHAR},
        PhoneNum = #{record.phoneNum,jdbcType=VARCHAR},
        InvoiceDate = #{record.invoiceDate,jdbcType=TIMESTAMP},
        SeqNo = #{record.seqNo,jdbcType=INTEGER},
        PeriodID = #{record.periodID,jdbcType=INTEGER},
        `Status` = #{record.status,jdbcType=INTEGER},
        CreatorID = #{record.creatorID,jdbcType=VARCHAR},
        CreateTime = #{record.createTime,jdbcType=TIMESTAMP},
        PartAccntedPeriod = #{record.partAccntedPeriod,jdbcType=INTEGER},
        AccntedPeriod = #{record.accntedPeriod,jdbcType=INTEGER}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoice">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update OutputVATInvoice
        <set>
            <if test="invoiceType != null">
                InvoiceType = #{invoiceType,jdbcType=INTEGER},
            </if>
            <if test="classCode != null">
                ClassCode = #{classCode,jdbcType=VARCHAR},
            </if>
            <if test="invoiceNumber != null">
                InvoiceNumber = #{invoiceNumber,jdbcType=VARCHAR},
            </if>
            <if test="buyerName != null">
                BuyerName = #{buyerName,jdbcType=VARCHAR},
            </if>
            <if test="buyerTaxNumber != null">
                BuyerTaxNumber = #{buyerTaxNumber,jdbcType=VARCHAR},
            </if>
            <if test="bankAccount != null">
                BankAccount = #{bankAccount,jdbcType=VARCHAR},
            </if>
            <if test="phoneNum != null">
                PhoneNum = #{phoneNum,jdbcType=VARCHAR},
            </if>
            <if test="invoiceDate != null">
                InvoiceDate = #{invoiceDate,jdbcType=TIMESTAMP},
            </if>
            <if test="seqNo != null">
                SeqNo = #{seqNo,jdbcType=INTEGER},
            </if>
            <if test="periodID != null">
                PeriodID = #{periodID,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                `Status` = #{status,jdbcType=INTEGER},
            </if>
            <if test="creatorID != null">
                CreatorID = #{creatorID,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                CreateTime = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="partAccntedPeriod != null">
                PartAccntedPeriod = #{partAccntedPeriod,jdbcType=INTEGER},
            </if>
            <if test="accntedPeriod != null">
                AccntedPeriod = #{accntedPeriod,jdbcType=INTEGER},
            </if>
        </set>
        where InvoiceID = #{invoiceID,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKey" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoice">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update OutputVATInvoice
        set InvoiceType = #{invoiceType,jdbcType=INTEGER},
        ClassCode = #{classCode,jdbcType=VARCHAR},
        InvoiceNumber = #{invoiceNumber,jdbcType=VARCHAR},
        BuyerName = #{buyerName,jdbcType=VARCHAR},
        BuyerTaxNumber = #{buyerTaxNumber,jdbcType=VARCHAR},
        BankAccount = #{bankAccount,jdbcType=VARCHAR},
        PhoneNum = #{phoneNum,jdbcType=VARCHAR},
        InvoiceDate = #{invoiceDate,jdbcType=TIMESTAMP},
        SeqNo = #{seqNo,jdbcType=INTEGER},
        PeriodID = #{periodID,jdbcType=INTEGER},
        `Status` = #{status,jdbcType=INTEGER},
        CreatorID = #{creatorID,jdbcType=VARCHAR},
        CreateTime = #{createTime,jdbcType=TIMESTAMP},
        PartAccntedPeriod = #{partAccntedPeriod,jdbcType=INTEGER},
        AccntedPeriod = #{accntedPeriod,jdbcType=INTEGER}
        where InvoiceID = #{invoiceID,jdbcType=VARCHAR}
    </update>
    <select id="selectByExampleWithRowbounds" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample"
            resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from OutputVATInvoice
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
    </select>
    <resultMap id="OutputVATInvoiceInfoDto" type="pwc.taxtech.atms.dto.vatdto.OutputVATInvoiceInfoDto">
        <id column="InvoiceID" jdbcType="VARCHAR" property="invoiceID"/>
        <result column="InvoiceType" jdbcType="INTEGER" property="invoiceType"/>
        <result column="InvoiceType" jdbcType="INTEGER" property="invoiceType"/>
        <result column="InvoiceTypeName" jdbcType="VARCHAR" property="invoiceTypeName"/>
        <result column="ClassCode" jdbcType="VARCHAR" property="classCode"/>
        <result column="InvoiceNumber" jdbcType="VARCHAR" property="invoiceNumber"/>
        <result column="BuyerName" jdbcType="VARCHAR" property="buyerName"/>
        <result column="BuyerTaxNumber" jdbcType="VARCHAR" property="buyerTaxNumber"/>
        <result column="BankAccount" jdbcType="VARCHAR" property="bankAccount"/>
        <result column="PhoneNum" jdbcType="VARCHAR" property="phoneNum"/>
        <result column="InvoiceDate" jdbcType="TIMESTAMP" property="invoiceDate"/>
        <result column="CodeVersion" jdbcType="VARCHAR" property="codeVersion"/>
        <result column="ProductName" jdbcType="VARCHAR" property="productName"/>
        <result column="DocumentNum" jdbcType="VARCHAR" property="documentNum"/>
        <result column="ProductStandard" jdbcType="VARCHAR" property="productStandard"/>
        <result column="Unit" jdbcType="VARCHAR" property="unit"/>
        <result column="Quantity" jdbcType="INTEGER" property="quantity"/>
        <result column="UnitPrice" jdbcType="DOUBLE" property="unitPrice"/>
        <result column="Amount" jdbcType="DECIMAL" property="amount"/>
        <result column="TaxRate" jdbcType="DECIMAL" property="taxRate"/>
        <result column="TaxAmount" jdbcType="DECIMAL" property="taxAmount"/>
        <result column="TaxClassCode" jdbcType="VARCHAR" property="taxClassCode"/>
        <result column="PeriodID" jdbcType="INTEGER" property="periodID"/>
        <result column="IsDuplicate" jdbcType="INTEGER" property="isDuplicate"/>
        <result column="AmountDifference" jdbcType="DECIMAL" property="amountDifference"/>
    </resultMap>
    <select id="selectOutputVATInvoiceInfoLeftJoinItem" parameterType="pwc.taxtech.atms.dto.vatdto.QueryOutputDto"
            resultMap="OutputVATInvoiceInfoDto">
        SELECT
        o.InvoiceID,
        o.InvoiceType,
        o.ClassCode,
        o.InvoiceNumber,
        o.BuyerName,
        o.BuyerTaxNumber,
        o.BankAccount,
        o.PhoneNum,
        o.InvoiceDate,
        IFNULL( oi.CodeVersion,'') AS CodeVersion,
        IFNULL(oi.ProductName,'') AS ProductName,
        IFNULL(oi.DocumentNum,'') AS DocumentNum,
        IFNULL(oi.ProductStandard,'') AS ProductStandard,
        IFNULL(oi.Unit,'') AS Unit,
        IFNULL(oi.Quantity,'') AS Quantity,
        IFNULL(oi.UnitPrice,'') AS UnitPrice,
        IFNULL(oi.Amount,'') AS Amount,
        IFNULL(oi.TaxAmount,'') AS TaxAmount,
        IFNULL(oi.TaxClassCode,'') AS TaxClassCode,
        o.PeriodID
        FROM OutputVATInvoice o
        LEFT JOIN OutputVATInvoiceItem oi
        ON o.InvoiceID = oi.InvoiceID
        WHERE 1=1
        <if test="queryDto.periodStart">
            AND o.PeriodID&gt;=#{queryDto.periodStart,jdbcType=VARCHAR}
        </if>
        <if test="queryDto.periodEnd">
            AND o.PeriodID&lt;=#{queryDto.periodEnd,jdbcType=VARCHAR}
        </if>
        <if test="queryDto.productName!=null and queryDto.productName!=''">
            AND ProductName LIKE concat('%',#{query.productName,jdbcType=VARCHAR,'%'})
        </if>
    </select>
    <resultMap id="outputVATInvoiceDto" type="pwc.taxtech.atms.dto.vatdto.OutputVATInvoiceDto">
        <id property="invoiceID" column="invoice_id"/>
        <association property="invoice" javaType="pwc.taxtech.atms.vat.entity.OutputVATInvoice">
            <id column="InvoiceID" property="invoiceID"/>
            <result column="InvoiceType" property="invoiceType"/>
            <result column="ClassCode" property="classCode"/>
            <result column="InvoiceNumber" property="invoiceNumber"/>
            <result column="BuyerName" property="buyerName"/>
            <result column="BuyerTaxNumber" property="buyerTaxNumber"/>
            <result column="BankAccount" property="bankAccount"/>
            <result column="PhoneNum" property="phoneNum"/>
            <result column="InvoiceDate" property="invoiceDate"/>
            <result column="SeqNo" property="seqNo"/>
            <result column="PeriodID" property="periodID"/>
            <result column="STATUS" property="status"/>
            <result column="CreatorID" property="creatorID"/>
            <result column="CreateTime" property="createTime"/>
            <result column="PartAccntedPeriod" property="partAccntedPeriod"/>
            <result column="AccntedPeriod" property="accntedPeriod"/>
        </association>
        <association property="invoiceItem" javaType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceItem">
            <id column="ItemID" property="itemID"/>
            <result column="InvoiceID" property="invoiceID"/>
            <result column="CodeVersion" property="codeVersion"/>
            <result column="ProductName" property="productName"/>
            <result column="DocumentNum" property="documentNum"/>
            <result column="ProductStandard" property="productStandard"/>
            <result column="Unit" property="unit"/>
            <result column="Quantity" property="quantity"/>
            <result column="UnitPrice" property="unitPrice"/>
            <result column="Amount" property="amount"/>
            <result column="TaxRate" property="taxRate"/>
            <result column="TaxAmount" property="taxAmount"/>
            <result column="SeqNo" property="seqNo"/>
            <result column="TaxClassCode" property="taxClassCode"/>
            <result column="CreatorID" property="creatorID"/>
            <result column="CreateTime" property="createTime"/>
            <result column="PeriodID" property="periodID"/>
        </association>
    </resultMap>
    <select id="getVatInvoiceWithItems" resultMap="outputVATInvoiceDto" parameterType="java.lang.String">
      SELECT
        invoice.InvoiceID,
        invoice.InvoiceType,
        invoice.ClassCode,
        invoice.InvoiceNumber,
        invoice.BuyerName,
        invoice.BuyerTaxNumber,
        invoice.BankAccount,
        invoice.PhoneNum,
        invoice.InvoiceDate,
        invoice.SeqNo,
        invoice.PeriodID,
        invoice.`STATUS`,
        invoice.CreatorID,
        invoice.CreateTime,
        invoice.PartAccntedPeriod,
        invoice.AccntedPeriod,
        invoiceItem.ItemID,
        invoiceItem.InvoiceID,
        invoiceItem.CodeVersion,
        invoiceItem.ProductName,
        invoiceItem.DocumentNum,
        invoiceItem.ProductStandard,
        invoiceItem.Unit,
        invoiceItem.Quantity,
        invoiceItem.UnitPrice,
        invoiceItem.Amount,
        invoiceItem.TaxRate,
        invoiceItem.TaxAmount,
        invoiceItem.SeqNo,
        invoiceItem.TaxClassCode,
        invoiceItem.CreatorID,
        invoiceItem.CreateTime,
        invoiceItem.PeriodID
      FROM ${dbName}.OutputVATInvoice invoice
        JOIN ${dbName}.OutputVATInvoiceItem invoiceItem
          ON invoice.InvoiceID = invoiceItem.InvoiceID AND invoice.PeriodID=invoiceItem.PeriodID
      ORDER BY invoice.PeriodID,invoice.ClassCode,invoice.InvoiceNumber,invoiceItem.SeqNo
  </select>
    <resultMap id="outputInvoiceDataSourceDto" type="pwc.taxtech.atms.dto.vatdto.OutputInvoiceDataSourceDto">
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <result column="amount" jdbcType="DECIMAL" property="amount"/>
        <result column="resultType" jdbcType="INTEGER" property="resultType"/>
        <result column="taxRate" jdbcType="DECIMAL" property="taxRate"/>
        <result column="buyerName" jdbcType="VARCHAR" property="buyerName"/>
        <result column="invoiceCode" jdbcType="VARCHAR" property="invoiceCode"/>
        <result column="invoiceNumber" jdbcType="VARCHAR" property="invoiceNumber"/>
        <result column="invoiceDate" jdbcType="TIMESTAMP" property="invoiceDate"/>
        <result column="invoiceType" jdbcType="INTEGER" property="invoiceType"/>
        <result column="period" jdbcType="INTEGER" property="period"/>
    </resultMap>
    <select id="selectOutputInvoiceAndItem" resultMap="outputInvoiceDataSourceDto">
      SELECT
          ovii.InvoiceID   AS id,
          ovii.Amount      AS amount,
          1                AS resultType,
          ovii.TaxAmount   AS taxAmount,
          ovii.TaxRate     AS taxRate,
          oi.BuyerName     AS buyerName,
          oi.ClassCode     AS invoiceCode,
          oi.InvoiceNumber AS invoiceNumber,
          oi.InvoiceDate   AS invoiceDate,
          oi.InvoiceType   AS invoiceType,
          oi.PeriodID      AS period
        FROM OutputVATInvoiceItem ovii
          JOIN OutputVATInvoice oi
            ON ovii.InvoiceID = oi.InvoiceID
    </select>
</mapper>