游戏新增gameInfo字段

This commit is contained in:
tianfeng 2026-03-11 15:51:35 +08:00
parent fcbed65ae5
commit 732c3d180b
4 changed files with 60 additions and 10 deletions

View File

@ -1,15 +1,13 @@
package com.red.circle.other.app.command.game.ludo;
import com.red.circle.component.redis.service.RedisService;
import com.red.circle.external.inner.endpoint.message.ImGroupClient;
import com.red.circle.external.inner.model.cmd.message.BroadcastGroupMsgBodyCmd;
import com.red.circle.external.inner.model.enums.message.GroupMessageTypeEnum;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.response.CommonErrorCode;
import com.red.circle.framework.web.props.EnvProperties;
import com.red.circle.other.app.convertor.game.GameLudoAppConvertor;
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
import com.red.circle.other.app.dto.clientobject.game.GameLudoRunCO;
import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig;
import com.red.circle.other.app.dto.cmd.game.GameLudoCreateCmd;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.infra.database.cache.service.other.GameCacheService;
@ -20,6 +18,7 @@ import com.red.circle.other.infra.database.mongo.entity.game.ludo.GameStatus;
import com.red.circle.other.infra.database.mongo.entity.game.ludo.GameStatusEvent;
import com.red.circle.other.infra.database.mongo.service.game.GameLudoRunService;
import com.red.circle.other.infra.database.rds.service.live.RoomMemberService;
import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService;
import com.red.circle.other.inner.asserts.GameErrorCode;
import com.red.circle.other.inner.asserts.user.UserErrorCode;
import com.red.circle.other.inner.enums.live.RoomUserRolesEnum;
@ -47,7 +46,6 @@ public class GameLudoCreateCmdExe {
private final RedisService redisService;
private final EnvProperties envProperties;
private final ImGroupClient imGroupClient;
private final WalletGoldClient walletGoldClient;
private final GameCacheService gameCacheService;
private final RoomMemberService roomMemberService;
@ -55,6 +53,7 @@ public class GameLudoCreateCmdExe {
private final GameLudoRunService gameLudoRunService;
private final GameLudoAppConvertor gameLudoAppConvertor;
private final UserProfileAppConvertor userProfileAppConvertor;
private final GameListConfigService gameListConfigService;
public GameLudoRunCO execute(GameLudoCreateCmd cmd) {
@ -76,15 +75,14 @@ public class GameLudoCreateCmdExe {
ResponseAssert.isFalse(GameErrorCode.GAME_CREATED,
gameLudoRunService.exists(cmd.getRoomId()));
gameLudoRun = createGameLudoRun(cmd);
GameListConfig gameListConfig = gameListConfigService.getById(cmd.getGameId());
ResponseAssert.notNull(GameErrorCode.GAME_NOT_EXIST, gameListConfig);
gameLudoRun = createGameLudoRun(cmd, gameListConfig);
ResponseAssert.isTrue(GameErrorCode.GAME_CREATED, gameLudoRunService.create(gameLudoRun));
gameCacheService.inrJoinNumberPeopleLudo(gameLudoRun.getId());
gameCacheService.setJoinGameLudo(gameLudoRun.getId(), gameLudoRun.getUserId());
imGroupClient
.sendMessageBroadcast(
BroadcastGroupMsgBodyCmd.builder().type(GroupMessageTypeEnum.CREATE_GAME_LUDO)
.data(gameLudoRun.getId()).toPlatform(cmd.requireReqSysOriginEnum()).build());
} finally {
redisService.unlock(lockKey(cmd));
}
@ -95,16 +93,24 @@ public class GameLudoCreateCmdExe {
return "CREATE_LUDO".concat(cmd.getRoomId().toString());
}
private GameLudoRun createGameLudoRun(GameLudoCreateCmd cmd) {
private GameLudoRun createGameLudoRun(GameLudoCreateCmd cmd, GameListConfig config) {
BigDecimal consumeAmount = consumeAmount(cmd);
UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO(
userProfileGateway.getByUserId(cmd.getHomeownerUserId()));
ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, userProfile);
GameLudoRun.GameInfo gameInfo = new GameLudoRun.GameInfo();
gameInfo.setId(config.getId());
gameInfo.setGameId(config.getGameId());
gameInfo.setName(config.getName());
gameInfo.setGameCode(config.getGameCode());
gameInfo.setCover(config.getCover());
return new GameLudoRun()
.setId(cmd.getRoomId())
.setSysOrigin(cmd.getReqSysOrigin().getOrigin())
.setRoomId(cmd.getRoomId())
.setUserId(cmd.getHomeownerUserId())
.setGameId(cmd.getGameId())
.setGameInfo(gameInfo)
.setGameStatus(GameStatus.WAIT)
.setGameStatusEvent(GameStatusEvent.NONE)
.setJoinAmount(cmd.getAmount())

View File

@ -79,5 +79,24 @@ public class GameLudoRunCO extends ClientObject {
*/
private Timestamp createTime;
/**
* 游戏信息.
*/
private GameInfo gameInfo;
@Data
public static class GameInfo {
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private String gameId;
private String name;
private String gameCode;
private String cover;
}
}

View File

@ -40,6 +40,11 @@ public class GameLudoCreateCmd extends AppExtCommand {
@NotNull(message = "localSeat required.")
private String localSeat;
/**
* 游戏ID
*/
private Long gameId;
/**
* 房主id.
*

View File

@ -50,6 +50,26 @@ public class GameLudoRun implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long userId;
/**
* 游戏ID(游戏列表的ID)
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long gameId;
/**
* 游戏信息快照.
*/
private GameInfo gameInfo;
@Data
public static class GameInfo {
private Long id;
private String gameId;
private String name;
private String gameCode;
private String cover;
}
/**
* 游戏状态.
*/