<?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.GamePlatformMapper">
    
    <resultMap type="GamePlatform" id="GamePlatformResult">
        <result property="id"    column="id"    />
        <result property="sortNo"    column="sort_no"    />
        <result property="platformCode"    column="platform_code"    />
        <result property="platformType"    column="platform_type"    />
        <result property="platformName"    column="platform_name"    />
        <result property="stopStatus"    column="stop_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="selectGamePlatformVo">
        select id, sort_no, platform_code, platform_type, platform_name, stop_status, create_by, create_time, update_by, update_time from ff_game_platform
    </sql>

    <select id="selectGamePlatformList" parameterType="GamePlatform" resultMap="GamePlatformResult">
        <include refid="selectGamePlatformVo"/>
        <where>  
            <if test="sortNo != null "> and sort_no = #{sortNo}</if>
            <if test="platformCode != null  and platformCode != ''"> and platform_code = #{platformCode}</if>
            <if test="platformType != null "> and platform_type = #{platformType}</if>
            <if test="platformName != null  and platformName != ''"> and platform_name like concat('%', #{platformName}, '%')</if>
            <if test="stopStatus != null "> and stop_status = #{stopStatus}</if>
        </where>
    </select>
    
    <select id="selectGamePlatformById" parameterType="Long" resultMap="GamePlatformResult">
        <include refid="selectGamePlatformVo"/>
        where id = #{id}
    </select>

    <insert id="insertGamePlatform" parameterType="GamePlatform" useGeneratedKeys="true" keyProperty="id">
        insert into ff_game_platform
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sortNo != null">sort_no,</if>
            <if test="platformCode != null">platform_code,</if>
            <if test="platformType != null">platform_type,</if>
            <if test="platformName != null">platform_name,</if>
            <if test="stopStatus != null">stop_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="sortNo != null">#{sortNo},</if>
            <if test="platformCode != null">#{platformCode},</if>
            <if test="platformType != null">#{platformType},</if>
            <if test="platformName != null">#{platformName},</if>
            <if test="stopStatus != null">#{stopStatus},</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="updateGamePlatform" parameterType="GamePlatform">
        update ff_game_platform
        <trim prefix="SET" suffixOverrides=",">
            <if test="sortNo != null">sort_no = #{sortNo},</if>
            <if test="platformCode != null">platform_code = #{platformCode},</if>
            <if test="platformType != null">platform_type = #{platformType},</if>
            <if test="platformName != null">platform_name = #{platformName},</if>
            <if test="stopStatus != null">stop_status = #{stopStatus},</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="deleteGamePlatformById" parameterType="Long">
        delete from ff_game_platform where id = #{id}
    </delete>

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

    <select id="selectMaxSortNo"  resultType="java.lang.Integer">

        select ifnull(max(sort_no),0)
        from ff_game_platform

    </select>
</mapper>