<?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.purchasecontract.mapper.PurchaseCommodityMapper">

    <resultMap type="com.trade.service.trade.purchasecontract.dto.PurchaseCommodityDto" id="PurchaseCommodityMap">
        <result property="id" column="id"/>
        <result property="purchaseContractId" column="purchase_contract_id"/>
        <result property="salesContractId" column="sales_contract_id"/>
        <result property="salesCommodityId" column="sales_commodity_id"/>
        <result property="hsCode" column="hs_code"/>
        <result property="name" column="name"/>
        <result property="declarationName" column="declaration_name"/>
        <result property="packSpec" column="pack_spec"/>
        <result property="measurementUnit" column="measurement_unit"/>
        <result property="exportTaxRebateRate" column="export_tax_rebate_rate"/>
        <result property="addedTaxRate" column="added_tax_rate"/>
        <result property="model" column="model"/>
        <result property="number" column="number"/>
        <result property="priceUnit" column="price_unit"/>
        <result property="currency" column="currency"/>
        <result property="amount" column="amount"/>
        <result property="totalAmount" column="total_amount"/>
        <result property="gmtCreate" column="gmt_create"/>
        <result property="gmtModified" column="gmt_modified"/>
    </resultMap>

    <sql id="Base_Column_List">
        `id`, `purchase_contract_id`, `sales_contract_id`, `sales_commodity_id`, `number`, `price_unit`, `currency`,
        `amount`, `total_amount`,`deleted`, `gmt_create`, `gmt_modified`
    </sql>

    <select id="getPurchaseCommodityByContractId"
            parameterType="java.lang.Long" resultMap="PurchaseCommodityMap">
        SELECT pc.`id`, pc.`purchase_contract_id`, pc.`sales_contract_id`, pc.`sales_commodity_id`, pc.`number`,
               pc.`price_unit`, pc.`currency`,pc.`amount`, pc.`total_amount`, pc.`gmt_create`, pc.`gmt_modified`,
               sc.`hs_code`,sc.`name`,sc.`pack_spec`,sc.`measurement_unit`,sc.`added_tax_rate`, sc.`model`,
               sc.`export_tax_rebate_rate`, sc.`declaration_name`
        FROM `purchase_commodity` pc
        LEFT JOIN `sales_commodity` sc ON sc.`id` = pc.`sales_commodity_id`
        WHERE pc.`purchase_contract_id` = #{contractId} AND pc.`deleted` = 0
    </select>

</mapper>

