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

    <resultMap type="OmsProductAttrValue" id="OmsProductAttrValueResult">
        <result property="id"    column="id"    />
        <result property="productId"    column="product_id"    />
        <result property="sku"    column="sku"    />
        <result property="price"    column="price"    />
        <result property="image"    column="image"    />
        <result property="cost"    column="cost"    />
        <result property="barCode"    column="bar_code"    />
        <result property="otPrice"    column="ot_price"    />
        <result property="activityPrice"    column="activity_price"    />
        <result property="innerPrice"    column="inner_price"    />
        <result property="marketPrice"    column="market_price"    />
        <result property="clearingPrice"    column="clearing_price"    />
        <result property="weight"    column="weight"    />
        <result property="volume"    column="volume"    />
    </resultMap>

    <sql id="selectOmsProductAttrValueVo">
        select id, product_id, sku, price, image, cost, bar_code, ot_price, weight, volume, activity_price, inner_price, market_price,
            clearing_price from oms_product_attr_value
    </sql>

    <select id="selectOmsProductAttrValueList" parameterType="OmsProductAttrValue" resultMap="OmsProductAttrValueResult">
        <include refid="selectOmsProductAttrValueVo"/>
        <where>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="sku != null  and sku != ''"> and sku = #{sku}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="cost != null "> and cost = #{cost}</if>
            <if test="barCode != null  and barCode != ''"> and bar_code = #{barCode}</if>
            <if test="otPrice != null "> and ot_price = #{otPrice}</if>
            <if test="activityPrice != null "> and activity_price = #{activityPrice}</if>
            <if test="innerPrice != null "> and inner_price = #{innerPrice}</if>
            <if test="clearingPrice != null "> and clearing_price = #{clearingPrice}</if>
            <if test="marketPrice != null "> and market_price = #{marketPrice}</if>
            <if test="weight != null "> and weight = #{weight}</if>
            <if test="volume != null "> and volume = #{volume}</if>
        </where>
    </select>

    <select id="selectOmsProductAttrValueById" parameterType="Long" resultMap="OmsProductAttrValueResult">
        <include refid="selectOmsProductAttrValueVo"/>
        where id = #{id}
    </select>

    <insert id="insertOmsProductAttrValue" parameterType="OmsProductAttrValue" useGeneratedKeys="true" keyProperty="id">
        insert into oms_product_attr_value
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productId != null">product_id,</if>
            <if test="sku != null and sku != ''">sku,</if>
            <if test="price != null">price,</if>
            <if test="image != null">image,</if>
            <if test="cost != null">cost,</if>
            <if test="barCode != null">bar_code,</if>
            <if test="otPrice != null">ot_price,</if>
            <if test="activityPrice != null ">activity_price,</if>
            <if test="innerPrice != null ">inner_price,</if>
            <if test="clearingPrice != null ">clearing_price,</if>
            <if test="marketPrice != null ">market_price,</if>
            <if test="weight != null">weight,</if>
            <if test="volume != null">volume,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productId != null">#{productId},</if>
            <if test="sku != null and sku != ''">#{sku},</if>
            <if test="price != null">#{price},</if>
            <if test="image != null">#{image},</if>
            <if test="cost != null">#{cost},</if>
            <if test="barCode != null">#{barCode},</if>
            <if test="otPrice != null">#{otPrice},</if>
            <if test="activityPrice != null ">#{activityPrice},</if>
            <if test="innerPrice != null ">#{innerPrice},</if>
            <if test="clearingPrice != null ">#{clearingPrice},</if>
            <if test="marketPrice != null ">#{marketPrice},</if>
            <if test="weight != null">#{weight},</if>
            <if test="volume != null">#{volume},</if>
         </trim>
    </insert>

    <update id="updateOmsProductAttrValue" parameterType="OmsProductAttrValue">
        update oms_product_attr_value
        <trim prefix="SET" suffixOverrides=",">
            <if test="productId != null">product_id = #{productId},</if>
            <if test="sku != null and sku != ''">sku = #{sku},</if>
            <if test="price != null">price = #{price},</if>
            <if test="image != null">image = #{image},</if>
            <if test="cost != null">cost = #{cost},</if>
            <if test="barCode != null">bar_code = #{barCode},</if>
            <if test="otPrice != null">ot_price = #{otPrice},</if>
            <if test="activityPrice != null ">activity_price = #{activityPrice},</if>
            <if test="innerPrice != null ">inner_price = #{innerPrice},</if>
            <if test="clearingPrice != null ">clearing_price = #{clearingPrice},</if>
            <if test="marketPrice != null ">market_price = #{marketPrice},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="volume != null">volume = #{volume},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOmsProductAttrValueById" parameterType="Long">
        delete from oms_product_attr_value where id = #{id}
    </delete>

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

</mapper>
