초기커밋
This commit is contained in:
128
UGQDataAccess/Repository/GameQuestDataRepository.cs
Normal file
128
UGQDataAccess/Repository/GameQuestDataRepository.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Driver;
|
||||
using UGQDatabase.Models;
|
||||
using UGQDataAccess.Settings;
|
||||
using ServerCommon.UGQ;
|
||||
using StackExchange.Redis;
|
||||
using System.Drawing;
|
||||
using ServerCommon;
|
||||
|
||||
namespace UGQDataAccess.Repository;
|
||||
|
||||
public class GameQuestDataRepository : BaseRepository<GameQuestDataEntity>
|
||||
{
|
||||
private const string CollectionName = "GameQuestData";
|
||||
|
||||
public GameQuestDataRepository(IMongoClient mongoClient, IOptions<UGQDatabaseSettings> settings) :
|
||||
base(mongoClient, settings.Value.DatabaseName, CollectionName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public async Task<GameQuestDataEntity?> insert(QuestContentEntity content,
|
||||
QuestContentState state,
|
||||
List<GameQuestDialogDataEntity> dialogues,
|
||||
List<QuestMetaInfo> metas,
|
||||
string ugqGameQuestDataForClientString,
|
||||
UgqGradeType? gradeType = null)
|
||||
{
|
||||
var filterBuilder = Builders<GameQuestDataEntity>.Filter;
|
||||
|
||||
var filter = filterBuilder.Eq(x => x.QuestId, content.QuestId) &
|
||||
filterBuilder.Eq(x => x.Revision, content.Revision) &
|
||||
filterBuilder.Eq(x => x.State, state);
|
||||
|
||||
var updateGradeType = gradeType;
|
||||
if (updateGradeType == null)
|
||||
updateGradeType = content.GradeType;
|
||||
|
||||
var update = Builders<GameQuestDataEntity>.Update
|
||||
.Set(x => x.QuestId, content.QuestId)
|
||||
.Set(x => x.Revision, content.Revision)
|
||||
.Set(x => x.UserGuid, content.UserGuid)
|
||||
.Set(x => x.Author, content.Author)
|
||||
.Set(x => x.BeaconId, content.BeaconId)
|
||||
.Set(x => x.UgcBeaconGuid, content.UgcBeaconGuid)
|
||||
.Set(x => x.UgcBeaconNickname, content.UgcBeaconNickname)
|
||||
.Set(x => x.Title, content.Title)
|
||||
.Set(x => x.Langs, content.Langs)
|
||||
.Set(x => x.TitleImagePath, content.TitleImagePath)
|
||||
.Set(x => x.BannerImagePath, content.BannerImagePath)
|
||||
.Set(x => x.Description, content.Description)
|
||||
.Set(x => x.GradeType, updateGradeType)
|
||||
.Set(x => x.State, state)
|
||||
.Set(x => x.Cost, content.Cost)
|
||||
.Set(x => x.Shutdown, false)
|
||||
.Set(x => x.Tasks, content.Tasks)
|
||||
.Set(x => x.Dialogs, dialogues)
|
||||
.Set(x => x.UpdatedAt, DateTime.UtcNow)
|
||||
.Set(x => x.QuestScriptMetas, metas)
|
||||
.Set(x => x.UgqGameQuestDataForClientString, ugqGameQuestDataForClientString)
|
||||
.SetOnInsert(x => x.CreatedAt, DateTime.UtcNow);
|
||||
|
||||
var option = new FindOneAndUpdateOptions<GameQuestDataEntity>
|
||||
{
|
||||
IsUpsert = true,
|
||||
ReturnDocument = ReturnDocument.After
|
||||
};
|
||||
|
||||
return await Collection.FindOneAndUpdateAsync(filter, update, option);
|
||||
}
|
||||
|
||||
public async Task delete(long questId, long revision, QuestContentState state)
|
||||
{
|
||||
var filterBuilder = Builders<GameQuestDataEntity>.Filter;
|
||||
|
||||
var filter = filterBuilder.Eq(x => x.QuestId, questId) &
|
||||
filterBuilder.Eq(x => x.Revision, revision) &
|
||||
filterBuilder.Eq(x => x.State, state);
|
||||
|
||||
await Collection.DeleteOneAsync(filter);
|
||||
}
|
||||
|
||||
public async Task<GameQuestDataEntity?> get(long questId, long revision, QuestContentState state)
|
||||
{
|
||||
var builder = Builders<GameQuestDataEntity>.Filter;
|
||||
var filter = builder.Eq(x => x.QuestId, questId) &
|
||||
builder.Eq(x => x.Revision, revision) &
|
||||
builder.Eq(x => x.State, state);
|
||||
|
||||
return await Collection.Find(filter).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<GameQuestDataEntity?> getLatestRevision(long questId)
|
||||
{
|
||||
var builder = Builders<GameQuestDataEntity>.Filter;
|
||||
var filter = builder.Eq(x => x.QuestId, questId);
|
||||
|
||||
GameQuestDataEntity? entity = await Collection.Find(filter)
|
||||
.SortByDescending(x => x.Revision)
|
||||
.Limit(1)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<GameQuestDataEntity?> setShutdown(long questId, long revision)
|
||||
{
|
||||
var builder = Builders<GameQuestDataEntity>.Filter;
|
||||
var filter = builder.Eq(x => x.QuestId, questId) & builder.Eq(x => x.Revision, revision) &
|
||||
builder.Eq(x => x.State, QuestContentState.Live);
|
||||
|
||||
var update = Builders<GameQuestDataEntity>.Update
|
||||
.Set(x => x.Shutdown, true);
|
||||
|
||||
var options = new FindOneAndUpdateOptions<GameQuestDataEntity>
|
||||
{
|
||||
ReturnDocument = ReturnDocument.After,
|
||||
};
|
||||
|
||||
return await Collection.FindOneAndUpdateAsync(filter, update, options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user