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