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

    <resultMap type="MdFaceColor" id="MdFaceColorResult">
        <result property="mdFaceColorId"    column="md_face_color_id"    />
        <result property="colorId"    column="color_id"    />
        <result property="coverageRate"    column="coverage_rate"    />
        <result property="sortOrder"    column="sort_order"    />
        <result property="itemId"    column="item_id"    />
        <result property="face"    column="face"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>
    <resultMap type="com.ximai.mes.md.vo.MdFaceColorVo" id="MdFaceColorVoResult">
        <result property="mdFaceColorId"    column="md_face_color_id"    />
        <result property="colorId"    column="color_id"    />
        <result property="coverageRate"    column="coverage_rate"    />
        <result property="sortOrder"    column="sort_order"    />
        <result property="itemId"    column="item_id"    />
        <result property="face"    column="face"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="colorCode"    column="color_code"    />
        <result property="colorName"    column="color_name"    />
    </resultMap>

    <sql id="selectMdFaceColorVo">
        select md_face_color_id, color_id, coverage_rate, sort_order, item_id, face, create_by, create_time, update_by, update_time from md_face_color
    </sql>

    <sql id="Base_Colum_List">
        fc.md_face_color_id, fc.color_id, fc.coverage_rate, fc.sort_order, fc.item_id, fc.face,
            fc.create_by, fc.create_time, fc.update_by, fc.update_time,c.color_code,c.color_name
    </sql>

    <select id="selectMdFaceColorList" parameterType="MdFaceColor" resultMap="MdFaceColorVoResult">
        select
        <include refid="Base_Colum_List"/>
            from md_face_color fc left join md_color c on fc.color_id = c.color_id
        <where>
            <if test="colorId != null "> and fc.color_id = #{colorId}</if>
            <if test="coverageRate != null "> and fc.coverage_rate = #{coverageRate}</if>
            <if test="sortOrder != null "> and fc.sort_order = #{sortOrder}</if>
            <if test="itemId != null "> and fc.item_id = #{itemId}</if>
            <if test="face != null  and face != ''"> and fc.face = #{face}</if>
        </where>
    </select>

    <select id="selectMdFaceColorByMdFaceColorId" parameterType="Long" resultMap="MdFaceColorVoResult">
        select
        <include refid="Base_Colum_List"/>
        from md_face_color fc left join md_color c on fc.color_id = c.color_id
        where md_face_color_id = #{mdFaceColorId}
    </select>

    <insert id="insertMdFaceColor" parameterType="MdFaceColor" useGeneratedKeys="true" keyProperty="mdFaceColorId">
        insert into md_face_color
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="colorId != null">color_id,</if>
            <if test="coverageRate != null">coverage_rate,</if>
            <if test="sortOrder != null">sort_order,</if>
            <if test="itemId != null">item_id,</if>
            <if test="face != null">face,</if>
            <if test="createBy != null">create_by,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="colorId != null">#{colorId},</if>
            <if test="coverageRate != null">#{coverageRate},</if>
            <if test="sortOrder != null">#{sortOrder},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="face != null">#{face},</if>
            <if test="createBy != null">#{createBy},</if>
            sysdate()
        </trim>
    </insert>

    <update id="updateMdFaceColor" parameterType="MdFaceColor">
        update md_face_color
        <trim prefix="SET" suffixOverrides=",">
            <if test="colorId != null">color_id = #{colorId},</if>
            <if test="coverageRate != null">coverage_rate = #{coverageRate},</if>
            <if test="sortOrder != null">sort_order = #{sortOrder},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="face != null">face = #{face},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = sysdate()
        </trim>
        where md_face_color_id = #{mdFaceColorId}
    </update>
    <update id="checkMdFaceColorUnique" parameterType="com.ximai.mes.md.domain.MdFaceColor">

    </update>

    <delete id="deleteMdFaceColorByMdFaceColorId" parameterType="Long">
        delete from md_face_color where md_face_color_id = #{mdFaceColorId}
    </delete>

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