diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/GameLudoAppRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/GameLudoAppRestController.java index 2ee51a30..d1cd266c 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/GameLudoAppRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/GameLudoAppRestController.java @@ -1,6 +1,6 @@ package com.red.circle.other.adapter.app.game; -import com.red.circle.common.business.dto.cmd.AppExtCommand; +import com.red.circle.other.app.dto.cmd.game.GamePlayHistoryQryCmd; import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd; import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; @@ -190,8 +190,8 @@ public class GameLudoAppRestController { * @eo.request-type formdata */ @GetMapping("/history/recent") - public List listRecentHistory(@Validated AppExtCommand cmd) { - return gamePlayHistoryService.listRecent(cmd.requireReqSysOrigin(), cmd.requiredReqUserId()); + public List listRecentHistory(@Validated GamePlayHistoryQryCmd cmd) { + return gamePlayHistoryService.listRecent(cmd.requireReqSysOrigin(), cmd.requiredReqUserId(), cmd.getScene()); } } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/GamePlayHistoryQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/GamePlayHistoryQryExe.java index 58345d10..810518ed 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/GamePlayHistoryQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/GamePlayHistoryQryExe.java @@ -22,9 +22,9 @@ public class GamePlayHistoryQryExe { private final UserGamePlayHistoryService userGamePlayHistoryService; - public List execute(String sysOrigin, Long userId) { + public List execute(String sysOrigin, Long userId, String scene) { List historyList = - userGamePlayHistoryService.listRecent(sysOrigin, userId, RECENT_LIMIT); + userGamePlayHistoryService.listRecent(sysOrigin, userId, scene, RECENT_LIMIT); return historyList.stream() .filter(h -> Objects.nonNull(h.getGameInfo())) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/GamePlayHistoryRecordCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/GamePlayHistoryRecordCmdExe.java index 3c16a627..18233141 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/GamePlayHistoryRecordCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/GamePlayHistoryRecordCmdExe.java @@ -44,6 +44,7 @@ public class GamePlayHistoryRecordCmdExe { history.setSysOrigin(cmd.getReqSysOrigin().getOrigin()); history.setUserId(cmd.requiredReqUserId()); history.setGameListConfigId(cmd.getGameListConfigId()); + history.setScene(cmd.getScene()); history.setGameInfo(gameInfo); history.setPlayTime(TimestampUtils.now()); history.setExpiredTime(TimestampUtils.nowPlusDays(90)); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GamePlayHistoryServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GamePlayHistoryServiceImpl.java index 29e9dcc4..80a299da 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GamePlayHistoryServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GamePlayHistoryServiceImpl.java @@ -24,7 +24,7 @@ public class GamePlayHistoryServiceImpl implements GamePlayHistoryService { } @Override - public List listRecent(String sysOrigin, Long userId) { - return gamePlayHistoryQryExe.execute(sysOrigin, userId); + public List listRecent(String sysOrigin, Long userId, String scene) { + return gamePlayHistoryQryExe.execute(sysOrigin, userId, scene); } } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/game/GamePlayHistoryQryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/game/GamePlayHistoryQryCmd.java new file mode 100644 index 00000000..e67d8ca3 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/game/GamePlayHistoryQryCmd.java @@ -0,0 +1,20 @@ +package com.red.circle.other.app.dto.cmd.game; + +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 查询最近游玩历史. + * + * @author tf + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class GamePlayHistoryQryCmd extends AppExtCommand { + + /** 场景:IN_ROOM / OUT_ROOM */ + @NotNull(message = "scene required.") + private String scene; +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/game/GamePlayHistoryRecordCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/game/GamePlayHistoryRecordCmd.java index 2f980e2b..b5135517 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/game/GamePlayHistoryRecordCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/game/GamePlayHistoryRecordCmd.java @@ -17,4 +17,8 @@ public class GamePlayHistoryRecordCmd extends AppExtCommand { /** GameListConfig 主键 */ @NotNull(message = "gameListConfigId required.") private Long gameListConfigId; + + /** 场景:IN_ROOM / OUT_ROOM */ + @NotNull(message = "scene required.") + private String scene; } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/game/GamePlayHistoryService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/game/GamePlayHistoryService.java index d87c65a1..ccfe24d2 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/game/GamePlayHistoryService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/game/GamePlayHistoryService.java @@ -13,5 +13,5 @@ public interface GamePlayHistoryService { void record(GamePlayHistoryRecordCmd cmd); - List listRecent(String sysOrigin, Long userId); + List listRecent(String sysOrigin, Long userId, String scene); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/game/UserGamePlayHistory.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/game/UserGamePlayHistory.java index d5e02526..8168d0a9 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/game/UserGamePlayHistory.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/game/UserGamePlayHistory.java @@ -22,7 +22,7 @@ import org.springframework.data.mongodb.core.mapping.Document; @Document("user_game_play_history") @CompoundIndexes({ @CompoundIndex(name = "idx_user_play_time", def = "{'userId': 1, 'playTime': -1}"), - @CompoundIndex(name = "idx_user_game", def = "{'userId': 1, 'gameListConfigId': 1}", unique = true) + @CompoundIndex(name = "idx_user_game_scene", def = "{'userId': 1, 'gameListConfigId': 1, 'scene': 1}", unique = true) }) public class UserGamePlayHistory implements Serializable { @@ -45,6 +45,9 @@ public class UserGamePlayHistory implements Serializable { @Indexed private Timestamp playTime; + /** 场景:IN_ROOM / OUT_ROOM */ + private String scene; + /** 过期时间,90天TTL自动清理 */ @Indexed(expireAfterSeconds = 0) private Timestamp expiredTime; diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/UserGamePlayHistoryService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/UserGamePlayHistoryService.java index f8faaea5..f1c953dc 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/UserGamePlayHistoryService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/UserGamePlayHistoryService.java @@ -11,12 +11,12 @@ import java.util.List; public interface UserGamePlayHistoryService { /** - * 记录游玩(同一用户同一游戏 upsert,仅更新 playTime 和快照). + * 记录游玩(同一用户同一游戏同一场景 upsert,仅更新 playTime 和快照). */ void record(UserGamePlayHistory history); /** * 查询用户最近游玩的游戏,按 playTime 倒序,最多 limit 条. */ - List listRecent(String sysOrigin, Long userId, int limit); + List listRecent(String sysOrigin, Long userId, String scene, int limit); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/impl/UserGamePlayHistoryServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/impl/UserGamePlayHistoryServiceImpl.java index 452021f7..e0d6c16a 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/impl/UserGamePlayHistoryServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/impl/UserGamePlayHistoryServiceImpl.java @@ -26,6 +26,7 @@ public class UserGamePlayHistoryServiceImpl implements UserGamePlayHistoryServic Query query = Query.query( Criteria.where("userId").is(history.getUserId()) .and("gameListConfigId").is(history.getGameListConfigId()) + .and("scene").is(history.getScene()) ); Update update = new Update() .set("gameInfo", history.getGameInfo()) @@ -34,14 +35,15 @@ public class UserGamePlayHistoryServiceImpl implements UserGamePlayHistoryServic .setOnInsert("id", String.valueOf(IdWorkerUtils.getId())) .setOnInsert("sysOrigin", history.getSysOrigin()) .setOnInsert("userId", history.getUserId()) - .setOnInsert("gameListConfigId", history.getGameListConfigId()); + .setOnInsert("gameListConfigId", history.getGameListConfigId()) + .setOnInsert("scene", history.getScene()); mongoTemplate.upsert(query, update, UserGamePlayHistory.class); } @Override - public List listRecent(String sysOrigin, Long userId, int limit) { + public List listRecent(String sysOrigin, Long userId, String scene, int limit) { return mongoTemplate.find( - Query.query(Criteria.where("sysOrigin").is(sysOrigin).and("userId").is(userId)) + Query.query(Criteria.where("sysOrigin").is(sysOrigin).and("userId").is(userId).and("scene").is(scene)) .with(Sort.by(Sort.Order.desc("playTime"))) .limit(limit), UserGamePlayHistory.class);