<?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.iamberry.wechat.service.mapper.IndexProductMapper">
    <resultMap  id="BaseResultMap" type="IndexProduct" >
        <result    column="inde_prod_id"    property="indeProdId" />
        <result    column="product_id"    property="productId" />
        <result    column="color_id"    property="colorId" />
        <result    column="inde_prod_sort"    property="indeProdSort" />
        <result    column="inde_prod_status"    property="indeProdStatus" />
        <result    column="inde_prod_type"    property="indeProdType" />
        <result    column="inde_prod_img"    property="indeProdImg" />
        <result    column="inde_prod_img_size"    property="indeProdImgSize" />
    </resultMap>
    <sql    id="Base_List" >
        t.inde_prod_id,
        t.product_id,
        t.color_id,
        t.inde_prod_sort,
        t.inde_prod_status,
        t.inde_prod_type,
        t.inde_prod_img,
        t.inde_prod_img_size
    </sql>
    <select id="getIndexProductList" resultMap="BaseResultMap" parameterType="IndexProduct" >
        select
        <include refid="Base_List" />,
        pc.color_product_id,
        pc.color_name,
        pc.color_discount,
        pc.color_price,
        pi.product_name,
        pi.product_color_des
        from tb_iamberry_index_product t
        LEFT JOIN tb_iamberry_product_color pc ON  t.color_id = pc.color_id
        LEFT JOIN tb_iamberry_product_info pi ON pi.product_id = pc.color_product_id
        <where>
            <if test="indeProdId != null ">
                AND t.inde_prod_id = #{indeProdId}
            </if >
            <if test="productId != null ">
                AND t.product_id = #{productId}
            </if >
            <if test="colorId != null ">
                AND t.color_id = #{colorId}
            </if >
            <if test="indeProdSort != null ">
                AND t.inde_prod_sort = #{indeProdSort}
            </if >
            <if test="indeProdStatus != null ">
                AND t.inde_prod_status = #{indeProdStatus}
            </if >
            <if test="indeProdType != null ">
                AND t.inde_prod_type = #{indeProdType}
            </if >
        </where>
        ORDER BY t.inde_prod_sort
    </select>
    <select id="getIndexProductById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_index_product t
        where t.inde_prod_id= #{indeProdId}
    </select>
    <insert id="save" parameterType="IndexProduct" >
        insert into
        tb_iamberry_index_product
        (
        product_id,
        color_id,
        inde_prod_sort,
        inde_prod_status
        )
        values
        (
        #{productId},
        #{colorId},
        #{indeProdSort},
        #{indeProdStatus}
        )
    </insert>
    <update id="update" parameterType="IndexProduct" >
        update
        tb_iamberry_index_product
        <set >
            <if test="productId != null ">
                product_id = #{productId},
            </if >
            <if test="colorId != null ">
                color_id = #{colorId},
            </if >
            <if test="indeProdSort != null ">
                inde_prod_sort = #{indeProdSort},
            </if >
            <if test="indeProdStatus != null ">
                inde_prod_status = #{indeProdStatus}
            </if >
        </set >
        where inde_prod_id= #{indeProdId}
    </update>
    <delete id="delete" parameterType="Integer" >
        delete FROM
            tb_iamberry_index_product
        where inde_prod_id=#{indeProdId}
    </delete>
</mapper>