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

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.entity.game.UserGamePlayHistory;
import com.red.circle.other.infra.database.mongo.service.game.UserGamePlayHistoryService; 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 com.red.circle.tool.core.sequence.IdWorkerUtils;
import java.util.List; import java.util.List;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -28,21 +27,15 @@ public class UserGamePlayHistoryServiceImpl implements UserGamePlayHistoryServic
Criteria.where("userId").is(history.getUserId()) Criteria.where("userId").is(history.getUserId())
.and("gameListConfigId").is(history.getGameListConfigId()) .and("gameListConfigId").is(history.getGameListConfigId())
); );
Update update = new Update()
boolean exists = mongoTemplate.exists(query, UserGamePlayHistory.class); .set("gameInfo", history.getGameInfo())
if (exists) { .set("playTime", history.getPlayTime())
mongoTemplate.updateFirst(query, .set("expiredTime", history.getExpiredTime())
new Update() .setOnInsert("id", String.valueOf(IdWorkerUtils.getId()))
.set("gameInfo", history.getGameInfo()) .setOnInsert("sysOrigin", history.getSysOrigin())
.set("playTime", history.getPlayTime()) .setOnInsert("userId", history.getUserId())
.set("expiredTime", history.getExpiredTime()), .setOnInsert("gameListConfigId", history.getGameListConfigId());
UserGamePlayHistory.class); mongoTemplate.upsert(query, update, UserGamePlayHistory.class);
} else {
history.setId(String.valueOf(IdWorkerUtils.getId()));
history.setPlayTime(TimestampUtils.now());
history.setExpiredTime(TimestampUtils.nowPlusDays(90));
mongoTemplate.save(history);
}
} }
@Override @Override