| | | 1 | | using OzonOrdersWeb.TransactionServices; |
| | | 2 | | using OzonRepositories.Context; |
| | | 3 | | using Services.TransactionCommentAi; |
| | | 4 | | |
| | | 5 | | namespace OzonOrdersWeb.WebServices.Transactions.Grid.Commit.Steps; |
| | | 6 | | |
| | | 7 | | /// <summary>Постановка AI-комментария в очередь, если пользователь не написал свой.</summary> |
| | | 8 | | public sealed class AiCommentStep : ITransactionCommitStep |
| | | 9 | | { |
| | | 10 | | private readonly ApplicationDbContext _context; |
| | | 11 | | |
| | 0 | 12 | | public AiCommentStep(ApplicationDbContext context) |
| | | 13 | | { |
| | 0 | 14 | | _context = context; |
| | 0 | 15 | | } |
| | | 16 | | |
| | 0 | 17 | | public string Key => TransactionCommitStepKeys.AiComment; |
| | | 18 | | |
| | | 19 | | public async Task ExecuteAsync(TransactionCommitContext ctx) |
| | | 20 | | { |
| | 0 | 21 | | var flow = ctx.CommentFlow; |
| | 0 | 22 | | if (!flow.ScheduleAiComment || flow.Builder == null || ctx.TransactionId <= 0) |
| | | 23 | | { |
| | 0 | 24 | | return; |
| | | 25 | | } |
| | | 26 | | |
| | 0 | 27 | | if (ctx.OzonShipResult is OrderToSupplierOzonShipResult ship) |
| | | 28 | | { |
| | 0 | 29 | | flow.Builder.WithOzonShip(TransactionCommentAiOzonShipMapper.ToSummary(ship)); |
| | | 30 | | } |
| | | 31 | | |
| | 0 | 32 | | var changedFieldsByOrder = ctx.OrdersToTransaction.ToDictionary( |
| | 0 | 33 | | o => o.Id, |
| | 0 | 34 | | o => (o.UpdatedColumns ?? new List<string>()).Where(c => !string.IsNullOrWhiteSpace(c)).Distinct().ToList()) |
| | | 35 | | |
| | 0 | 36 | | await TransactionCommentAiSchedulingHelper.TryScheduleAsync( |
| | 0 | 37 | | ctx.Services, flow.Builder, flow.ScheduleAiComment, ctx.TransactionId, ctx.OrdersToTransaction, |
| | 0 | 38 | | ctx.FromStatusByOrderId, _context, changedFieldsByOrder, ctx.CancellationToken); |
| | 0 | 39 | | } |
| | | 40 | | } |