<?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.FsStoreActivityMapper">
    
    <resultMap type="FsStoreActivity" id="FsStoreActivityResult">
        <result property="activityId"    column="activity_id"    />
        <result property="title"    column="title"    />
        <result property="descs"    column="descs"    />
        <result property="logoUrl"    column="logo_url"    />
        <result property="images"    column="images"    />
        <result property="productIds"    column="product_ids"    />
        <result property="content"    column="content"    />
        <result property="createTime"    column="create_time"    />
        <result property="status"    column="status"    />
        <result property="shareNumber"    column="share_number"    />
    </resultMap>

    <sql id="selectFsStoreActivityVo">
        select activity_id, title, descs, logo_url, images, product_ids, content, create_time, status,share_number from fs_store_activity
    </sql>

    <select id="selectFsStoreActivityList" parameterType="FsStoreActivity" resultMap="FsStoreActivityResult">
        <include refid="selectFsStoreActivityVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="logoUrl != null  and logoUrl != ''"> and logo_url = #{logoUrl}</if>
            <if test="images != null  and images != ''"> and images = #{images}</if>
            <if test="productIds != null  and productIds != ''"> and product_ids = #{productIds}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        order by activity_id desc
    </select>
    
    <select id="selectFsStoreActivityById" parameterType="Long" resultMap="FsStoreActivityResult">
        <include refid="selectFsStoreActivityVo"/>
        where activity_id = #{activityId}
    </select>
        
    <insert id="insertFsStoreActivity" parameterType="FsStoreActivity" useGeneratedKeys="true" keyProperty="activityId">
        insert into fs_store_activity
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="descs != null">descs,</if>
            <if test="logoUrl != null">logo_url,</if>
            <if test="images != null">images,</if>
            <if test="productIds != null">product_ids,</if>
            <if test="content != null">content,</if>
            <if test="createTime != null">create_time,</if>
            <if test="status != null">status,</if>
            <if test="shareNumber != null">share_number,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="descs != null">#{descs},</if>
            <if test="logoUrl != null">#{logoUrl},</if>
            <if test="images != null">#{images},</if>
            <if test="productIds != null">#{productIds},</if>
            <if test="content != null">#{content},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
            <if test="shareNumber != null">#{shareNumber},</if>
         </trim>
    </insert>

    <update id="updateFsStoreActivity" parameterType="FsStoreActivity">
        update fs_store_activity
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="descs != null">descs = #{descs},</if>
            <if test="logoUrl != null">logo_url = #{logoUrl},</if>
            <if test="images != null">images = #{images},</if>
            <if test="productIds != null">product_ids = #{productIds},</if>
            <if test="content != null">content = #{content},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="shareNumber != null">share_number = #{shareNumber},</if>
        </trim>
        where activity_id = #{activityId}
    </update>

    <delete id="deleteFsStoreActivityById" parameterType="Long">
        delete from fs_store_activity where activity_id = #{activityId}
    </delete>

    <delete id="deleteFsStoreActivityByIds" parameterType="String">
        delete from fs_store_activity where activity_id in 
        <foreach item="activityId" collection="array" open="(" separator="," close=")">
            #{activityId}
        </foreach>
    </delete>
    
</mapper>