From e2e76142163e93c7b682376a499c72ff27a48f70 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 12 Mar 2026 10:13:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=B0=E5=BD=95=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B8=B8=E7=8E=A9=E8=AE=B0=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/UserGamePlayHistoryServiceImpl.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) 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 0aebcebc..452021f7 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 @@ -2,7 +2,6 @@ package com.red.circle.other.infra.database.mongo.service.game.impl; import com.red.circle.other.infra.database.mongo.entity.game.UserGamePlayHistory; import com.red.circle.other.infra.database.mongo.service.game.UserGamePlayHistoryService; -import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.sequence.IdWorkerUtils; import java.util.List; import lombok.RequiredArgsConstructor; @@ -28,21 +27,15 @@ public class UserGamePlayHistoryServiceImpl implements UserGamePlayHistoryServic Criteria.where("userId").is(history.getUserId()) .and("gameListConfigId").is(history.getGameListConfigId()) ); - - boolean exists = mongoTemplate.exists(query, UserGamePlayHistory.class); - if (exists) { - mongoTemplate.updateFirst(query, - new Update() - .set("gameInfo", history.getGameInfo()) - .set("playTime", history.getPlayTime()) - .set("expiredTime", history.getExpiredTime()), - UserGamePlayHistory.class); - } else { - history.setId(String.valueOf(IdWorkerUtils.getId())); - history.setPlayTime(TimestampUtils.now()); - history.setExpiredTime(TimestampUtils.nowPlusDays(90)); - mongoTemplate.save(history); - } + Update update = new Update() + .set("gameInfo", history.getGameInfo()) + .set("playTime", history.getPlayTime()) + .set("expiredTime", history.getExpiredTime()) + .setOnInsert("id", String.valueOf(IdWorkerUtils.getId())) + .setOnInsert("sysOrigin", history.getSysOrigin()) + .setOnInsert("userId", history.getUserId()) + .setOnInsert("gameListConfigId", history.getGameListConfigId()); + mongoTemplate.upsert(query, update, UserGamePlayHistory.class); } @Override