<?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.game.business.mapper.AppGameLotteryMapper">
    
    <resultMap type="com.game.business.domain.AppGameLottery" id="AppGameLotteryResult">
        <result property="id"    column="id"    />
        <result property="classId"    column="class_id"    />
        <result property="gameId"    column="game_id"    />
        <result property="gameDate"    column="game_date"    />
        <result property="isLottery"    column="is_lottery"    />
        <result property="gameLotterySucc"    column="game_lottery_succ"    />
        <result property="gameRecordDate"    column="game_record_date"    />
    </resultMap>

    <sql id="selectAppGameLotteryVo">
        select id, class_id, game_id, game_date, is_lottery, game_lottery_succ, game_record_date from app_game_lottery
    </sql>

    <select id="selectAppGameLotteryList" parameterType="com.game.business.domain.AppGameLottery" resultMap="AppGameLotteryResult">
        <include refid="selectAppGameLotteryVo"/>
        <where>  
            <if test="classId != null "> and class_id = #{classId}</if>
            <if test="gameId != null "> and game_id = #{gameId}</if>
            <if test="gameDate != null  and gameDate != ''"> and game_date = #{gameDate}</if>
            <if test="isLottery != null"> and is_lottery = #{isLottery}</if>
            <if test="gameLotterySucc != null  and gameLotterySucc != ''"> and FIND_IN_SET(#{gameLotterySucc},game_lottery_succ) > 0</if>
            <if test="gameRecordDate != null "> and game_record_date = #{gameRecordDate}</if>
        </where>
        order by game_record_date desc
    </select>
    
    <select id="selectAppGameLotteryById" parameterType="Long" resultMap="AppGameLotteryResult">
        <include refid="selectAppGameLotteryVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAppGameLottery" parameterType="com.game.business.domain.AppGameLottery" useGeneratedKeys="true" keyProperty="id">
        insert into app_game_lottery
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="classId != null">class_id,</if>
            <if test="gameId != null">game_id,</if>
            <if test="gameDate != null">game_date,</if>
            <if test="isLottery != null">is_lottery,</if>
            <if test="gameLotterySucc != null">game_lottery_succ,</if>
            <if test="gameRecordDate != null">game_record_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="classId != null">#{classId},</if>
            <if test="gameId != null">#{gameId},</if>
            <if test="gameDate != null">#{gameDate},</if>
            <if test="isLottery != null">#{isLottery},</if>
            <if test="gameLotterySucc != null">#{gameLotterySucc},</if>
            <if test="gameRecordDate != null">#{gameRecordDate},</if>
         </trim>
    </insert>

    <update id="updateAppGameLottery" parameterType="com.game.business.domain.AppGameLottery">
        update app_game_lottery
        <trim prefix="SET" suffixOverrides=",">
            <if test="classId != null">class_id = #{classId},</if>
            <if test="gameId != null">game_id = #{gameId},</if>
            <if test="gameDate != null">game_date = #{gameDate},</if>
            <if test="isLottery != null">is_lottery = #{isLottery},</if>
            <if test="gameLotterySucc != null">game_lottery_succ = #{gameLotterySucc},</if>
            <if test="gameRecordDate != null">game_record_date = #{gameRecordDate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppGameLotteryById" parameterType="Long">
        delete from app_game_lottery where id = #{id}
    </delete>

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