<?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.framework.recovery.mapper.RecSaleInfoMapper">

    <resultMap type="RecSaleInfo" id="RecSaleInfoResult">
        <result property="id"    column="id"    />
        <result property="saleName"    column="sale_name"    />
        <result property="salePrice"    column="sale_price"    />
        <result property="market"    column="market"    />
        <result property="storeId"    column="store_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
        <result property="catalog"    column="catalog"    />
        <result property="images"    column="images"    />
        <result property="eventStartTime"    column="event_start_time"    />
        <result property="endTimeOfActivity"    column="end_time_of_activity"    />
    </resultMap>

    <sql id="selectRecSaleInfoVo">
        select id, sale_name,catalog, sale_price, market, store_id, create_by, create_date, update_by, update_date,
            images, event_start_time, end_time_of_activity  from rec_sale_info
    </sql>

    <select id="selectRecSaleInfoList" parameterType="RecSaleInfo" resultMap="RecSaleInfoResult">
        <include refid="selectRecSaleInfoVo"/>
        <where>
            <if test="saleName != null  and saleName != ''"> and sale_name like concat('%', #{saleName}, '%')</if>
            <if test="salePrice != null  and salePrice != ''"> and sale_price = #{salePrice}</if>
            <if test="market != null  and market != ''"> and market = #{market}</if>
            <if test="storeId != null  and storeId != ''"> and store_id = #{storeId}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
            <if test="catalog != null "> and catalog = #{catalog}</if>
            <if test="images != null "> and images = #{images}</if>
            <if test="eventStartTime != null "> and event_start_time = #{eventStartTime}</if>
            <if test="endTimeOfActivity != null "> and end_time_of_activity = #{endTimeOfActivity}</if>
        </where>
    </select>

    <select id="selectRecSaleInfoById" parameterType="Long" resultMap="RecSaleInfoResult">
        <include refid="selectRecSaleInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertRecSaleInfo" parameterType="RecSaleInfo">
        insert into rec_sale_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="saleName != null">sale_name,</if>
            <if test="salePrice != null">sale_price,</if>
            <if test="market != null">market,</if>
            <if test="storeId != null">store_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createDate != null">create_date,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="catalog != null">catalog,</if>
            <if test="images != null">images,</if>
            <if test="eventStartTime != null">event_start_time,</if>
            <if test="endTimeOfActivity != null">end_time_of_activity,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="saleName != null">#{saleName},</if>
            <if test="salePrice != null">#{salePrice},</if>
            <if test="market != null">#{market},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="catalog != null">#{catalog},</if>
            <if test="images != null">#{images},</if>
            <if test="eventStartTime != null">#{eventStartTime},</if>
            <if test="endTimeOfActivity != null">#{endTimeOfActivity},</if>
         </trim>
    </insert>

    <update id="updateRecSaleInfo" parameterType="RecSaleInfo">
        update rec_sale_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="saleName != null">sale_name = #{saleName},</if>
            <if test="salePrice != null">sale_price = #{salePrice},</if>
            <if test="market != null">market = #{market},</if>
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="catalog != null">update_date = #{catalog},</if>
            <if test="images != null">images = #{images},</if>
            <if test="eventStartTime != null">event_start_time = #{eventStartTime},</if>
            <if test="endTimeOfActivity != null">end_time_of_activity = #{endTimeOfActivity},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRecSaleInfoById" parameterType="Long">
        delete from rec_sale_info where id = #{id}
    </delete>

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

    <select id="selectRecSaleInfoByTime" resultMap="RecSaleInfoResult">
        <include refid="selectRecSaleInfoVo"/>
        where (create_date between #{start,jdbcType=TIMESTAMP} and #{end,jdbcType=TIMESTAMP})
        or (event_start_time &lt; #{start,jdbcType=TIMESTAMP} and end_time_of_activity >= #{end,jdbcType=TIMESTAMP})
    </select>
</mapper>
