<?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.member.mapper.MemberMapper">

    <resultMap type="Member" id="MemberResult">
        <result property="id"    column="id"    />
        <result property="tenantKey"    column="tenant_key"    />
        <result property="memberAccount"    column="member_account"    />
        <result property="gameAccount"    column="game_account"    />
        <result property="platformCode"    column="platform_code"    />
        <result property="currencyCode"    column="currency_code"    />
        <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="selectMemberVo">
        select id, tenant_key, member_account, game_account, platform_code, currency_code, create_by, create_time, update_by, update_time from ff_member
    </sql>

    <select id="selectMemberList" parameterType="Member" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        <where>
            <if test="tenantKey != null  and tenantKey != ''"> and tenant_key = #{tenantKey}</if>
            <if test="memberAccount != null  and memberAccount != ''"> and member_account = #{memberAccount}</if>
            <if test="gameAccount != null  and gameAccount != ''"> and game_account = #{gameAccount}</if>
            <if test="platformCode != null  and platformCode != ''"> and platform_code = #{platformCode}</if>
            <if test="currencyCode != null  and currencyCode != ''"> and currency_code = #{currencyCode}</if>
        </where>
    </select>

    <select id="selectMemberById" parameterType="Long" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        where id = #{id}
    </select>

    <insert id="insertMember" parameterType="Member" useGeneratedKeys="true" keyProperty="id">
        insert into ff_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tenantKey != null">tenant_key,</if>
            <if test="memberAccount != null and memberAccount != ''">member_account,</if>
            <if test="gameAccount != null">game_account,</if>
            <if test="platformCode != null and platformCode != ''">platform_code,</if>
            <if test="currencyCode != null and currencyCode != ''">currency_code,</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="tenantKey != null">#{tenantKey},</if>
            <if test="memberAccount != null and memberAccount != ''">#{memberAccount},</if>
            <if test="gameAccount != null">#{gameAccount},</if>
            <if test="platformCode != null and platformCode != ''">#{platformCode},</if>
            <if test="currencyCode != null and currencyCode != ''">#{currencyCode},</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="updateMember" parameterType="Member">
        update ff_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="tenantKey != null">tenant_key = #{tenantKey},</if>
            <if test="memberAccount != null and memberAccount != ''">member_account = #{memberAccount},</if>
            <if test="gameAccount != null">game_account = #{gameAccount},</if>
            <if test="platformCode != null and platformCode != ''">platform_code = #{platformCode},</if>
            <if test="currencyCode != null and currencyCode != ''">currency_code = #{currencyCode},</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="deleteMemberById" parameterType="Long">
        delete from ff_member where id = #{id}
    </delete>

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

    <select id="selectMemberByMemberAccount" parameterType="String" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        where member_account = #{memberAccount}
    </select>

    <select id="selectMemberByGameAccount" parameterType="String" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        where game_account = #{gameAccount}
    </select>
</mapper>