<?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.OmsSupplierGoodsMapper">

    <resultMap type="OmsSupplierGoods" id="OmsSupplierGoodsResult">
        <result property="id"    column="id"    />
        <result property="supplierId"    column="supplier_id"    />
        <result property="supplierCode"    column="supplier_code"    />
        <result property="supplierSkucode"    column="supplier_skucode"    />
        <result property="supplierSpucode"    column="supplier_spucode"    />
        <result property="taxunitPrice"    column="taxunit_price"    />
        <result property="unitPrice"    column="unit_price"    />
        <result property="taxRate"    column="tax_rate"    />
        <result property="packagingFlag"    column="packaging_flag"    />
        <result property="shippingFlag"    column="shipping_flag"    />
        <result property="remark"    column="remark"    />
        <result property="image"    column="image"    />
        <result property="spuName"    column="spu_name"    />
        <result property="spuCode"    column="spu_code"    />
        <result property="skuId"    column="sku_id"    />
        <result property="skuCode"    column="sku_code"    />
        <result property="skuName"    column="sku_name"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectOmsSupplierGoodsVo">
        select osg.id, osg.supplier_id, os.name, osg.supplier_code, osg.supplier_skucode, osg.supplier_spucode, osg.taxunit_price, osg.unit_price, osg.tax_rate, osg.packaging_flag, osg.shipping_flag, osg.remark, osg.image, osg.spu_name, osg.spu_code, osg.sku_id, osg.sku_code, osg.sku_name, osg.create_user_id, osg.update_user_id, osg.create_time, osg.update_time from oms_supplier_goods osg
        left join oms_supplier os on osg.supplier_code = os.code
    </sql>

    <select id="selectOmsSupplierListVO" parameterType="OmsSupplierGoods" resultMap="OmsSupplierGoodsResult">
        <include refid="selectOmsSupplierGoodsVo"/>
        <where>
            <if test="supplierId != null "> and supplier_id = #{supplierId}</if>
            <if test="supplierCode != null  and supplierCode != ''"> and supplier_code = #{supplierCode}</if>
            <if test="supplierSkucode != null  and supplierSkucode != ''"> and supplier_skucode = #{supplierSkucode}</if>
            <if test="supplierSpucode != null  and supplierSpucode != ''"> and supplier_spucode = #{supplierSpucode}</if>
            <if test="taxunitPrice != null "> and taxunit_price = #{taxunitPrice}</if>
            <if test="unitPrice != null "> and unit_price = #{unitPrice}</if>
            <if test="taxRate != null "> and tax_rate = #{taxRate}</if>
            <if test="packagingFlag != null "> and packaging_flag = #{packagingFlag}</if>
            <if test="shippingFlag != null "> and shipping_flag = #{shippingFlag}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="spuName != null  and spuName != ''"> and spu_name like concat('%', #{spuName}, '%')</if>
            <if test="spuCode != null  and spuCode != ''"> and spu_code = #{spuCode}</if>
            <if test="skuId != null "> and sku_id = #{skuId}</if>
            <if test="skuCode != null  and skuCode != ''"> and sku_code = #{skuCode}</if>
            <if test="skuName != null  and skuName != ''"> and sku_name like concat('%', #{skuName}, '%')</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="updateUserId != null "> and update_user_id = #{updateUserId}</if>
            <if test="name !=null ">and name like concat('%', #{name}, '%'</if>
        </where>
    </select>

    <select id="selectOmsSupplierGoodsById" parameterType="Long" resultMap="OmsSupplierGoodsResult">
        <include refid="selectOmsSupplierGoodsVo"/>
        where osg.id = #{id}
    </select>

    <insert id="insertOmsSupplierGoods" parameterType="OmsSupplierGoods" useGeneratedKeys="true" keyProperty="id">
        insert into oms_supplier_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="supplierId != null">supplier_id,</if>
            <if test="supplierCode != null">supplier_code,</if>
            <if test="supplierSkucode != null">supplier_skucode,</if>
            <if test="supplierSpucode != null">supplier_spucode,</if>
            <if test="taxunitPrice != null">taxunit_price,</if>
            <if test="unitPrice != null">unit_price,</if>
            <if test="taxRate != null">tax_rate,</if>
            <if test="packagingFlag != null">packaging_flag,</if>
            <if test="shippingFlag != null">shipping_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="image != null and image != ''">image,</if>
            <if test="spuName != null">spu_name,</if>
            <if test="spuCode != null">spu_code,</if>
            <if test="skuId != null">sku_id,</if>
            <if test="skuCode != null">sku_code,</if>
            <if test="skuName != null">sku_name,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="updateUserId != null">update_user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="supplierId != null">#{supplierId},</if>
            <if test="supplierCode != null">#{supplierCode},</if>
            <if test="supplierSkucode != null">#{supplierSkucode},</if>
            <if test="supplierSpucode != null">#{supplierSpucode},</if>
            <if test="taxunitPrice != null">#{taxunitPrice},</if>
            <if test="unitPrice != null">#{unitPrice},</if>
            <if test="taxRate != null">#{taxRate},</if>
            <if test="packagingFlag != null">#{packagingFlag},</if>
            <if test="shippingFlag != null">#{shippingFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="image != null and image != ''">#{image},</if>
            <if test="spuName != null">#{spuName},</if>
            <if test="spuCode != null">#{spuCode},</if>
            <if test="skuId != null">#{skuId},</if>
            <if test="skuCode != null">#{skuCode},</if>
            <if test="skuName != null">#{skuName},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateOmsSupplierGoods" parameterType="OmsSupplierGoods">
        update oms_supplier_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="supplierId != null">supplier_id = #{supplierId},</if>
            <if test="supplierCode != null">supplier_code = #{supplierCode},</if>
            <if test="supplierSkucode != null">supplier_skucode = #{supplierSkucode},</if>
            <if test="supplierSpucode != null">supplier_spucode = #{supplierSpucode},</if>
            <if test="taxunitPrice != null">taxunit_price = #{taxunitPrice},</if>
            <if test="unitPrice != null">unit_price = #{unitPrice},</if>
            <if test="taxRate != null">tax_rate = #{taxRate},</if>
            <if test="packagingFlag != null">packaging_flag = #{packagingFlag},</if>
            <if test="shippingFlag != null">shipping_flag = #{shippingFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="image != null and image != ''">image = #{image},</if>
            <if test="spuName != null">spu_name = #{spuName},</if>
            <if test="spuCode != null">spu_code = #{spuCode},</if>
            <if test="skuId != null">sku_id = #{skuId},</if>
            <if test="skuCode != null">sku_code = #{skuCode},</if>
            <if test="skuName != null">sku_name = #{skuName},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOmsSupplierGoodsById" parameterType="Long">
        delete from oms_supplier_goods where id = #{id}
    </delete>

    <delete id="deleteOmsSupplierGoodsByIds" parameterType="String">
        delete from oms_supplier_goods where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
