<?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.ChannelPriceMapper">
    <resultMap  id="BaseResultMap" type="ChannelPrice" >
        <result    column="channel_price_id"    property="channelPriceId" />
        <result    column="channel_type"    property="channelType" />
        <result    column="channel_id"    property="channelId" />
        <result    column="product_id"    property="productId" />
        <result    column="color_id"    property="colorId" />
        <result    column="channel_price_offer"    property="channelPriceOffer" />
        <result    column="channel_original_price"    property="channelOriginalPrice" />
        <result    column="channel_rebate_amount"    property="channelRebateAmount" />
        <result    column="channel_price_status"    property="channelPriceStatus" />
        <result    column="channel_price_create_time"    property="channelPriceCreateTime" />
        <result    column="channel_price_update_time"    property="channelPriceUpdateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.channel_price_id,
        t.channel_type,
        t.channel_id,
        t.product_id,
        t.color_id,
        t.channel_price_offer,
        t.channel_original_price,
        t.channel_rebate_amount,
        t.channel_price_status,
        t.channel_price_create_time,
        t.channel_price_update_time
    </sql>
    <select id="getChannelPriceList" resultMap="BaseResultMap" parameterType="ChannelPrice" >
        select
        <include refid="Base_List" />
        from tb_iamberry_channel_price t
        <where>
            <if test="channelPriceId != null ">
                AND t.channel_price_id = #{channelPriceId}
            </if >
            <if test="channelType != null ">
                AND t.channel_type = #{channelType}
            </if >
            <if test="channelId != null ">
                AND t.channel_id = #{channelId}
            </if >
            <if test="productId != null ">
                AND t.product_id = #{productId}
            </if >
            <if test="colorId != null ">
                AND t.color_id = #{colorId}
            </if >
            <if test="channelPriceStatus != null ">
                AND t.channel_price_status = #{channelPriceStatus}
            </if >
        </where>
    </select>

    <select id="getChannelProductList" resultMap="BaseResultMap" parameterType="ChannelPrice" >
        select
        <include refid="Base_List" />
        from tb_iamberry_channel_price t
        <where>
            <if test="channelPriceId != null ">
                AND t.channel_price_id = #{channelPriceId}
            </if >
            <if test="channelType != null ">
                AND t.channel_type = #{channelType}
            </if >
            <if test="channelId != null ">
                AND t.channel_id = #{channelId}
            </if >
            <if test="productId != null ">
                AND t.product_id = #{productId}
            </if >
            <if test="colorId != null ">
                AND t.color_id = #{colorId}
            </if >
            <if test="channelPriceStatus != null ">
                AND t.channel_price_status = #{channelPriceStatus}
            </if >
        </where>
        GROUP BY t.product_id
        ORDER BY t.channel_price_id
    </select>

    <select id="getChannelPriceById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_channel_price t
        where t.channel_price_id= #{channelPriceId}
    </select>
    <insert id="save" parameterType="ChannelPrice" >
        insert into
        tb_iamberry_channel_price
        (
        channel_type,
        channel_id,
        product_id,
        color_id,
        channel_price_offer,
        channel_original_price,
        channel_rebate_amount,
        channel_price_status
        )
        values
        (
        #{channelType},
        #{channelId},
        #{productId},
        #{colorId},
        #{channelPriceOffer},
        #{channelOriginalPrice},
        #{channelRebateAmount},
        #{channelPriceStatus}
        )
    </insert>
    <update id="update" parameterType="ChannelPrice" >
        update
        tb_iamberry_channel_price
        <set >
            <if test="channelType != null ">
                channel_type = #{channelType},
            </if >
            <if test="channelId != null ">
                channel_id = #{channelId},
            </if >
            <if test="productId != null ">
                product_id = #{productId},
            </if >
            <if test="colorId != null ">
                color_id = #{colorId},
            </if >
            <if test="channelPriceOffer != null ">
                channel_price_offer = #{channelPriceOffer},
            </if >
            <if test="channelOriginalPrice != null ">
                channel_original_price = #{channelOriginalPrice},
            </if >
            <if test="channelRebateAmount != null ">
                channel_rebate_amount = #{channelRebateAmount},
            </if >
            <if test="channelPriceStatus != null ">
                channel_price_status = #{channelPriceStatus},
            </if >
        </set >
        where channel_price_id= #{channelPriceId}
    </update>
    <delete id="delete" parameterType="Integer" >
        delete FROM
        tb_iamberry_channel_price
        where channel_price_id=#{channelPriceId}
    </delete>
    <insert id="saveList" parameterType="java.util.List" >
        insert into
        tb_iamberry_channel_price
        (
        channel_type,
        channel_id,
        product_id,
        color_id,
        channel_price_offer,
        channel_original_price,
        channel_rebate_amount,
        channel_price_status
        )
        values
        <foreach collection="list" item="node" index="index" separator="," open="" close="">
            (
            #{node.channelType},
            #{node.channelId},
            #{node.productId},
            #{node.colorId},
            #{node.channelPriceOffer},
            #{node.channelOriginalPrice},
            #{node.channelRebateAmount},
            #{node.channelPriceStatus}
            )
        </foreach >
    </insert>
    <delete id="deleteList" parameterType="String" >
        delete FROM
        tb_iamberry_channel_price
        where channel_price_id  in
        <foreach collection="ids" item="item" index="index" separator="," open="(" close=")">
            #{item}
        </foreach >
    </delete>
</mapper>