adjust db service parameter

This commit is contained in:
DismissedLight
2024-06-10 23:03:23 +08:00
parent 3e26e247cd
commit 05c3a575bc
4 changed files with 10 additions and 11 deletions

View File

@@ -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);
}
}

View File

@@ -9,7 +9,7 @@ internal interface IInventoryDbService
{
ValueTask AddInventoryItemRangeByProjectId(List<InventoryItem> items);
ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId, bool includeMora = false);
ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId);
void UpdateInventoryItem(InventoryItem item);

View File

@@ -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<AppDbContext>();
await appDbContext.InventoryItems
.AsNoTracking()
.Where(a => a.ProjectId == projectId && (includeMora || a.ItemId != 202U)) // 摩拉
.Where(a => a.ProjectId == projectId)
.ExecuteDeleteAsync()
.ConfigureAwait(false);
}

View File

@@ -19,6 +19,7 @@ internal sealed partial class CalculateClient
private readonly ILogger<CalculateClient> logger;
private readonly HttpClient httpClient;
[Obsolete("Use BatchComputeAsync instead")]
public async ValueTask<Response<Consumption>> 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<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, AvatarPromotionDelta delta, bool syncMaterials = false, CancellationToken token = default)
public async ValueTask<Response<BatchConsumption>> 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<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, List<AvatarPromotionDelta> deltas, bool syncMaterials = false, CancellationToken token = default)
public async ValueTask<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, List<AvatarPromotionDelta> 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()