<?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.ff.game.mapper.GameBettingDetailsMapper">
    
    <resultMap type="GameBettingDetails" id="GameBettingDetailsResult">
        <result property="id"    column="id"    />
        <result property="currencyCode"    column="currency_code"    />
        <result property="memberId"    column="member_id"    />
        <result property="gameCode"    column="game_code"    />
        <result property="gameId"    column="game_id"    />
        <result property="gameType"    column="game_type"    />
        <result property="platformCode"    column="platform_code"    />
        <result property="gameName"    column="game_name"    />
        <result property="gameStatus"    column="game_status"    />
        <result property="gameStatusType"    column="game_status_type"    />
        <result property="gameCurrencyCode"    column="game_currency_code"    />
        <result property="account"    column="account"    />
        <result property="wagersId"    column="wagers_id"    />
        <result property="wagersTime"    column="wagers_time"    />
        <result property="betAmount"    column="bet_amount"    />
        <result property="payoffTime"    column="payoff_time"    />
        <result property="payoffAmount"    column="payoff_amount"    />
        <result property="settlementTime"    column="settlement_time"    />
        <result property="turnover"    column="turnover"    />
        <result property="orderNo"    column="order_no"    />
        <result property="settlementStatus"    column="settlement_status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectGameBettingDetailsVo">
        select id, currency_code, member_id, game_code, game_id, game_type, platform_code, game_name, game_status, game_status_type, game_currency_code, account, wagers_id, wagers_time, bet_amount, payoff_time, payoff_amount, settlement_time, turnover, order_no, settlement_status, create_by, create_time, update_by, update_time from ff_game_betting_details
    </sql>

    <select id="selectGameBettingDetailsList" parameterType="GameBettingDetails" resultMap="GameBettingDetailsResult">
        <include refid="selectGameBettingDetailsVo"/>
        <where>  
            <if test="currencyCode != null  and currencyCode != ''"> and currency_code = #{currencyCode}</if>
            <if test="memberId != null "> and member_id = #{memberId}</if>
            <if test="gameCode != null "> and game_code = #{gameCode}</if>
            <if test="gameId != null "> and game_id = #{gameId}</if>
            <if test="gameType != null "> and game_type = #{gameType}</if>
            <if test="platformCode != null  and platformCode != ''"> and platform_code = #{platformCode}</if>
            <if test="gameName != null  and gameName != ''"> and game_name like concat('%', #{gameName}, '%')</if>
            <if test="gameStatus != null "> and game_status = #{gameStatus}</if>
            <if test="gameStatusType != null "> and game_status_type = #{gameStatusType}</if>
            <if test="gameCurrencyCode != null  and gameCurrencyCode != ''"> and game_currency_code = #{gameCurrencyCode}</if>
            <if test="account != null  and account != ''"> and account = #{account}</if>
            <if test="wagersId != null "> and wagers_id = #{wagersId}</if>
            <if test="wagersTime != null "> and wagers_time = #{wagersTime}</if>
            <if test="betAmount != null "> and bet_amount = #{betAmount}</if>
            <if test="payoffTime != null "> and payoff_time = #{payoffTime}</if>
            <if test="payoffAmount != null "> and payoff_amount = #{payoffAmount}</if>
            <if test="settlementTime != null "> and settlement_time = #{settlementTime}</if>
            <if test="turnover != null "> and turnover = #{turnover}</if>
            <if test="orderNo != null  and orderNo != ''"> and order_no = #{orderNo}</if>
            <if test="settlementStatus != null "> and settlement_status = #{settlementStatus}</if>
            <if test="params.beginTime != null">
                AND wagers_time &gt;= #{params.beginTime}
            </if>
            <if test="params.endTime != null">
                AND wagers_time &lt;= #{params.endTime}

            </if>
        </where>
    </select>
    
    <select id="selectGameBettingDetailsById" parameterType="Long" resultMap="GameBettingDetailsResult">
        <include refid="selectGameBettingDetailsVo"/>
        where id = #{id}
    </select>


    <select id="selectGameBettingDetailsByWagersId"  resultType="java.lang.Long">
        select wagers_id from ff_game_betting_details

        where wagers_id in
        <foreach item="wagersId" collection="wagersIds" open="(" separator="," close=")">
            #{wagersId}
        </foreach>

    </select>


    <insert id="insertGameBettingDetails" parameterType="GameBettingDetails" useGeneratedKeys="true" keyProperty="id">
        insert into ff_game_betting_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="currencyCode != null">currency_code,</if>
            <if test="memberId != null">member_id,</if>
            <if test="gameCode != null">game_code,</if>
            <if test="gameId != null">game_id,</if>
            <if test="gameType != null">game_type,</if>
            <if test="platformCode != null">platform_code,</if>
            <if test="gameName != null">game_name,</if>
            <if test="gameStatus != null">game_status,</if>
            <if test="gameStatusType != null">game_status_type,</if>
            <if test="gameCurrencyCode != null">game_currency_code,</if>
            <if test="account != null">account,</if>
            <if test="wagersId != null">wagers_id,</if>
            <if test="wagersTime != null">wagers_time,</if>
            <if test="betAmount != null">bet_amount,</if>
            <if test="payoffTime != null">payoff_time,</if>
            <if test="payoffAmount != null">payoff_amount,</if>
            <if test="settlementTime != null">settlement_time,</if>
            <if test="turnover != null">turnover,</if>
            <if test="orderNo != null">order_no,</if>
            <if test="settlementStatus != null">settlement_status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="currencyCode != null">#{currencyCode},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="gameCode != null">#{gameCode},</if>
            <if test="gameId != null">#{gameId},</if>
            <if test="gameType != null">#{gameType},</if>
            <if test="platformCode != null">#{platformCode},</if>
            <if test="gameName != null">#{gameName},</if>
            <if test="gameStatus != null">#{gameStatus},</if>
            <if test="gameStatusType != null">#{gameStatusType},</if>
            <if test="gameCurrencyCode != null">#{gameCurrencyCode},</if>
            <if test="account != null">#{account},</if>
            <if test="wagersId != null">#{wagersId},</if>
            <if test="wagersTime != null">#{wagersTime},</if>
            <if test="betAmount != null">#{betAmount},</if>
            <if test="payoffTime != null">#{payoffTime},</if>
            <if test="payoffAmount != null">#{payoffAmount},</if>
            <if test="settlementTime != null">#{settlementTime},</if>
            <if test="turnover != null">#{turnover},</if>
            <if test="orderNo != null">#{orderNo},</if>
            <if test="settlementStatus != null">#{settlementStatus},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateGameBettingDetails" parameterType="GameBettingDetails">
        update ff_game_betting_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="currencyCode != null">currency_code = #{currencyCode},</if>
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="gameCode != null">game_code = #{gameCode},</if>
            <if test="gameId != null">game_id = #{gameId},</if>
            <if test="gameType != null">game_type = #{gameType},</if>
            <if test="platformCode != null">platform_code = #{platformCode},</if>
            <if test="gameName != null">game_name = #{gameName},</if>
            <if test="gameStatus != null">game_status = #{gameStatus},</if>
            <if test="gameStatusType != null">game_status_type = #{gameStatusType},</if>
            <if test="gameCurrencyCode != null">game_currency_code = #{gameCurrencyCode},</if>
            <if test="account != null">account = #{account},</if>
            <if test="wagersId != null">wagers_id = #{wagersId},</if>
            <if test="wagersTime != null">wagers_time = #{wagersTime},</if>
            <if test="betAmount != null">bet_amount = #{betAmount},</if>
            <if test="payoffTime != null">payoff_time = #{payoffTime},</if>
            <if test="payoffAmount != null">payoff_amount = #{payoffAmount},</if>
            <if test="settlementTime != null">settlement_time = #{settlementTime},</if>
            <if test="turnover != null">turnover = #{turnover},</if>
            <if test="orderNo != null">order_no = #{orderNo},</if>
            <if test="settlementStatus != null">settlement_status = #{settlementStatus},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGameBettingDetailsById" parameterType="Long">
        delete from ff_game_betting_details where id = #{id}
    </delete>

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

    <insert id="batchInsert" parameterType="list" useGeneratedKeys="true" keyProperty="id">
        insert into ff_game_betting_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            game_id, currency_code, member_id, game_code, game_type, platform_code,
            game_name, game_status, game_status_type, game_currency_code, account,
            wagers_id, wagers_time, bet_amount, payoff_time, payoff_amount,
            settlement_time, turnover, order_no, create_by, create_time
        </trim>
        values
        <foreach collection="list" item="item" separator=",">
            <trim prefix="(" suffix=")" suffixOverrides=",">
                #{item.gameId},
                #{item.currencyCode},
                #{item.memberId},
                #{item.gameCode},
                #{item.gameType},
                #{item.platformCode},
                #{item.gameName},
                #{item.gameStatus},
                #{item.gameStatusType},
                #{item.gameCurrencyCode},
                #{item.account},
                #{item.wagersId},
                #{item.wagersTime},
                #{item.betAmount},
                #{item.payoffTime},
                #{item.payoffAmount},
                #{item.settlementTime},
                #{item.turnover},
                #{item.orderNo},
                #{item.createBy},
                #{item.createTime}
            </trim>
        </foreach>
    </insert>
</mapper>