<?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.ruoyi.system.mapper.ScoreRoomMapper">
    
    <resultMap type="ScoreRoom" id="ScoreRoomResult">
        <result property="roomId"    column="room_id"    />
        <result property="createUser"    column="create_user"    />
        <result property="odds"    column="odds"    />
        <result property="roomStatus"    column="room_status"    />
        <result property="bossId"    column="boss_id"    />
        <result property="roomName"    column="room_name"    />
    </resultMap>

    <sql id="selectScoreRoomVo">
        select room_id, create_user, odds, room_status, boss_id from score_room
    </sql>

    <select id="selectScoreRoomList" parameterType="ScoreRoom" resultMap="ScoreRoomResult">
        <include refid="selectScoreRoomVo"/>
        <where>  
            <if test="createUser != null "> and create_user = #{createUser}</if>
            <if test="odds != null "> and odds = #{odds}</if>
            <if test="roomStatus != null "> and room_status = #{roomStatus}</if>
            <if test="bossId != null "> and boss_id = #{bossId}</if>
        </where>
    </select>
    
    <select id="selectScoreRoomByRoomId" parameterType="Long" resultMap="ScoreRoomResult">
        <include refid="selectScoreRoomVo"/>
        where room_id = #{roomId}
    </select>

    <select id="selectScoreRoomBycreateUser" parameterType="Long" resultMap="ScoreRoomResult">
        <include refid="selectScoreRoomVo"/>
        WHERE room_status IN (0, 1)
        AND create_user = #{createUser}
    </select>

    <insert id="insertScoreRoom" parameterType="ScoreRoom" useGeneratedKeys="true" keyProperty="roomId">
        insert into score_room
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="createUser != null">create_user,</if>
            <if test="odds != null">odds,</if>
            <if test="roomStatus != null">room_status,</if>
            <if test="bossId != null">boss_id,</if>
            <if test="roomName != null">room_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="createUser != null">#{createUser},</if>
            <if test="odds != null">#{odds},</if>
            <if test="roomStatus != null">#{roomStatus},</if>
            <if test="bossId != null">#{bossId},</if>
            <if test="roomName != null">#{roomName},</if>
         </trim>
    </insert>

    <update id="updateScoreRoom" parameterType="ScoreRoom">
        update score_room
        <trim prefix="SET" suffixOverrides=",">
            <if test="createUser != null">create_user = #{createUser},</if>
            <if test="odds != null">odds = #{odds},</if>
            <if test="roomStatus != null">room_status = #{roomStatus},</if>
            <if test="bossId != null">boss_id = #{bossId},</if>
        </trim>
        where room_id = #{roomId}
    </update>

    <delete id="deleteScoreRoomByRoomId" parameterType="Long">
        delete from score_room where room_id = #{roomId}
    </delete>

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