<?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.GameSecretKeyMapper">
    
    <resultMap type="GameSecretKey" id="GameSecretKeyResult">
        <result property="id"    column="id"    />
        <result property="platform"    column="platform"    />
        <result property="code"    column="code"    />
        <result property="key"    column="key"    />
        <result property="systemCode"    column="system_code"    />
        <result property="lang"    column="lang"    />
        <result property="systemLangCode"    column="system_lang_code"    />
        <result property="info"    column="info"    />
        <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="selectGameSecretKeyVo">
        select id, platform, code, `key`, system_code, lang, system_lang_code, info, create_by, create_time, update_by, update_time from ff_game_secret_key
    </sql>

    <select id="selectGameSecretKeyList" parameterType="GameSecretKey" resultMap="GameSecretKeyResult">
        <include refid="selectGameSecretKeyVo"/>
        <where>  
            <if test="platform != null  and platform != ''"> and platform = #{platform}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="key != null  and key != ''"> and `key` = #{key}</if>
            <if test="systemCode != null  and systemCode != ''"> and system_code = #{systemCode}</if>
            <if test="lang != null  and lang != ''"> and lang = #{lang}</if>
            <if test="systemLangCode != null  and systemLangCode != ''"> and system_lang_code = #{systemLangCode}</if>
            <if test="info != null  and info != ''"> and info = #{info}</if>
        </where>
    </select>
    
    <select id="selectGameSecretKeyById" parameterType="Long" resultMap="GameSecretKeyResult">
        <include refid="selectGameSecretKeyVo"/>
        where id = #{id}
    </select>

    <insert id="insertGameSecretKey" parameterType="GameSecretKey" useGeneratedKeys="true" keyProperty="id">
        insert into ff_game_secret_key
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="platform != null and platform != ''">platform,</if>
            <if test="code != null and code != ''">code,</if>
            <if test="key != null and key != ''">`key`,</if>
            <if test="systemCode != null and systemCode != ''">system_code,</if>
            <if test="lang != null and lang != ''">lang,</if>
            <if test="systemLangCode != null">system_lang_code,</if>
            <if test="info != null and info != ''">info,</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="platform != null and platform != ''">#{platform},</if>
            <if test="code != null and code != ''">#{code},</if>
            <if test="key != null and key != ''">#{key},</if>
            <if test="systemCode != null and systemCode != ''">#{systemCode},</if>
            <if test="lang != null and lang != ''">#{lang},</if>
            <if test="systemLangCode != null">#{systemLangCode},</if>
            <if test="info != null and info != ''">#{info},</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="updateGameSecretKey" parameterType="GameSecretKey">
        update ff_game_secret_key
        <trim prefix="SET" suffixOverrides=",">
            <if test="platform != null and platform != ''">platform = #{platform},</if>
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="key != null and key != ''">`key` = #{key},</if>
            <if test="systemCode != null and systemCode != ''">system_code = #{systemCode},</if>
            <if test="lang != null and lang != ''">lang = #{lang},</if>
            <if test="systemLangCode != null">system_lang_code = #{systemLangCode},</if>
            <if test="info != null and info != ''">info = #{info},</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="deleteGameSecretKeyById" parameterType="Long">
        delete from ff_game_secret_key where id = #{id}
    </delete>

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

    <select id="findSystemByCode" resultType="string">
        SELECT system_code
        FROM ff_game_secret_key
        WHERE code = #{code}  and platform = #{platform}
    </select>

    <select id="findSecretKeyByPlatformAndSystemCode" resultType="com.ff.game.domain.GameSecretKey">
        <include refid="selectGameSecretKeyVo"/>
        where  platform = #{platform}  and  system_code = #{systemCode}
    </select>

    <select id="findByPlatformAndSystemLangCode" resultType="com.ff.game.domain.GameSecretKey">
        <include refid="selectGameSecretKeyVo"/>
        where  platform = #{platform}  and  system_lang_code = #{systemLangCode}
    </select>
</mapper>