package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.ScoreRoomUser;
import com.ruoyi.system.domain.ScoreUser;
import com.ruoyi.system.mapper.ScoreRoomUserMapper;
import com.ruoyi.system.mapper.ScoreUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ScoreRoomMapper;
import com.ruoyi.system.domain.ScoreRoom;
import com.ruoyi.system.service.IScoreRoomService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-30
 */
@Service
public class ScoreRoomServiceImpl implements IScoreRoomService 
{
    @Autowired
    private ScoreRoomMapper scoreRoomMapper;
    @Autowired
    private ScoreUserMapper scoreUserMapper;
    @Autowired
    private ScoreRoomUserMapper scoreRoomUserMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param roomId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public ScoreRoom selectScoreRoomByRoomId(Long roomId)
    {
        return scoreRoomMapper.selectScoreRoomByRoomId(roomId);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param scoreRoom 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<ScoreRoom> selectScoreRoomList(ScoreRoom scoreRoom)
    {
        return scoreRoomMapper.selectScoreRoomList(scoreRoom);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param scoreRoom 【请填写功能名称】
     * @return 结果
     */
    @Transactional
    @Override
    public Long insertScoreRoom(ScoreRoom scoreRoom)
    {
        scoreRoomMapper.insertScoreRoom(scoreRoom);
        ScoreRoomUser scoreRoomUser = new ScoreRoomUser();
        ScoreUser scoreUser = scoreUserMapper.selectScoreUserByUserId(scoreRoom.getCreateUser());
        //回填创建房间的主键id
        Long roomId = scoreRoom.getRoomId();
        scoreRoomUser.setRoomId(scoreRoom.getRoomId());
        scoreRoomUser.setUserId(scoreUser.getUserId());
        scoreRoomUser.setScore(0L);
        scoreRoomUser.setPlayerType("business");
        scoreRoomUser.setNickName(scoreUser.getNickName());
        scoreRoomUser.setAvatars(scoreUser.getAvatars());
        scoreRoomUserMapper.insertScoreRoomUser(scoreRoomUser);
         return roomId;
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param scoreRoom 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateScoreRoom(ScoreRoom scoreRoom)
    {
        return scoreRoomMapper.updateScoreRoom(scoreRoom);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param roomIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteScoreRoomByRoomIds(Long[] roomIds)
    {
        return scoreRoomMapper.deleteScoreRoomByRoomIds(roomIds);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param roomId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteScoreRoomByRoomId(Long roomId)
    {
        return scoreRoomMapper.deleteScoreRoomByRoomId(roomId);
    }
}
