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

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);
if (exists) {
mongoTemplate.updateFirst(query,
new Update()
.set("gameInfo", history.getGameInfo()) .set("gameInfo", history.getGameInfo())
.set("playTime", history.getPlayTime()) .set("playTime", history.getPlayTime())
.set("expiredTime", history.getExpiredTime()), .set("expiredTime", history.getExpiredTime())
UserGamePlayHistory.class); .setOnInsert("id", String.valueOf(IdWorkerUtils.getId()))
} else { .setOnInsert("sysOrigin", history.getSysOrigin())
history.setId(String.valueOf(IdWorkerUtils.getId())); .setOnInsert("userId", history.getUserId())
history.setPlayTime(TimestampUtils.now()); .setOnInsert("gameListConfigId", history.getGameListConfigId());
history.setExpiredTime(TimestampUtils.nowPlusDays(90)); mongoTemplate.upsert(query, update, UserGamePlayHistory.class);
mongoTemplate.save(history);
}
} }
@Override @Override