<?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.trade.service.trade.purchaseorder.mapper.PurchaseOrderInvoiceCommodityMapper">

    <resultMap id="BaseResultMap" type="com.trade.service.trade.purchaseorder.domain.PurchaseOrderInvoiceCommodity">
        <id column="amount" property="amount"/>
        <id column="commodity_code" property="commodityCode"/>
        <id column="deleted" property="deleted"/>
        <id column="gmt_create" property="gmtCreate"/>
        <id column="gmt_modified" property="gmtModified"/>
        <id column="id" property="id"/>
        <id column="invoice_id" property="invoiceId"/>
        <id column="measurement_unit" property="measurementUnit"/>
        <id column="model" property="model"/>
        <id column="name" property="name"/>
        <id column="number" property="number"/>
        <id column="price_unit" property="priceUnit"/>
        <id column="tax_amount" property="taxAmount"/>
        <id column="tax_rate" property="taxRate"/>
        <id column="line_number" property="lineNumber"/>
    </resultMap>

    <resultMap id="dtoResultMap" type="com.trade.service.trade.purchaseorder.dto.InvoiceCommodityDto">
        <id column="amount" property="amount"/>
        <id column="measurement_unit" property="measurementUnit"/>
        <id column="model" property="model"/>
        <id column="name" property="name"/>
        <id column="number" property="number"/>
        <id column="price_unit" property="priceUnit"/>
        <id column="tax_amount" property="taxAmount"/>
        <id column="tax_rate" property="taxRate"/>
    </resultMap>
    <sql id="Base_Column_List">
        amount
        , commodity_code, deleted, gmt_create, gmt_modified, id, invoice_id, measurement_unit, model, name, number, price_unit, tax_amount, tax_rate, line_number
    </sql>
    <select id="selectByInvoiceId" resultMap="dtoResultMap">
        select t.amount,
               t.measurement_unit,
               t.model,
               t.name,
               t.number,
               t.tax_amount,
               t.tax_rate,
               p.price_unit
        from purchase_order_invoice_commodity t
                 left join purchase_order_commodity p on t.commodity_code = p.hs_code
        where t.invoice_id = #{invoiceId}
          and t.deleted = 0
    </select>
    <select id="selectInfoByInvoiceId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from purchase_order_invoice_commodity t where t.invoice_id = #{invoiceId}
        and t.deleted = 0
    </select>

</mapper>