<?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.WxLotteryMapper">
    
    <resultMap type="WxLottery" id="WxLotteryResult">
        <result property="id"    column="id"    />
        <result property="lotteryDesc"    column="lottery_desc"    />
        <result property="lotteryNum"    column="lottery_num"    />
        <result property="lotteryImage"    column="lottery_image"    />
        <result property="lotteryTime"    column="lottery_time"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateDate"    column="update_date"    />
    </resultMap>

    <sql id="selectWxLotteryVo">
        select id, lottery_desc, lottery_num, lottery_image, lottery_time, create_date, update_date from wx_lottery
    </sql>

    <select id="selectWxLotteryList" parameterType="WxLottery" resultMap="WxLotteryResult">
        <include refid="selectWxLotteryVo"/>
        <where>  
            <if test="lotteryDesc != null  and lotteryDesc != ''"> and lottery_desc = #{lotteryDesc}</if>
            <if test="lotteryNum != null "> and lottery_num = #{lotteryNum}</if>
            <if test="lotteryImage != null  and lotteryImage != ''"> and lottery_image = #{lotteryImage}</if>
            <if test="lotteryTime != null "> and lottery_time = #{lotteryTime}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
        </where>
    </select>
    
    <select id="selectWxLotteryById" parameterType="Long" resultMap="WxLotteryResult">
        <include refid="selectWxLotteryVo"/>
        where id = #{id}
    </select>

    <insert id="insertWxLottery" parameterType="WxLottery" useGeneratedKeys="true" keyProperty="id">
        insert into wx_lottery
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lotteryDesc != null">lottery_desc,</if>
            <if test="lotteryNum != null">lottery_num,</if>
            <if test="lotteryImage != null">lottery_image,</if>
            <if test="lotteryTime != null">lottery_time,</if>
            <if test="createDate != null">create_date,</if>
            <if test="updateDate != null">update_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="lotteryDesc != null">#{lotteryDesc},</if>
            <if test="lotteryNum != null">#{lotteryNum},</if>
            <if test="lotteryImage != null">#{lotteryImage},</if>
            <if test="lotteryTime != null">#{lotteryTime},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateDate != null">#{updateDate},</if>
         </trim>
    </insert>

    <update id="updateWxLottery" parameterType="WxLottery">
        update wx_lottery
        <trim prefix="SET" suffixOverrides=",">
            <if test="lotteryDesc != null">lottery_desc = #{lotteryDesc},</if>
            <if test="lotteryNum != null">lottery_num = #{lotteryNum},</if>
            <if test="lotteryImage != null">lottery_image = #{lotteryImage},</if>
            <if test="lotteryTime != null">lottery_time = #{lotteryTime},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxLotteryById" parameterType="Long">
        delete from wx_lottery where id = #{id}
    </delete>

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

    <select id="selectWxLotteryListByTime" resultMap="WxLotteryResult">
        <include refid="selectWxLotteryVo"/>
        <where>
            <if test="type != null and type != '' and type == 'now'">
                lottery_time >= #{date,jdbcType=TIMESTAMP}
            </if>
            <if test="type != null and type != '' and type == 'history'">
                lottery_time &lt;= #{date,jdbcType=TIMESTAMP}
            </if>
        </where>
    </select>
</mapper>