<?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.salescontract.mapper.SalesCommodityMapper">

    <resultMap id="BaseResultMap" type="com.trade.service.trade.salescontract.domain.SalesCommodity">
        <id column="id" property="id"/>
        <id column="sales_contract_id" property="salesContractId"/>
        <id column="hs_code" property="hsCode"/>
        <id column="name" property="name"/>
        <id column="declaration_name" property="declarationName"/>
        <id column="pack_spec" property="packSpec"/>
        <id column="measurement_unit" property="measurementUnit"/>
        <id column="export_tax_rebate_rate" property="exportTaxRebateRate"/>
        <id column="added_tax_rate" property="addedTaxRate"/>
        <id column="number" property="number"/>
        <id column="price_unit" property="priceUnit"/>
        <id column="currency" property="currency"/>
        <id column="amount" property="amount"/>
        <id column="deleted" property="deleted"/>
        <id column="entity_no" property="entityNo"/>
        <id column="entity_name" property="entityName"/>
        <id column="model" property="model"/>
        <id column="gmt_create" property="gmtCreate"/>
        <id column="gmt_modified" property="gmtModified"/>
    </resultMap>
    <sql id="Base_Column_List">
        id
        , sales_contract_id, entity_no, entity_name, hs_code, name, declaration_name, pack_spec, measurement_unit, export_tax_rebate_rate, added_tax_rate, number, price_unit, currency, amount, model, deleted, gmt_create, gmt_modified
    </sql>
    <select id="selectBySalesContractId" resultMap="BaseResultMap">
        select T1.id,
               T1.sales_contract_id,
               T1.entity_no,
               T1.hs_code,
               T1.name,
               T1.declaration_name,
               T1.pack_spec,
               T1.measurement_unit,
               T1.export_tax_rebate_rate,
               T1.added_tax_rate,
               T1.number,
               T1.price_unit,
               T1.currency,
               T1.amount,
               T1.model,
               T1.deleted,
               T1.gmt_create,
               T1.gmt_modified,
               T2.entity_name
        from sales_commodity T1
                 left join vendor_entity T2 on T1.entity_no = T2.entity_no
        where T1.sales_contract_id = #{salesContractId}
          and T1.deleted = 0
    </select>
    <select id="selectByDeclarationName"
            resultType="com.trade.service.trade.salescontract.domain.SalesCommodity">
        select
        <include refid="Base_Column_List"/>
        from sales_commodity where declaration_name = #{declarationName} limit 1
    </select>
</mapper>
