<?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.goldenwater.slgc.mapper.PlayerMapper">

    <resultMap type="Player" id="PlayerResult">
        <result property="plyId" column="PLY_ID"/>
        <result property="plyCode" column="PLY_CODE"/>
        <result property="plyName" column="PLY_NAME"/>
        <result property="plyType" column="PLY_TYPE"/>
        <result property="plyUrl" column="PLY_URL"/>
        <result property="viewHeigh" column="VIEW_HEIGH"/>
        <result property="viewWidth" column="VIEW_WIDTH"/>
        <result property="viewCount" column="VIEW_COUNT"/>
        <result property="plyState" column="PLY_STATE"/>
    </resultMap>

    <sql id="selectPlayerVo">
        select PLY_ID, PLY_CODE, PLY_NAME, PLY_TYPE, PLY_URL, VIEW_HEIGH, VIEW_WIDTH,
               VIEW_COUNT, PLY_STATE
        from BIZ_PLAYER
    </sql>

    <select id="selectPlayerList" parameterType="Player" resultMap="PlayerResult">
        <include refid="selectPlayerVo"/>
        <where>
            <if test="plyName != null and plyName != ''">
                and PLY_NAME like concat('%', #{plyName}, '%')
            </if>
            <if test="plyType != null and plyType != ''">
                and PLY_TYPE = #{plyType}
            </if>
            <if test="plyState != null and plyState != ''">
                and PLY_STATE = #{plyState}
            </if>
        </where>
        order by PLY_CODE
    </select>

    <select id="selectAll" resultMap="PlayerResult">
        <include refid="selectPlayerVo"/>
        order by PLY_CODE
    </select>

    <select id="selectPlayerById" parameterType="String" resultMap="PlayerResult">
        <include refid="selectPlayerVo"/>
        where PLY_ID = #{plyId}
    </select>

    <delete id="deletePlayerById" parameterType="String">
        delete from BIZ_PLAYER where PLY_ID = #{plyId}
    </delete>

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

    <insert id="insertPlayer" parameterType="Player">
        insert into BIZ_PLAYER
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="plyId != null">PLY_ID,</if>
            <if test="plyCode != null">PLY_CODE,</if>
            <if test="plyName != null">PLY_NAME,</if>
            <if test="plyType != null">PLY_TYPE,</if>
            <if test="plyUrl != null">PLY_URL,</if>
            <if test="viewHeigh != null">VIEW_HEIGH,</if>
            <if test="viewWidth != null">VIEW_WIDTH,</if>
            <if test="viewCount != null">VIEW_COUNT,</if>
            <if test="plyState != null">PLY_STATE,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="plyId != null">#{plyId},</if>
            <if test="plyCode != null">#{plyCode},</if>
            <if test="plyName != null">#{plyName},</if>
            <if test="plyType != null">#{plyType},</if>
            <if test="plyUrl != null">#{plyUrl},</if>
            <if test="viewHeigh != null">#{viewHeigh},</if>
            <if test="viewWidth != null">#{viewWidth},</if>
            <if test="viewCount != null">#{viewCount},</if>
            <if test="plyState != null">#{plyState},</if>
        </trim>
    </insert>

    <update id="updatePlayer" parameterType="Player">
        update BIZ_PLAYER
        <trim prefix="SET" suffixOverrides=",">
            <if test="plyCode != null">PLY_CODE = #{plyCode},</if>
            <if test="plyName != null">PLY_NAME = #{plyName},</if>
            <if test="plyType != null">PLY_TYPE = #{plyType},</if>
            <if test="plyUrl != null">PLY_URL = #{plyUrl},</if>
            <if test="viewHeigh != null">VIEW_HEIGH = #{viewHeigh},</if>
            <if test="viewWidth != null">VIEW_WIDTH = #{viewWidth},</if>
            <if test="viewCount != null">VIEW_COUNT = #{viewCount},</if>
            <if test="plyState != null">PLY_STATE = #{plyState},</if>
        </trim>
        where PLY_ID = #{plyId}
    </update>

</mapper>
