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

    <resultMap type="MdColor" id="MdColorResult">
        <result property="colorId"    column="color_id"    />
        <result property="colorCode"    column="color_code"    />
        <result property="colorName"    column="color_name"    />
    </resultMap>

    <sql id="selectMdColorVo">
        select color_id, color_code, color_name from md_color
    </sql>

    <select id="selectMdColorList" parameterType="MdColor" resultMap="MdColorResult">
        <include refid="selectMdColorVo"/>
        <where>
            <if test="colorCode != null  and colorCode != ''"> and color_code = #{colorCode}</if>
            <if test="colorName != null  and colorName != ''"> and color_name like concat('%', #{colorName}, '%')</if>
        </where>
    </select>

    <select id="selectMdColorByColorId" parameterType="Long" resultMap="MdColorResult">
        <include refid="selectMdColorVo"/>
        where color_id = #{colorId}
    </select>

    <insert id="insertMdColor" parameterType="MdColor" keyProperty="colorId">
        insert into md_color
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="colorCode != null">color_code,</if>
            <if test="colorName != null">color_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">

            <if test="colorCode != null">#{colorCode},</if>
            <if test="colorName != null">#{colorName},</if>
         </trim>
    </insert>

    <update id="updateMdColor" parameterType="MdColor">
        update md_color
        <trim prefix="SET" suffixOverrides=",">
            <if test="colorCode != null">color_code = #{colorCode},</if>
            <if test="colorName != null">color_name = #{colorName},</if>
        </trim>
        where color_id = #{colorId}
    </update>

    <delete id="deleteMdColorByColorId" parameterType="Long">
        delete from md_color where color_id = #{colorId}
    </delete>

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