<?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.WxUserLotteryMapper">
    
    <resultMap type="WxUserLottery" id="WxUserLotteryResult">
        <result property="id"    column="id"    />
        <result property="lotteryId"    column="lottery_id"    />
        <result property="lotteryNum"    column="lottery_num"    />
        <result property="openId"    column="open_id"    />
        <result property="mark"    column="mark"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateDate"    column="update_date"    />
        <result property="lotteryType"    column="lottery_type"    />
    </resultMap>

    <sql id="selectWxUserLotteryVo">
        select id, lottery_id, lottery_num, open_id, mark, lottery_type, create_date, update_date from wx_user_lottery
    </sql>

    <select id="selectWxUserLotteryList" parameterType="WxUserLottery" resultMap="WxUserLotteryResult">
        <include refid="selectWxUserLotteryVo"/>
        <where>  
            <if test="lotteryId != null "> and lottery_id = #{lotteryId}</if>
            <if test="lotteryNum != null  and lotteryNum != ''"> and lottery_num = #{lotteryNum}</if>
            <if test="openId != null "> and open_id = #{openId}</if>
            <if test="mark != null  and mark != ''"> and mark = #{mark}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
            <if test="lotteryType != null "> and lottery_type = #{lotteryType}</if>
        </where>
    </select>
    
    <select id="selectWxUserLotteryById" parameterType="Long" resultMap="WxUserLotteryResult">
        <include refid="selectWxUserLotteryVo"/>
        where id = #{id}
    </select>

    <insert id="insertWxUserLottery" parameterType="WxUserLottery" useGeneratedKeys="true" keyProperty="id">
        insert into wx_user_lottery
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lotteryId != null">lottery_id,</if>
            <if test="lotteryNum != null">lottery_num,</if>
            <if test="openId != null">open_id,</if>
            <if test="mark != null">mark,</if>
            <if test="createDate != null">create_date,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="lotteryType != null">lottery_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="lotteryId != null">#{lotteryId},</if>
            <if test="lotteryNum != null">#{lotteryNum},</if>
            <if test="openId != null">#{openId},</if>
            <if test="mark != null">#{mark},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="lotteryType != null">#{lotteryType},</if>
         </trim>
    </insert>

    <update id="updateWxUserLottery" parameterType="WxUserLottery">
        update wx_user_lottery
        <trim prefix="SET" suffixOverrides=",">
            <if test="lotteryId != null">lottery_id = #{lotteryId},</if>
            <if test="lotteryNum != null">lottery_num = #{lotteryNum},</if>
            <if test="openId != null">open_id = #{openId},</if>
            <if test="mark != null">mark = #{mark},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="lotteryType != null">lottery_type = #{lotteryType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxUserLotteryById" parameterType="Long">
        delete from wx_user_lottery where id = #{id}
    </delete>

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

    <select id="selectWxUserLotteryListByOpenId" resultType="com.ruoyi.framework.recovery.domain.WxUserLottery">

    </select>

    <select id="selectLotteryCodesByLotteryId" resultType="java.lang.Long">
        select lottery_num from wx_user_lottery where lottery_id = #{id} and mark = 1
    </select>
</mapper>