From 05c3a575bc875477314fef08f4e77034af53ca00 Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Mon, 10 Jun 2024 23:03:23 +0800 Subject: [PATCH] adjust db service parameter --- .../Service/Cultivation/CultivationService.cs | 2 +- .../Service/Inventory/IInventoryDbService.cs | 2 +- .../Service/Inventory/InventoryDbService.cs | 4 ++-- .../Takumi/Event/Calculate/CalculateClient.cs | 13 ++++++------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs index 509a26db..114b61ee 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs @@ -293,7 +293,7 @@ internal sealed partial class CultivationService : ICultivationService if (batchConsumption is { OverallConsume: { } items }) { - await inventoryDbService.RemoveInventoryItemRangeByProjectId(project.InnerId, true).ConfigureAwait(false); + await inventoryDbService.RemoveInventoryItemRangeByProjectId(project.InnerId).ConfigureAwait(false); await inventoryDbService.AddInventoryItemRangeByProjectId(items.SelectList(item => InventoryItem.From(project.InnerId, item.Id, (uint)((int)item.Num - item.LackNum)))).ConfigureAwait(false); } } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Inventory/IInventoryDbService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Inventory/IInventoryDbService.cs index db4c8c53..14430ec9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Inventory/IInventoryDbService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Inventory/IInventoryDbService.cs @@ -9,7 +9,7 @@ internal interface IInventoryDbService { ValueTask AddInventoryItemRangeByProjectId(List items); - ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId, bool includeMora = false); + ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId); void UpdateInventoryItem(InventoryItem item); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Inventory/InventoryDbService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Inventory/InventoryDbService.cs index 67a66ec2..6f1b6d50 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Inventory/InventoryDbService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Inventory/InventoryDbService.cs @@ -14,14 +14,14 @@ internal sealed partial class InventoryDbService : IInventoryDbService { private readonly IServiceProvider serviceProvider; - public async ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId, bool includeMora = false) + public async ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId) { using (IServiceScope scope = serviceProvider.CreateScope()) { AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); await appDbContext.InventoryItems .AsNoTracking() - .Where(a => a.ProjectId == projectId && (includeMora || a.ItemId != 202U)) // 摩拉 + .Where(a => a.ProjectId == projectId) .ExecuteDeleteAsync() .ConfigureAwait(false); } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/Calculate/CalculateClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/Calculate/CalculateClient.cs index febbceca..a2fae462 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/Calculate/CalculateClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/Calculate/CalculateClient.cs @@ -19,6 +19,7 @@ internal sealed partial class CalculateClient private readonly ILogger logger; private readonly HttpClient httpClient; + [Obsolete("Use BatchComputeAsync instead")] public async ValueTask> ComputeAsync(Model.Entity.User user, AvatarPromotionDelta delta, CancellationToken token = default) { HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create() @@ -34,20 +35,18 @@ internal sealed partial class CalculateClient return Response.Response.DefaultIfNull(resp); } - public async ValueTask> BatchComputeAsync(UserAndUid userAndUid, AvatarPromotionDelta delta, bool syncMaterials = false, CancellationToken token = default) + public async ValueTask> BatchComputeAsync(UserAndUid userAndUid, AvatarPromotionDelta delta, bool syncInventory = false, CancellationToken token = default) { - return await BatchComputeAsync(userAndUid, [delta], syncMaterials, token).ConfigureAwait(false); + return await BatchComputeAsync(userAndUid, [delta], syncInventory, token).ConfigureAwait(false); } - public async ValueTask> BatchComputeAsync(UserAndUid userAndUid, List deltas, bool syncMaterials = false, CancellationToken token = default) + public async ValueTask> BatchComputeAsync(UserAndUid userAndUid, List deltas, bool syncInventory = false, CancellationToken token = default) { - //ArgumentOutOfRangeException.ThrowIfGreaterThan(deltas.Count, 8); - BatchConsumptionData data = new() { Items = deltas, - Region = syncMaterials ? userAndUid.Uid.Region : default!, - Uid = syncMaterials ? userAndUid.Uid.ToString() : default!, + Region = syncInventory ? userAndUid.Uid.Region : default!, + Uid = syncInventory ? userAndUid.Uid.ToString() : default!, }; HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()