<?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.OmsProductAttrMapper">
    
    <resultMap type="OmsProductAttr" id="OmsProductAttrResult">
        <result property="id"    column="id"    />
        <result property="productId"    column="product_id"    />
        <result property="attrName"    column="attr_name"    />
        <result property="attrValues"    column="attr_values"    />
    </resultMap>

    <sql id="selectOmsProductAttrVo">
        select id, product_id, attr_name, attr_values from oms_product_attr
    </sql>

    <select id="selectOmsProductAttrList" parameterType="OmsProductAttr" resultMap="OmsProductAttrResult">
        <include refid="selectOmsProductAttrVo"/>
        <where>  
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="attrName != null  and attrName != ''"> and attr_name like concat('%', #{attrName}, '%')</if>
            <if test="attrValues != null  and attrValues != ''"> and attr_values = #{attrValues}</if>
        </where>
    </select>
    
    <select id="selectOmsProductAttrById" parameterType="Long" resultMap="OmsProductAttrResult">
        <include refid="selectOmsProductAttrVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertOmsProductAttr" parameterType="OmsProductAttr" useGeneratedKeys="true" keyProperty="id">
        insert into oms_product_attr
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productId != null">product_id,</if>
            <if test="attrName != null and attrName != ''">attr_name,</if>
            <if test="attrValues != null and attrValues != ''">attr_values,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productId != null">#{productId},</if>
            <if test="attrName != null and attrName != ''">#{attrName},</if>
            <if test="attrValues != null and attrValues != ''">#{attrValues},</if>
         </trim>
    </insert>

    <update id="updateOmsProductAttr" parameterType="OmsProductAttr">
        update oms_product_attr
        <trim prefix="SET" suffixOverrides=",">
            <if test="productId != null">product_id = #{productId},</if>
            <if test="attrName != null and attrName != ''">attr_name = #{attrName},</if>
            <if test="attrValues != null and attrValues != ''">attr_values = #{attrValues},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOmsProductAttrById" parameterType="Long">
        delete from oms_product_attr where id = #{id}
    </delete>

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