<?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.PromotionActivityMapper">

    <resultMap type="PromotionActivity" id="PromotionActivityResult">
        <result property="id" column="id" />
        <result property="storeId" column="store_id" />
        <result property="type" column="type" />
        <result property="name" column="name" />
        <result property="status" column="status" />
        <result property="startTime" column="start_time" />
        <result property="endTime" column="end_time" />
        <result property="createTime" column="create_time" />
        <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="selectPromotionActivityVo">
        select id, store_id, type, name, status, start_time, end_time, create_time, update_time
        from promotion_activity
    </sql>

    <select id="selectPromotionActivityList" parameterType="PromotionActivity" resultMap="PromotionActivityResult">
        <include refid="selectPromotionActivityVo"/>
        <where>
            <if test="storeId != null">and store_id = #{storeId}</if>
            <if test="type != null">and type = #{type}</if>
            <if test="status != null">and status = #{status}</if>
        </where>
        order by id desc
    </select>

    <select id="selectPromotionActivityById" parameterType="Long" resultMap="PromotionActivityResult">
        <include refid="selectPromotionActivityVo"/>
        where id = #{id}
    </select>

    <insert id="insertPromotionActivity" parameterType="PromotionActivity" useGeneratedKeys="true" keyProperty="id">
        insert into promotion_activity
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="storeId != null">store_id,</if>
            <if test="type != null">type,</if>
            <if test="name != null">name,</if>
            <if test="status != null">status,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="storeId != null">#{storeId},</if>
            <if test="type != null">#{type},</if>
            <if test="name != null">#{name},</if>
            <if test="status != null">#{status},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updatePromotionActivity" parameterType="PromotionActivity">
        update promotion_activity
        <trim prefix="SET" suffixOverrides=",">
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="name != null">name = #{name},</if>
            <if test="status != null">status = #{status},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <select id="selectActiveByStoreId" parameterType="Long" resultMap="PromotionActivityResult">
        <include refid="selectPromotionActivityVo"/>
        where store_id = #{storeId} and status = 1
        order by type asc
    </select>

</mapper>