<?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.ProdTagMapper">
    <resultMap type="ProdTag" id="ProdTagResult">
        <result property="id"    column="id"    />
        <result property="prodId"    column="prodId"    />
        <result property="tagId"    column="tagId"    />
        <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="selectProdTag">
        select id, prodId, tagId, delFlag, createUser, createTime, updateUser, updateTime from m_prod_tag
    </sql>

    <select id="selectProdTagList" parameterType="ProdTag" resultMap="ProdTagResult">
        <include refid="selectProdTag"/>
        <where>  
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="tagId != null "> and tagId = #{tagId}</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="selectProdTagById" parameterType="Long" resultMap="ProdTagResult">
        <include refid="selectProdTag"/>
        where id = #{id}
    </select>
        
    <insert id="insertProdTag" parameterType="ProdTag" useGeneratedKeys="true" keyProperty="id">
        insert into m_prod_tag
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prodId != null">prodId,</if>
            <if test="tagId != null">tagId,</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="tagId != null">#{tagId},</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="batchInsertProdTag">
        insert into m_prod_tag( prodId, tagId, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.prodId}, #{item.tagId}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateProdTag" parameterType="ProdTag">
        update m_prod_tag
        <trim prefix="SET" suffixOverrides=",">
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="tagId != null">tagId = #{tagId},</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="deleteProdTagById" parameterType="Long">
        delete from m_prod_tag where id = #{id}
    </delete>

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

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

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

    <update id="logicDeleteProdTagByCondition" parameterType="ProdTag">
        update m_prod_tag
        set delFlag = '1'
        <where>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="tagId != null "> and tagId = #{tagId}</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>