<?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.ruoyi.system.mapper.ActivityInfoMapper">
    
    <resultMap type="ActivityInfo" id="ActivityInfoResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="content"    column="content"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="creator"    column="creator"    />
        <result property="modify"    column="modify"    />
        <result property="shelf"    column="shelf"    />
        <result property="isDel"    column="is_del"    />
        <result property="img"    column="img"    />
    </resultMap>

    <sql id="selectActivityInfoVo">
        select id, name, content, start_time, end_time, creator, modify, shelf, is_del, img from activity_info
    </sql>

    <select id="selectActivityInfoList" parameterType="ActivityInfo" resultMap="ActivityInfoResult">
        <include refid="selectActivityInfoVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="creator != null  and creator != ''"> and creator = #{creator}</if>
            <if test="modify != null  and modify != ''"> and modify = #{modify}</if>
            <if test="shelf != null "> and shelf = #{shelf}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="img != null  and img != ''"> and img = #{img}</if>
        </where>
    </select>
    
    <select id="selectActivityInfoById" parameterType="String" resultMap="ActivityInfoResult">
        <include refid="selectActivityInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertActivityInfo" parameterType="ActivityInfo" useGeneratedKeys="true" keyProperty="id">
        insert into activity_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="content != null">content,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="creator != null">creator,</if>
            <if test="modify != null">modify,</if>
            <if test="shelf != null">shelf,</if>
            <if test="isDel != null">is_del,</if>
            <if test="img != null">img,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="content != null">#{content},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="creator != null">#{creator},</if>
            <if test="modify != null">#{modify},</if>
            <if test="shelf != null">#{shelf},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="img != null">#{img},</if>
         </trim>
    </insert>

    <update id="updateActivityInfo" parameterType="ActivityInfo">
        update activity_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="content != null">content = #{content},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="modify != null">modify = #{modify},</if>
            <if test="shelf != null">shelf = #{shelf},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="img != null">img = #{img},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteActivityInfoById" parameterType="String">
        delete from activity_info where id = #{id}
    </delete>

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

    <select id="selectActivityShelfInfo" resultMap="ActivityInfoResult">
        SELECT * FROM activity_info where shelf=1 order by  end_time desc limit 1;
    </select>

    <select id="selectActivityInfoByUserId" resultType="com.ruoyi.common.core.domain.entity.ActivityInfo">
        SELECT  activity_id as activityId FROM  user_activity where user_id=#{userId}
    </select>

    <insert id="insertActivityUser">
        insert into user_activity(user_id, activity_id) value (#{userId},#{activityId})
    </insert>
</mapper>