111
This commit is contained in:
@@ -31,6 +31,10 @@
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.11.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -32,7 +32,10 @@ public class ScoreRoom extends BaseEntity
|
||||
|
||||
/** 房主id */
|
||||
@Excel(name = "房主id")
|
||||
private Long boosId;
|
||||
private Long bossId;
|
||||
|
||||
@Excel(name = "房间名称")
|
||||
private String roomName;
|
||||
|
||||
public void setRoomId(Long roomId)
|
||||
{
|
||||
@@ -74,14 +77,22 @@ public class ScoreRoom extends BaseEntity
|
||||
return roomStatus;
|
||||
}
|
||||
|
||||
public void setBoosId(Long boosId)
|
||||
public void setBossId(Long bossId)
|
||||
{
|
||||
this.boosId = boosId;
|
||||
this.bossId = bossId;
|
||||
}
|
||||
|
||||
public Long getBoosId()
|
||||
public Long getBossId()
|
||||
{
|
||||
return boosId;
|
||||
return bossId;
|
||||
}
|
||||
|
||||
public String getRoomName() {
|
||||
return roomName;
|
||||
}
|
||||
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,7 +102,8 @@ public class ScoreRoom extends BaseEntity
|
||||
.append("createUser", getCreateUser())
|
||||
.append("odds", getOdds())
|
||||
.append("roomStatus", getRoomStatus())
|
||||
.append("boosId", getBoosId())
|
||||
.append("roomName", getRoomName())
|
||||
.append("bossId", getBossId())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ScoreRoomDetail extends BaseEntity
|
||||
|
||||
/** 详情分数 */
|
||||
@Excel(name = "详情分数")
|
||||
private Long score;
|
||||
private Long detailScore;
|
||||
|
||||
/** 触发时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@@ -41,9 +41,17 @@ public class ScoreRoomDetail extends BaseEntity
|
||||
@Excel(name = "0 胜 1 负")
|
||||
private Long detailType;
|
||||
|
||||
/** 目标玩家id 多人模式给分使用 */
|
||||
@Excel(name = "目标玩家id 多人模式给分使用")
|
||||
private Long getterId;
|
||||
/** 局次 */
|
||||
@Excel(name = "局次")
|
||||
private Long gameTime;
|
||||
|
||||
public Long getGameTime() {
|
||||
return gameTime;
|
||||
}
|
||||
|
||||
public void setGameTime(Long gameTime) {
|
||||
this.gameTime = gameTime;
|
||||
}
|
||||
|
||||
public void setDetailId(Long detailId)
|
||||
{
|
||||
@@ -75,16 +83,6 @@ public class ScoreRoomDetail extends BaseEntity
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setScore(Long score)
|
||||
{
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Long getScore()
|
||||
{
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setCreatedTime(Date createdTime)
|
||||
{
|
||||
this.createdTime = createdTime;
|
||||
@@ -105,15 +103,6 @@ public class ScoreRoomDetail extends BaseEntity
|
||||
return detailType;
|
||||
}
|
||||
|
||||
public void setGetterId(Long getterId)
|
||||
{
|
||||
this.getterId = getterId;
|
||||
}
|
||||
|
||||
public Long getGetterId()
|
||||
{
|
||||
return getterId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -121,10 +110,18 @@ public class ScoreRoomDetail extends BaseEntity
|
||||
.append("detailId", getDetailId())
|
||||
.append("roomId", getRoomId())
|
||||
.append("userId", getUserId())
|
||||
.append("score", getScore())
|
||||
.append("detailScore", getDetailScore())
|
||||
.append("createdTime", getCreatedTime())
|
||||
.append("detailType", getDetailType())
|
||||
.append("getterId", getGetterId())
|
||||
.append("gameTime", getGameTime())
|
||||
.toString();
|
||||
}
|
||||
|
||||
public Long getDetailScore() {
|
||||
return detailScore;
|
||||
}
|
||||
|
||||
public void setDetailScore(Long detailScore) {
|
||||
this.detailScore = detailScore;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】对象 score_room_user
|
||||
*
|
||||
@@ -28,7 +30,7 @@ public class ScoreRoomUser extends BaseEntity
|
||||
|
||||
/** 得分 */
|
||||
@Excel(name = "得分")
|
||||
private Long score;
|
||||
private Long totalScore;
|
||||
|
||||
/** 三个值 {'user', 'boot', 'business'} */
|
||||
@Excel(name = "三个值 {'user', 'boot', 'business'}")
|
||||
@@ -42,6 +44,17 @@ public class ScoreRoomUser extends BaseEntity
|
||||
@Excel(name = "玩家头像")
|
||||
private String avatars;
|
||||
|
||||
// 详细对局记录
|
||||
private List<ScoreRoomDetail> details;
|
||||
|
||||
public List<ScoreRoomDetail> getDetails() {
|
||||
return details;
|
||||
}
|
||||
|
||||
public void setDetails(List<ScoreRoomDetail> details) {
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
public void setRoomUserId(Long roomUserId)
|
||||
{
|
||||
this.roomUserId = roomUserId;
|
||||
@@ -72,16 +85,6 @@ public class ScoreRoomUser extends BaseEntity
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setScore(Long score)
|
||||
{
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Long getScore()
|
||||
{
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setPlayerType(String playerType)
|
||||
{
|
||||
this.playerType = playerType;
|
||||
@@ -118,10 +121,19 @@ public class ScoreRoomUser extends BaseEntity
|
||||
.append("roomUserId", getRoomUserId())
|
||||
.append("roomId", getRoomId())
|
||||
.append("userId", getUserId())
|
||||
.append("score", getScore())
|
||||
.append("totalScore", getTotalScore())
|
||||
.append("playerType", getPlayerType())
|
||||
.append("nickName", getNickName())
|
||||
.append("avatars", getAvatars())
|
||||
.append("details", getDetails())
|
||||
.toString();
|
||||
}
|
||||
|
||||
public Long getTotalScore() {
|
||||
return totalScore;
|
||||
}
|
||||
|
||||
public void setTotalScore(Long totalScore) {
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ScoreUser extends BaseEntity
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 用户id */
|
||||
private Long userId;
|
||||
private String userId;
|
||||
|
||||
/** 微信id */
|
||||
@Excel(name = "微信id")
|
||||
@@ -30,12 +30,12 @@ public class ScoreUser extends BaseEntity
|
||||
@Excel(name = "用户头像")
|
||||
private String avatars;
|
||||
|
||||
public void setUserId(Long userId)
|
||||
public void setUserId(String userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
public String getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.ScoreRoomDetail;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】Mapper接口
|
||||
@@ -30,10 +31,10 @@ public interface ScoreRoomDetailMapper
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
* @param scoreRoomDetail 【请填写功能名称】
|
||||
* @param scoreRoomDetails 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertScoreRoomDetail(ScoreRoomDetail scoreRoomDetail);
|
||||
public int insertScoreRoomDetail(@Param("scoreRoomDetails") List<ScoreRoomDetail> scoreRoomDetails);
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
|
||||
@@ -58,4 +58,8 @@ public interface ScoreRoomMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteScoreRoomByRoomIds(Long[] roomIds);
|
||||
|
||||
|
||||
|
||||
public List<ScoreRoom> selectScoreRoomBycreateUser(Long createUser);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.ScoreRoomUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】Mapper接口
|
||||
@@ -19,6 +20,20 @@ public interface ScoreRoomUserMapper
|
||||
*/
|
||||
public ScoreRoomUser selectScoreRoomUserByRoomUserId(Long roomUserId);
|
||||
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
* @param UserId 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
public ScoreRoomUser selectScoreRoomUserByUserId(Long UserId);
|
||||
|
||||
|
||||
|
||||
public ScoreRoomUser selectScoreRoomUserPrescore(@Param("userId") Long UserId, @Param("roomId") Long RoomId);
|
||||
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
@@ -27,6 +42,7 @@ public interface ScoreRoomUserMapper
|
||||
*/
|
||||
public List<ScoreRoomUser> selectScoreRoomUserList(ScoreRoomUser scoreRoomUser);
|
||||
|
||||
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
@@ -35,13 +51,7 @@ public interface ScoreRoomUserMapper
|
||||
*/
|
||||
public int insertScoreRoomUser(ScoreRoomUser scoreRoomUser);
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*
|
||||
* @param scoreRoomUser 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateScoreRoomUser(ScoreRoomUser scoreRoomUser);
|
||||
public int updateScoreRoomUser(@Param("scoreRoomUsers") List<ScoreRoomUser> scoreRoomUsers);
|
||||
|
||||
/**
|
||||
* 删除【请填写功能名称】
|
||||
@@ -58,4 +68,10 @@ public interface ScoreRoomUserMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteScoreRoomUserByRoomUserIds(Long[] roomUserIds);
|
||||
|
||||
/**
|
||||
* 通过JOIN查询获取房间内所有用户及其详细对局记录
|
||||
*/
|
||||
public List<ScoreRoomUser> selectUserScoresWithDetails(Long roomId);
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface ScoreUserMapper
|
||||
* @param userId 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
public ScoreUser selectScoreUserByUserId(Long userId);
|
||||
public ScoreUser selectScoreUserByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
|
||||
@@ -30,10 +30,10 @@ public interface IScoreRoomDetailService
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
* @param scoreRoomDetail 【请填写功能名称】
|
||||
* @param scoreRoomDetails 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertScoreRoomDetail(ScoreRoomDetail scoreRoomDetail);
|
||||
public int insertScoreRoomDetail(List<ScoreRoomDetail> scoreRoomDetails);
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
|
||||
@@ -58,4 +58,5 @@ public interface IScoreRoomService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteScoreRoomByRoomId(Long roomId);
|
||||
public List<ScoreRoom> selectScoreRoomBycreateUser(Long createUser);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.system.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.ScoreRoomUser;
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】Service接口
|
||||
@@ -19,6 +20,16 @@ public interface IScoreRoomUserService
|
||||
*/
|
||||
public ScoreRoomUser selectScoreRoomUserByRoomUserId(Long roomUserId);
|
||||
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
* @param UserId 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
public ScoreRoomUser selectScoreRoomUserByUserId(Long UserId);
|
||||
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
@@ -27,6 +38,13 @@ public interface IScoreRoomUserService
|
||||
*/
|
||||
public List<ScoreRoomUser> selectScoreRoomUserList(ScoreRoomUser scoreRoomUser);
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
* @param roomId 【请填写功能名称】
|
||||
* @return 【请填写功能名称】集合
|
||||
*/
|
||||
public List<ScoreRoomUser> getUserScoresWithDetails(Long roomId);
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
@@ -35,13 +53,8 @@ public interface IScoreRoomUserService
|
||||
*/
|
||||
public int insertScoreRoomUser(ScoreRoomUser scoreRoomUser);
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*
|
||||
* @param scoreRoomUser 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateScoreRoomUser(ScoreRoomUser scoreRoomUser);
|
||||
|
||||
public int updateScoreRoomUser(List<ScoreRoomUser> scoreRoomUsers);
|
||||
|
||||
/**
|
||||
* 批量删除【请填写功能名称】
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface IScoreUserService
|
||||
* @param userId 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
public ScoreUser selectScoreUserByUserId(Long userId);
|
||||
public ScoreUser selectScoreUserByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
@@ -33,8 +33,7 @@ public interface IScoreUserService
|
||||
* @param scoreUser 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertScoreUser(ScoreUser scoreUser);
|
||||
|
||||
public ScoreUser insertScoreUser(ScoreUser scoreUser);
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*
|
||||
|
||||
@@ -46,13 +46,13 @@ public class ScoreRoomDetailServiceImpl implements IScoreRoomDetailService
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
* @param scoreRoomDetail 【请填写功能名称】
|
||||
* @param scoreRoomDetails 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertScoreRoomDetail(ScoreRoomDetail scoreRoomDetail)
|
||||
public int insertScoreRoomDetail(List<ScoreRoomDetail> scoreRoomDetails)
|
||||
{
|
||||
return scoreRoomDetailMapper.insertScoreRoomDetail(scoreRoomDetail);
|
||||
return scoreRoomDetailMapper.insertScoreRoomDetail(scoreRoomDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,18 @@ public class ScoreRoomServiceImpl implements IScoreRoomService
|
||||
return scoreRoomMapper.selectScoreRoomByRoomId(roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
* @param createUser 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
@Override
|
||||
public List<ScoreRoom> selectScoreRoomBycreateUser(Long createUser)
|
||||
{
|
||||
return scoreRoomMapper.selectScoreRoomBycreateUser(createUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
@@ -52,6 +64,8 @@ public class ScoreRoomServiceImpl implements IScoreRoomService
|
||||
@Override
|
||||
public int insertScoreRoom(ScoreRoom scoreRoom)
|
||||
{
|
||||
// List<ScoreRoom> newRoom = scoreRoomMapper.selectScoreRoomList(scoreRoom);
|
||||
|
||||
return scoreRoomMapper.insertScoreRoom(scoreRoom);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.system.mapper.ScoreRoomUserMapper;
|
||||
@@ -31,6 +35,20 @@ public class ScoreRoomUserServiceImpl implements IScoreRoomUserService
|
||||
return scoreRoomUserMapper.selectScoreRoomUserByRoomUserId(roomUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
* @param UserId 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
@Override
|
||||
public ScoreRoomUser selectScoreRoomUserByUserId(Long UserId)
|
||||
{
|
||||
return scoreRoomUserMapper.selectScoreRoomUserByUserId(UserId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
@@ -43,6 +61,17 @@ public class ScoreRoomUserServiceImpl implements IScoreRoomUserService
|
||||
return scoreRoomUserMapper.selectScoreRoomUserList(scoreRoomUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
* @param roomId 【请填写功能名称】
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
@Override
|
||||
public List<ScoreRoomUser> getUserScoresWithDetails(Long roomId) {
|
||||
return scoreRoomUserMapper.selectUserScoresWithDetails(roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
@@ -55,16 +84,53 @@ public class ScoreRoomUserServiceImpl implements IScoreRoomUserService
|
||||
return scoreRoomUserMapper.insertScoreRoomUser(scoreRoomUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*
|
||||
* @param scoreRoomUser 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
|
||||
@Override
|
||||
public int updateScoreRoomUser(ScoreRoomUser scoreRoomUser)
|
||||
public int updateScoreRoomUser(List<ScoreRoomUser> scoreRoomUsers)
|
||||
{
|
||||
return scoreRoomUserMapper.updateScoreRoomUser(scoreRoomUser);
|
||||
List<ScoreRoomUser> updatedUsers = new ArrayList<>();
|
||||
|
||||
for (ScoreRoomUser playerScore: scoreRoomUsers){
|
||||
// 处理单个用户的得分累加
|
||||
ScoreRoomUser updatedUser = processUserScoreUpdate(playerScore);
|
||||
updatedUsers.add(updatedUser);
|
||||
}
|
||||
|
||||
return scoreRoomUserMapper.updateScoreRoomUser(updatedUsers);
|
||||
}
|
||||
|
||||
private ScoreRoomUser processUserScoreUpdate(ScoreRoomUser newScore) {
|
||||
// 1. 首先检查用户是否已在房间中
|
||||
ScoreRoomUser existingUser = scoreRoomUserMapper.selectScoreRoomUserPrescore(newScore.getUserId(), newScore.getRoomId());
|
||||
|
||||
Long newTotalScore;
|
||||
ScoreRoomUser userToUpdate;
|
||||
|
||||
if (existingUser == null) {
|
||||
// 用户不在房间中,创建新记录
|
||||
userToUpdate = new ScoreRoomUser();
|
||||
userToUpdate.setRoomId(newScore.getRoomId());
|
||||
userToUpdate.setUserId(newScore.getUserId());
|
||||
userToUpdate.setPlayerType("user");
|
||||
userToUpdate.setNickName(newScore.getNickName());
|
||||
userToUpdate.setTotalScore(newScore.getTotalScore() != null ? newScore.getTotalScore() : 0L);
|
||||
|
||||
// 插入新记录
|
||||
scoreRoomUserMapper.insertScoreRoomUser(userToUpdate);
|
||||
return userToUpdate;
|
||||
} else {
|
||||
// 2. 存在记录:历史总分 + 本次得分
|
||||
Long currentScore = existingUser.getTotalScore() != null ? existingUser.getTotalScore() : 0L;
|
||||
Long additionalScore = newScore.getTotalScore() != null ? newScore.getTotalScore() : 0L;
|
||||
|
||||
newTotalScore = currentScore + additionalScore;
|
||||
|
||||
// 使用现有记录进行更新
|
||||
userToUpdate = existingUser;
|
||||
userToUpdate.setTotalScore(newTotalScore);
|
||||
|
||||
return userToUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,4 +156,7 @@ public class ScoreRoomUserServiceImpl implements IScoreRoomUserService
|
||||
{
|
||||
return scoreRoomUserMapper.deleteScoreRoomUserByRoomUserId(roomUserId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ScoreUserServiceImpl implements IScoreUserService
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
@Override
|
||||
public ScoreUser selectScoreUserByUserId(Long userId)
|
||||
public ScoreUser selectScoreUserByUserId(String userId)
|
||||
{
|
||||
return scoreUserMapper.selectScoreUserByUserId(userId);
|
||||
}
|
||||
@@ -51,16 +51,23 @@ public class ScoreUserServiceImpl implements IScoreUserService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertScoreUser(ScoreUser scoreUser)
|
||||
public ScoreUser insertScoreUser(ScoreUser scoreUser)
|
||||
{
|
||||
// 判断当前openId是否已经有值了
|
||||
ScoreUser scoreUser1 = scoreUserMapper.selectScoreUserByOpenId(scoreUser.getOpenId());
|
||||
if(scoreUser1 != null) {
|
||||
return 1;
|
||||
throw new RuntimeException("当前openId是否已经有值");
|
||||
}
|
||||
|
||||
scoreUser.setCreateTime(DateUtils.getNowDate());
|
||||
return scoreUserMapper.insertScoreUser(scoreUser);
|
||||
// 插入用户,MyBatis会自动将自增ID设置到user对象的userId属性中
|
||||
int result = scoreUserMapper.insertScoreUser(scoreUser);
|
||||
|
||||
if (result > 0) {
|
||||
// 返回包含自增ID的用户对象
|
||||
return scoreUser;
|
||||
} else {
|
||||
throw new RuntimeException("用户插入失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,26 +35,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
where detail_id = #{detailId}
|
||||
</select>
|
||||
|
||||
<insert id="insertScoreRoomDetail" parameterType="ScoreRoomDetail" useGeneratedKeys="true" keyProperty="detailId">
|
||||
insert into score_room_detail
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="roomId != null">room_id,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="score != null">score,</if>
|
||||
<if test="createdTime != null">created_time,</if>
|
||||
<if test="detailType != null">detail_type,</if>
|
||||
<if test="getterId != null">getter_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="roomId != null">#{roomId},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="score != null">#{score},</if>
|
||||
<if test="createdTime != null">#{createdTime},</if>
|
||||
<if test="detailType != null">#{detailType},</if>
|
||||
<if test="getterId != null">#{getterId},</if>
|
||||
</trim>
|
||||
|
||||
|
||||
<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=",">
|
||||
|
||||
@@ -9,11 +9,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="createUser" column="create_user" />
|
||||
<result property="odds" column="odds" />
|
||||
<result property="roomStatus" column="room_status" />
|
||||
<result property="boosId" column="boos_id" />
|
||||
<result property="bossId" column="boss_id" />
|
||||
<result property="roomName" column="room_name" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectScoreRoomVo">
|
||||
select room_id, create_user, odds, room_status, boos_id from score_room
|
||||
select room_id, create_user, odds, room_status, boss_id from score_room
|
||||
</sql>
|
||||
|
||||
<select id="selectScoreRoomList" parameterType="ScoreRoom" resultMap="ScoreRoomResult">
|
||||
@@ -22,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<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="boosId != null "> and boos_id = #{boosId}</if>
|
||||
<if test="bossId != null "> and boss_id = #{bossId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@@ -31,19 +32,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
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="boosId != null">boos_id,</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="boosId != null">#{boosId},</if>
|
||||
<if test="bossId != null">#{bossId},</if>
|
||||
<if test="roomName != null">#{roomName},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@@ -53,7 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<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="boosId != null">boos_id = #{boosId},</if>
|
||||
<if test="bossId != null">boss_id = #{bossId},</if>
|
||||
</trim>
|
||||
where room_id = #{roomId}
|
||||
</update>
|
||||
|
||||
@@ -8,7 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="roomUserId" column="room_user_id" />
|
||||
<result property="roomId" column="room_id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="score" column="score" />
|
||||
<result property="totalScore" column="score" />
|
||||
<result property="playerType" column="player_type" />
|
||||
<result property="nickName" column="nick_name" />
|
||||
<result property="avatars" column="avatars" />
|
||||
@@ -23,49 +23,65 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<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="playerType != null and playerType != ''"> and player_type = #{playerType}</if>
|
||||
<if test="nickName != null and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
|
||||
<if test="avatars != null and avatars != ''"> and avatars = #{avatars}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectScoreRoomUserByRoomUserId" parameterType="Long" resultMap="ScoreRoomUserResult">
|
||||
<include refid="selectScoreRoomUserVo"/>
|
||||
where room_user_id = #{roomUserId}
|
||||
</select>
|
||||
|
||||
<select id="selectScoreRoomUserPrescore" resultMap="ScoreRoomUserResult">
|
||||
select room_id, user_id, score from score_room_user
|
||||
where room_id = #{roomId} AND user_id = #{userId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectScoreRoomUserByUserId" parameterType="Long" resultMap="ScoreRoomUserResult">
|
||||
<include refid="selectScoreRoomUserVo"/>
|
||||
where user_id = #{UserId}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<insert id="insertScoreRoomUser" parameterType="ScoreRoomUser" useGeneratedKeys="true" keyProperty="roomUserId">
|
||||
insert into score_room_user
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="roomId != null">room_id,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="score != null">score,</if>
|
||||
<if test="totalScore != null">score,</if>
|
||||
<if test="playerType != null">player_type,</if>
|
||||
<if test="nickName != null">nick_name,</if>
|
||||
<if test="avatars != null">avatars,</if>
|
||||
</trim>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="roomId != null">#{roomId},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="score != null">#{score},</if>
|
||||
<if test="totalScore != null">#{totalScore},</if>
|
||||
<if test="playerType != null">#{playerType},</if>
|
||||
<if test="nickName != null">#{nickName},</if>
|
||||
<if test="avatars != null">#{avatars},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateScoreRoomUser" parameterType="ScoreRoomUser">
|
||||
update score_room_user
|
||||
<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="playerType != null">player_type = #{playerType},</if>
|
||||
<if test="nickName != null">nick_name = #{nickName},</if>
|
||||
<if test="avatars != null">avatars = #{avatars},</if>
|
||||
</trim>
|
||||
where room_user_id = #{roomUserId}
|
||||
<update id="updateScoreRoomUser">
|
||||
UPDATE score_room_user
|
||||
SET
|
||||
score = CASE
|
||||
<foreach collection="scoreRoomUsers" item="item">
|
||||
WHEN room_id = #{item.roomId} AND user_id = #{item.userId} THEN #{item.totalScore}
|
||||
</foreach>
|
||||
ELSE score
|
||||
END
|
||||
<!-- 如果需要更新其他字段,可以继续添加类似的CASE WHEN结构 -->
|
||||
WHERE (room_id, user_id) IN
|
||||
<foreach collection="scoreRoomUsers" item="item" separator="," open="(" close=")">
|
||||
(#{item.roomId}, #{item.userId})
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<delete id="deleteScoreRoomUserByRoomUserId" parameterType="Long">
|
||||
@@ -78,4 +94,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{roomUserId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<resultMap id="UserScoreDetailResultMap" type="ScoreRoomUser">
|
||||
<!-- 主用户信息映射 -->
|
||||
<id property="userId" column="user_id"/>
|
||||
<result property="nickName" column="nick_name"/>
|
||||
<result property="avatars" column="avatars"/>
|
||||
<result property="totalScore" column="score"/>
|
||||
<result property="roomId" column="room_id" />
|
||||
<!-- 详细对局记录映射 -->
|
||||
<collection property="details" ofType="ScoreRoomDetail">
|
||||
<result property="gameTime" column="game_time"/>
|
||||
<result property="detailScore" column="detail_score"/>
|
||||
<result property="createdTime" column="created_time"/>
|
||||
<result property="roomId" column="room_id" />
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectUserScoresWithDetails" parameterType="Long" resultMap="UserScoreDetailResultMap">
|
||||
SELECT
|
||||
sru.user_id,
|
||||
sru.room_id,
|
||||
sru.nick_name,
|
||||
sru.avatars,
|
||||
sru.score,
|
||||
srd.game_time,
|
||||
srd.detail_score,
|
||||
srd.created_time
|
||||
FROM score_room_user sru
|
||||
LEFT JOIN score_room_detail srd ON sru.room_id = srd.room_id AND sru.user_id = srd.user_id
|
||||
WHERE sru.room_id = #{roomId}
|
||||
ORDER BY srd.game_time
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -26,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectScoreUserByUserId" parameterType="Long" resultMap="ScoreUserResult">
|
||||
<select id="selectScoreUserByUserId" resultMap="ScoreUserResult">
|
||||
<include refid="selectScoreUserVo"/>
|
||||
where user_id = #{userId}
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user