<?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.xingxi.master.product.mapper.ProdAttrPriceMapper">
    <resultMap type="ProdAttrPrice" id="ProdAttrPriceResult">
        <result property="prodAttrPriceId"    column="prodAttrPriceId"    />
        <result property="prodId"    column="prodId"    />
        <result property="prodAttrId"    column="prodAttrId"    />
        <result property="buyerId"    column="buyerId"    />
        <result property="buyerRoleKey"    column="buyerRoleKey"    />
        <result property="sellerId"    column="sellerId"    />
        <result property="sellerRoleKey"    column="sellerRoleKey"    />
        <result property="price"    column="price"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectProdAttrPrice">
        select prodAttrPriceId, prodId, prodAttrId, buyerId, buyerRoleKey, sellerId, sellerRoleKey, price, delFlag, createUser, createTime, updateUser, updateTime from m_prod_attr_price
    </sql>

    <select id="selectProdAttrPriceList" parameterType="ProdAttrPrice" resultMap="ProdAttrPriceResult">
        <include refid="selectProdAttrPrice"/>
        <where>  
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="prodAttrId != null "> and prodAttrId = #{prodAttrId}</if>
            <if test="buyerId != null "> and buyerId = #{buyerId}</if>
            <if test="buyerRoleKey != null  and buyerRoleKey != ''"> and buyerRoleKey = #{buyerRoleKey}</if>
            <if test="sellerId != null "> and sellerId = #{sellerId}</if>
            <if test="sellerRoleKey != null  and sellerRoleKey != ''"> and sellerRoleKey = #{sellerRoleKey}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectProdAttrPriceByProdAttrPriceId" parameterType="Long" resultMap="ProdAttrPriceResult">
        <include refid="selectProdAttrPrice"/>
        where prodAttrPriceId = #{prodAttrPriceId}
    </select>
        
    <insert id="insertProdAttrPrice" parameterType="ProdAttrPrice" useGeneratedKeys="true" keyProperty="prodAttrPriceId">
        insert into m_prod_attr_price
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prodId != null">prodId,</if>
            <if test="prodAttrId != null">prodAttrId,</if>
            <if test="buyerId != null">buyerId,</if>
            <if test="buyerRoleKey != null">buyerRoleKey,</if>
            <if test="sellerId != null">sellerId,</if>
            <if test="sellerRoleKey != null">sellerRoleKey,</if>
            <if test="price != null">price,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="prodId != null">#{prodId},</if>
            <if test="prodAttrId != null">#{prodAttrId},</if>
            <if test="buyerId != null">#{buyerId},</if>
            <if test="buyerRoleKey != null">#{buyerRoleKey},</if>
            <if test="sellerId != null">#{sellerId},</if>
            <if test="sellerRoleKey != null">#{sellerRoleKey},</if>
            <if test="price != null">#{price},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertProdAttrPrice">
        insert into m_prod_attr_price( prodId, prodAttrId, buyerId, buyerRoleKey, sellerId, sellerRoleKey, price, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.prodId}, #{item.prodAttrId}, #{item.buyerId}, #{item.buyerRoleKey}, #{item.sellerId}, #{item.sellerRoleKey}, #{item.price}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateProdAttrPrice" parameterType="ProdAttrPrice">
        update m_prod_attr_price
        <trim prefix="SET" suffixOverrides=",">
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="prodAttrId != null">prodAttrId = #{prodAttrId},</if>
            <if test="buyerId != null">buyerId = #{buyerId},</if>
            <if test="buyerRoleKey != null">buyerRoleKey = #{buyerRoleKey},</if>
            <if test="sellerId != null">sellerId = #{sellerId},</if>
            <if test="sellerRoleKey != null">sellerRoleKey = #{sellerRoleKey},</if>
            <if test="price != null">price = #{price},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where prodAttrPriceId = #{prodAttrPriceId}
    </update>

    <delete id="deleteProdAttrPriceByProdAttrPriceId" parameterType="Long">
        delete from m_prod_attr_price where prodAttrPriceId = #{prodAttrPriceId}
    </delete>

    <delete id="deleteProdAttrPriceByProdAttrPriceIds" parameterType="String">
        delete from m_prod_attr_price where prodAttrPriceId in 
        <foreach item="prodAttrPriceId" collection="array" open="(" separator="," close=")">
            #{prodAttrPriceId}
        </foreach>
    </delete>

    <update id="logicDeleteProdAttrPriceByProdAttrPriceId" parameterType="Long">
        update m_prod_attr_price
            set delFlag = '1'
        where prodAttrPriceId = #{prodAttrPriceId}
    </update>

    <update id="logicDeleteProdAttrPriceByProdAttrPriceIds" parameterType="String">
        update m_prod_attr_price
        set delFlag = '1'
        where prodAttrPriceId in
        <foreach item="prodAttrPriceId" collection="array" open="(" separator="," close=")">
            #{prodAttrPriceId}
        </foreach>
    </update>

    <update id="logicDeleteProdAttrPriceByCondition" parameterType="ProdAttrPrice">
        update m_prod_attr_price
        set delFlag = '1'
        <where>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="prodAttrId != null "> and prodAttrId = #{prodAttrId}</if>
            <if test="buyerId != null "> and buyerId = #{buyerId}</if>
            <if test="buyerRoleKey != null  and buyerRoleKey != ''"> and buyerRoleKey = #{buyerRoleKey}</if>
            <if test="sellerId != null "> and sellerId = #{sellerId}</if>
            <if test="sellerRoleKey != null  and sellerRoleKey != ''"> and sellerRoleKey = #{sellerRoleKey}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>