| | | 1 | | using Microsoft.Extensions.DependencyInjection; |
| | | 2 | | using OzonDomains.Models; |
| | | 3 | | using Services.ApiServices._1CApi.Models; |
| | | 4 | | using Services.OneCServices; |
| | | 5 | | |
| | | 6 | | namespace Services.DataServices; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Безопасная запись проведений 1С в историю заказа (не ломает транзакцию при ошибке БД). |
| | | 10 | | /// </summary> |
| | | 11 | | public static class OrderHistoryOneCPostingRecorder |
| | | 12 | | { |
| | | 13 | | public static async Task TryRecordAsync( |
| | | 14 | | IServiceProvider serviceProvider, |
| | | 15 | | IReadOnlyList<Order> orders, |
| | | 16 | | IReadOnlyList<OneCResponse> responses, |
| | | 17 | | string operationKind, |
| | | 18 | | string changedBy, |
| | | 19 | | int? transactionId, |
| | | 20 | | DateTime historyWindowStart, |
| | | 21 | | string? warehouseSender = null, |
| | | 22 | | string? warehouseRecipient = null) |
| | | 23 | | { |
| | 11 | 24 | | if (orders == null || orders.Count == 0 || responses == null || responses.Count == 0) |
| | 4 | 25 | | return; |
| | | 26 | | |
| | | 27 | | try |
| | | 28 | | { |
| | 7 | 29 | | using var scope = serviceProvider.CreateScope(); |
| | 6 | 30 | | var service = scope.ServiceProvider.GetService<IOrderHistoryOneCPostingService>(); |
| | 6 | 31 | | if (service == null) |
| | 1 | 32 | | return; |
| | | 33 | | |
| | 5 | 34 | | await service.RecordPostingsAsync( |
| | 5 | 35 | | orders, |
| | 5 | 36 | | responses, |
| | 5 | 37 | | operationKind, |
| | 5 | 38 | | changedBy, |
| | 5 | 39 | | transactionId, |
| | 5 | 40 | | historyWindowStart, |
| | 5 | 41 | | warehouseSender, |
| | 5 | 42 | | warehouseRecipient); |
| | 4 | 43 | | } |
| | 2 | 44 | | catch |
| | | 45 | | { |
| | | 46 | | // Не ломаем проведение транзакции из-за журнала 1С. |
| | 2 | 47 | | } |
| | 11 | 48 | | } |
| | | 49 | | |
| | | 50 | | public static Task TryRecordMovementAsync( |
| | | 51 | | IServiceProvider serviceProvider, |
| | | 52 | | IReadOnlyList<Order> orders, |
| | | 53 | | IReadOnlyList<OneCResponse> responses, |
| | | 54 | | string changedBy, |
| | | 55 | | int? transactionId, |
| | | 56 | | DateTime historyWindowStart, |
| | | 57 | | string? warehouseSender = null, |
| | | 58 | | string? warehouseRecipient = null) |
| | 1 | 59 | | => TryRecordAsync( |
| | 1 | 60 | | serviceProvider, |
| | 1 | 61 | | orders, |
| | 1 | 62 | | responses, |
| | 1 | 63 | | OneCPostingOperationKinds.Movement, |
| | 1 | 64 | | changedBy, |
| | 1 | 65 | | transactionId, |
| | 1 | 66 | | historyWindowStart, |
| | 1 | 67 | | warehouseSender, |
| | 1 | 68 | | warehouseRecipient); |
| | | 69 | | |
| | | 70 | | public static Task TryRecordReceiptAsync( |
| | | 71 | | IServiceProvider serviceProvider, |
| | | 72 | | IReadOnlyList<Order> orders, |
| | | 73 | | IReadOnlyList<OneCResponse> responses, |
| | | 74 | | string changedBy, |
| | | 75 | | int? transactionId, |
| | | 76 | | DateTime historyWindowStart) |
| | 1 | 77 | | => TryRecordAsync( |
| | 1 | 78 | | serviceProvider, |
| | 1 | 79 | | orders, |
| | 1 | 80 | | responses, |
| | 1 | 81 | | OneCPostingOperationKinds.Receipt, |
| | 1 | 82 | | changedBy, |
| | 1 | 83 | | transactionId, |
| | 1 | 84 | | historyWindowStart); |
| | | 85 | | |
| | | 86 | | public static Task TryRecordExpenseAsync( |
| | | 87 | | IServiceProvider serviceProvider, |
| | | 88 | | IReadOnlyList<Order> orders, |
| | | 89 | | IReadOnlyList<OneCResponse> responses, |
| | | 90 | | string changedBy, |
| | | 91 | | int? transactionId, |
| | | 92 | | DateTime historyWindowStart) |
| | 1 | 93 | | => TryRecordAsync( |
| | 1 | 94 | | serviceProvider, |
| | 1 | 95 | | orders, |
| | 1 | 96 | | responses, |
| | 1 | 97 | | OneCPostingOperationKinds.Expense, |
| | 1 | 98 | | changedBy, |
| | 1 | 99 | | transactionId, |
| | 1 | 100 | | historyWindowStart); |
| | | 101 | | } |