<?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.ScoreRoomDetailMapper">
    
    <resultMap type="ScoreRoomDetail" id="ScoreRoomDetailResult">
        <result property="detailId"    column="detail_id"    />
        <result property="roomId"    column="room_id"    />
        <result property="userId"    column="user_id"    />
        <result property="score"    column="score"    />
        <result property="createdTime"    column="created_time"    />
        <result property="detailType"    column="detail_type"    />
        <result property="getterId"    column="getter_id"    />
    </resultMap>

    <sql id="selectScoreRoomDetailVo">
        select detail_id, room_id, user_id, score, created_time, detail_type, getter_id from score_room_detail
    </sql>

    <select id="selectScoreRoomDetailList" parameterType="ScoreRoomDetail" resultMap="ScoreRoomDetailResult">
        <include refid="selectScoreRoomDetailVo"/>
        <where>  
            <if test="roomId != null "> and room_id = #{roomId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="score != null "> and score = #{score}</if>
            <if test="createdTime != null "> and created_time = #{createdTime}</if>
            <if test="detailType != null "> and detail_type = #{detailType}</if>
            <if test="getterId != null "> and getter_id = #{getterId}</if>
        </where>
    </select>
    
    <select id="selectScoreRoomDetailByDetailId" parameterType="Long" resultMap="ScoreRoomDetailResult">
        <include refid="selectScoreRoomDetailVo"/>
        where detail_id = #{detailId}
    </select>



    <insert id="insertScoreRoomDetail" useGeneratedKeys="true" keyProperty="detailId">
        INSERT INTO score_room_detail
        (room_id, user_id, detail_score, game_time, created_time, detail_type)
        VALUES
        <foreach collection="scoreRoomDetails" item="item" separator=",">
            (
            #{item.roomId},
            #{item.userId},
            #{item.detailScore},
            #{item.gameTime},
            NOW(),
            0
            )
        </foreach>
    </insert>


    <update id="updateScoreRoomDetail" parameterType="ScoreRoomDetail">
        update score_room_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="roomId != null">room_id = #{roomId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="score != null">score = #{score},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="detailType != null">detail_type = #{detailType},</if>
            <if test="getterId != null">getter_id = #{getterId},</if>
        </trim>
        where detail_id = #{detailId}
    </update>

    <delete id="deleteScoreRoomDetailByDetailId" parameterType="Long">
        delete from score_room_detail where detail_id = #{detailId}
    </delete>

    <delete id="deleteScoreRoomDetailByDetailIds" parameterType="String">
        delete from score_room_detail where detail_id in 
        <foreach item="detailId" collection="array" open="(" separator="," close=")">
            #{detailId}
        </foreach>
    </delete>
</mapper>