修改记录用户游玩记录接口

This commit is contained in:
tianfeng 2026-03-12 10:13:38 +08:00
parent 4f53c6a9e8
commit e2e7614216

View File

@ -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