<?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.fs.oms.mapper.OmsSupplierProductMapper">

    <resultMap type="OmsSupplierProductVO" id="OmsSupplierProductResult">
        <result property="image"    column="image"    />
        <result property="spuName"    column="spu_name"    />
        <result property="spuCode"    column="spu_code"    />
        <result property="skuCode"    column="sku_code"    />
        <result property="skuName"    column="sku_name"    />
        <result property="cateName"    column="cate_name"    />
    </resultMap>

    <sql id="selectOmsSupplierProductVo">
        select pc.cate_name,p.product_name as spu_name,p.image,p.bar_code as spu_code
             ,av.sku as sku_name,av.bar_code as sku_code from oms_product p left join oms_product_attr_value av on p.product_id = av.product_id left join oms_product_category
            pc on p.cate_id=pc.cate_id
    </sql>

    <select id="selectOmsSupplierProduct" parameterType="OmsSupplierGoods" resultMap="OmsSupplierProductResult">
        <include refid="selectOmsSupplierProductVo"/>
        <where>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="spuName != null  and spuName != ''"> and p.product_name like concat('%', #{spuName}, '%')</if>
            <if test="spuCode != null  and spuCode != ''"> and p.bar_code = #{spuCode}</if>
            <if test="skuCode != null  and skuCode != ''"> and av.bar_code = #{skuCode}</if>
        </where>
    </select>

    <resultMap type="OmsPurchaseProductVO" id="OmsPurchaseProductResult">
        <result property="image"    column="image"    />
        <result property="supplierName"    column="supplier_name"    />
        <result property="taxunitPrice"    column="taxunit_price"    />
        <result property="taxRate"    column="tax_rate"    />
        <result property="spuName"    column="spu_name"    />
        <result property="spuCode"    column="spu_code"    />
        <result property="skuCode"    column="sku_code"    />
        <result property="skuName"    column="sku_name"    />
        <result property="supplierSpucode" column="supplier_spucode"/>
        <result property="supplierCode"    column="supplier_code"    />
    </resultMap>

    <sql id="selectOmsPurchaseProductVo">
        select og.image,og.spu_name,og.spu_code,os.name as supplier_name,og.supplier_spucode,og.supplier_skucode,og.taxunit_price,og.tax_rate
             ,og.sku_name,og.sku_code, og.supplier_code from oms_supplier_goods og left join oms_supplier os on og.supplier_id=os.id
    </sql>

    <select id="selectPurchaseProduct" parameterType="OmsPurchaseProductVO" resultMap="OmsPurchaseProductResult">
        <include refid="selectOmsPurchaseProductVo"/>
        <where>
            <if test="supplierCode != null  and supplierCode != ''"> and og.supplier_code = #{supplierCode}</if>
            <if test="spuName != null  and spuName != ''"> and og.spu_name like concat('%', #{spuName}, '%')</if>
            <if test="supplierName != null  and supplierName != ''"> and os.name like concat('%', #{supplierName}, '%')</if>
            <if test="spuCode != null  and spuCode != ''"> and og.spu_code = #{spuCode}</if>
            <if test="skuCode != null  and skuCode != ''"> and og.sku_code = #{skuCode}</if>
        </where>
    </select>

</mapper>
