<?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.merchant.mapper.MerchantProdMapper">
    <resultMap type="MerchantProd" id="MerchantProdResult">
        <result property="mercProdId"    column="mercProdId"    />
        <result property="mercId"    column="mercId"    />
        <result property="prodId"    column="prodId"    />
        <result property="prodAttrId"    column="prodAttrId"    />
        <result property="shelfTime"    column="shelfTime"    />
        <result property="shelfFlag"    column="shelfFlag"    />
        <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="selectMerchantProd">
        select mercProdId, mercId, prodId, prodAttrId, shelfTime, shelfFlag, delFlag, createUser, createTime, updateUser, updateTime from m_merchant_prod
    </sql>

    <select id="selectMerchantProdList" parameterType="MerchantProd" resultMap="MerchantProdResult">
        <include refid="selectMerchantProd"/>
        <where>  
            <if test="mercId != null "> and mercId = #{mercId}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="prodAttrId != null "> and prodAttrId = #{prodAttrId}</if>
            <if test="shelfTime != null "> and shelfTime = #{shelfTime}</if>
            <if test="shelfFlag != null  and shelfFlag != ''"> and shelfFlag = #{shelfFlag}</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="selectMerchantProdByMercProdId" parameterType="Long" resultMap="MerchantProdResult">
        <include refid="selectMerchantProd"/>
        where mercProdId = #{mercProdId}
    </select>
        
    <insert id="insertMerchantProd" parameterType="MerchantProd" useGeneratedKeys="true" keyProperty="mercProdId">
        insert into m_merchant_prod
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mercId != null">mercId,</if>
            <if test="prodId != null">prodId,</if>
            <if test="prodAttrId != null">prodAttrId,</if>
            <if test="shelfTime != null">shelfTime,</if>
            <if test="shelfFlag != null">shelfFlag,</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="mercId != null">#{mercId},</if>
            <if test="prodId != null">#{prodId},</if>
            <if test="prodAttrId != null">#{prodAttrId},</if>
            <if test="shelfTime != null">#{shelfTime},</if>
            <if test="shelfFlag != null">#{shelfFlag},</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="batchInsertMerchantProd">
        insert into m_merchant_prod( mercId, prodId, prodAttrId, shelfTime, shelfFlag, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.mercId}, #{item.prodId}, #{item.prodAttrId}, #{item.shelfTime}, #{item.shelfFlag}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateMerchantProd" parameterType="MerchantProd">
        update m_merchant_prod
        <trim prefix="SET" suffixOverrides=",">
            <if test="mercId != null">mercId = #{mercId},</if>
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="prodAttrId != null">prodAttrId = #{prodAttrId},</if>
            <if test="shelfTime != null">shelfTime = #{shelfTime},</if>
            <if test="shelfFlag != null">shelfFlag = #{shelfFlag},</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 mercProdId = #{mercProdId}
    </update>

    <delete id="deleteMerchantProdByMercProdId" parameterType="Long">
        delete from m_merchant_prod where mercProdId = #{mercProdId}
    </delete>

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

    <update id="logicDeleteMerchantProdByMercProdId" parameterType="Long">
        update m_merchant_prod
            set delFlag = '1'
        where mercProdId = #{mercProdId}
    </update>

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

    <update id="logicDeleteMerchantProdByCondition" parameterType="MerchantProd">
        update m_merchant_prod
        set delFlag = '1'
        <where>
            <if test="mercId != null "> and mercId = #{mercId}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="prodAttrId != null "> and prodAttrId = #{prodAttrId}</if>
            <if test="shelfTime != null "> and shelfTime = #{shelfTime}</if>
            <if test="shelfFlag != null  and shelfFlag != ''"> and shelfFlag = #{shelfFlag}</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>