<?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.ximai.mes.md.mapper.MdProductSpecMapper">

    <resultMap type="MdProductSpec" id="MdItemSpecResult">
        <result property="itemSpecId"    column="item_spec_id"    />
        <result property="itemId"    column="item_id"    />
        <result property="spec"    column="spec"    />
    </resultMap>

    <sql id="selectMdItemSpecVo">
        select item_spec_id, item_id, spec from md_product_spec
    </sql>

    <select id="selectMdItemSpecList" parameterType="MdProductSpec" resultMap="MdItemSpecResult">
        <include refid="selectMdItemSpecVo"/>
        <where>
            <if test="itemId != null "> and item_id = #{itemId}</if>
            <if test="spec != null  and spec != ''"> and spec = #{spec}</if>
        </where>
    </select>

    <select id="selectMdItemSpecByItemSpecId" parameterType="Long" resultMap="MdItemSpecResult">
        <include refid="selectMdItemSpecVo"/>
        where item_spec_id = #{itemSpecId}
    </select>

    <insert id="insertMdItemSpec" parameterType="MdProductSpec">
        insert into md_product_spec
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="itemSpecId != null">item_spec_id,</if>
            <if test="itemId != null">item_id,</if>
            <if test="spec != null">spec,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="itemSpecId != null">#{itemSpecId},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="spec != null">#{spec},</if>
        </trim>
    </insert>

    <update id="updateMdItemSpec" parameterType="MdProductSpec">
        update md_product_spec
        <trim prefix="SET" suffixOverrides=",">
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="spec != null">spec = #{spec},</if>
        </trim>
        where item_spec_id = #{itemSpecId}
    </update>

    <delete id="deleteMdItemSpecByItemSpecId" parameterType="Long">
        delete from md_product_spec where item_spec_id = #{itemSpecId}
    </delete>

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