<?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.GameFreeRecordMapper">
    
    <resultMap type="GameFreeRecord" id="GameFreeRecordResult">
        <result property="id"    column="id"    />
        <result property="currencyCode"    column="currency_code"    />
        <result property="platformCode"    column="platform_code"    />
        <result property="referenceId"    column="reference_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="memberAccount"    column="member_account"    />
        <result property="gameId"    column="game_id"    />
        <result property="sendTime"    column="send_time"    />
        <result property="expiredTime"    column="expired_time"    />
        <result property="freeUpdateTime"    column="free_update_time"    />
        <result property="sendGame"    column="send_game"    />
        <result property="sendAmount"    column="send_amount"    />
        <result property="usedAmount"    column="used_amount"    />
        <result property="unusedAmount"    column="unused_amount"    />
        <result property="freeStatus"    column="free_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="selectGameFreeRecordVo">
        select id, currency_code, platform_code, reference_id, member_id, member_account, game_id, send_time, expired_time, free_update_time, send_game, send_amount, used_amount, unused_amount, free_status, create_by, create_time, update_by, update_time from ff_game_free_record
    </sql>

    <select id="selectGameFreeRecordList" parameterType="GameFreeRecord" resultMap="GameFreeRecordResult">
        <include refid="selectGameFreeRecordVo"/>
        <where>  
            <if test="currencyCode != null  and currencyCode != ''"> and currency_code = #{currencyCode}</if>
            <if test="platformCode != null  and platformCode != ''"> and platform_code = #{platformCode}</if>
            <if test="referenceId != null  and referenceId != ''"> and reference_id = #{referenceId}</if>
            <if test="memberId != null "> and member_id = #{memberId}</if>
            <if test="memberAccount != null  and memberAccount != ''"> and member_account = #{memberAccount}</if>
            <if test="gameId != null "> and game_id = #{gameId}</if>
            <if test="sendTime != null "> and send_time = #{sendTime}</if>
            <if test="expiredTime != null "> and expired_time = #{expiredTime}</if>
            <if test="freeUpdateTime != null "> and free_update_time = #{freeUpdateTime}</if>
            <if test="sendGame != null  and sendGame != ''"> and send_game = #{sendGame}</if>
            <if test="sendAmount != null "> and send_amount = #{sendAmount}</if>
            <if test="usedAmount != null "> and used_amount = #{usedAmount}</if>
            <if test="unusedAmount != null "> and unused_amount = #{unusedAmount}</if>
            <if test="freeStatus != null "> and free_status = #{freeStatus}</if>
        </where>
    </select>
    
    <select id="selectGameFreeRecordById" parameterType="Long" resultMap="GameFreeRecordResult">
        <include refid="selectGameFreeRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertGameFreeRecord" parameterType="GameFreeRecord" useGeneratedKeys="true" keyProperty="id">
        insert into ff_game_free_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="currencyCode != null">currency_code,</if>
            <if test="platformCode != null">platform_code,</if>
            <if test="referenceId != null">reference_id,</if>
            <if test="memberId != null">member_id,</if>
            <if test="memberAccount != null">member_account,</if>
            <if test="gameId != null">game_id,</if>
            <if test="sendTime != null">send_time,</if>
            <if test="expiredTime != null">expired_time,</if>
            <if test="freeUpdateTime != null">free_update_time,</if>
            <if test="sendGame != null">send_game,</if>
            <if test="sendAmount != null">send_amount,</if>
            <if test="usedAmount != null">used_amount,</if>
            <if test="unusedAmount != null">unused_amount,</if>
            <if test="freeStatus != null">free_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="platformCode != null">#{platformCode},</if>
            <if test="referenceId != null">#{referenceId},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="memberAccount != null">#{memberAccount},</if>
            <if test="gameId != null">#{gameId},</if>
            <if test="sendTime != null">#{sendTime},</if>
            <if test="expiredTime != null">#{expiredTime},</if>
            <if test="freeUpdateTime != null">#{freeUpdateTime},</if>
            <if test="sendGame != null">#{sendGame},</if>
            <if test="sendAmount != null">#{sendAmount},</if>
            <if test="usedAmount != null">#{usedAmount},</if>
            <if test="unusedAmount != null">#{unusedAmount},</if>
            <if test="freeStatus != null">#{freeStatus},</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="updateGameFreeRecord" parameterType="GameFreeRecord">
        update ff_game_free_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="currencyCode != null">currency_code = #{currencyCode},</if>
            <if test="platformCode != null">platform_code = #{platformCode},</if>
            <if test="referenceId != null">reference_id = #{referenceId},</if>
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="memberAccount != null">member_account = #{memberAccount},</if>
            <if test="gameId != null">game_id = #{gameId},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="expiredTime != null">expired_time = #{expiredTime},</if>
            <if test="freeUpdateTime != null">free_update_time = #{freeUpdateTime},</if>
            <if test="sendGame != null">send_game = #{sendGame},</if>
            <if test="sendAmount != null">send_amount = #{sendAmount},</if>
            <if test="usedAmount != null">used_amount = #{usedAmount},</if>
            <if test="unusedAmount != null">unused_amount = #{unusedAmount},</if>
            <if test="freeStatus != null">free_status = #{freeStatus},</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="deleteGameFreeRecordById" parameterType="Long">
        delete from ff_game_free_record where id = #{id}
    </delete>

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