<?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.business.SuggestProd.mapper.SuggestProdMapper">
    <resultMap type="SuggestProd" id="SuggestProdResult">
        <result property="id"    column="id"    />
        <result property="mercProdId"    column="mercProdId"    />
        <result property="sort"    column="sort"    />
        <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="selectSuggestProd">
        select id, mercProdId, sort, delFlag, createUser, createTime, updateUser, updateTime from t_suggest_prod
    </sql>

    <select id="selectSuggestProdList" parameterType="SuggestProd" resultMap="SuggestProdResult">
        <include refid="selectSuggestProd"/>
        <where>  
            <if test="mercProdId != null "> and mercProdId = #{mercProdId}</if>
            <if test="sort != null "> and sort = #{sort}</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>
        order by sort
    </select>
    
    <select id="selectSuggestProdById" parameterType="Long" resultMap="SuggestProdResult">
        <include refid="selectSuggestProd"/>
        where id = #{id}
    </select>
        
    <insert id="insertSuggestProd" parameterType="SuggestProd" useGeneratedKeys="true" keyProperty="id">
        insert into t_suggest_prod
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mercProdId != null">mercProdId,</if>
            <if test="sort != null">sort,</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="mercProdId != null">#{mercProdId},</if>
            <if test="sort != null">#{sort},</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="batchInsertSuggestProd">
        insert into t_suggest_prod( mercProdId, sort, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.mercProdId}, #{item.sort}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateSuggestProd" parameterType="SuggestProd">
        update t_suggest_prod
        <trim prefix="SET" suffixOverrides=",">
            <if test="mercProdId != null">mercProdId = #{mercProdId},</if>
            <if test="sort != null">sort = #{sort},</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 id = #{id}
    </update>

    <delete id="deleteSuggestProdById" parameterType="Long">
        delete from t_suggest_prod where id = #{id}
    </delete>

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

    <update id="logicDeleteSuggestProdById" parameterType="Long">
        update t_suggest_prod
            set delFlag = '1'
        where id = #{id}
    </update>

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

    <update id="logicDeleteSuggestProdByCondition" parameterType="SuggestProd">
        update t_suggest_prod
        set delFlag = '1'
        <where>
            <if test="mercProdId != null "> and mercProdId = #{mercProdId}</if>
            <if test="sort != null "> and sort = #{sort}</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>