<?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.fs.store.mapper.FsStoreProductRelationMapper">
    
    <resultMap type="FsStoreProductRelation" id="FsStoreProductRelationResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="productId"    column="product_id"    />
        <result property="type"    column="type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectFsStoreProductRelationVo">
        select id, user_id, product_id, type, create_time, update_time, is_del from fs_store_product_relation
    </sql>

    <select id="selectFsStoreProductRelationList" parameterType="FsStoreProductRelation" resultMap="FsStoreProductRelationResult">
        <include refid="selectFsStoreProductRelationVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectFsStoreProductRelationById" parameterType="Long" resultMap="FsStoreProductRelationResult">
        <include refid="selectFsStoreProductRelationVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsStoreProductRelation" parameterType="FsStoreProductRelation" useGeneratedKeys="true" keyProperty="id">
        insert into fs_store_product_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="productId != null">product_id,</if>
            <if test="type != null">type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="productId != null">#{productId},</if>
            <if test="type != null">#{type},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateFsStoreProductRelation" parameterType="FsStoreProductRelation">
        update fs_store_product_relation
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsStoreProductRelationById" parameterType="Long">
        update fs_store_product_relation set is_del=1 where id = #{id}
    </delete>

    <delete id="deleteFsStoreProductRelationByIds" parameterType="String">
        update fs_store_product_relation set is_del=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>