| | | 1 | | using Newtonsoft.Json; |
| | | 2 | | using OzonDomains; |
| | | 3 | | using OzonDomains.Models; |
| | | 4 | | using OzonRepositories.Data; |
| | | 5 | | using Services.ApiServices.OzonApi; |
| | | 6 | | using Services.ApiServices.OzonApi.Filters; |
| | | 7 | | using Services.LabelServices; |
| | | 8 | | using Services.ParserServices.HelpDictEnum; |
| | | 9 | | |
| | | 10 | | namespace Services.DataServices; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Сервис для работы с возвратами Ozon. Синхронизация из API, связь с заказами. |
| | | 14 | | /// </summary> |
| | | 15 | | public class OrderReturnDataServices |
| | | 16 | | { |
| | | 17 | | private readonly OrderReturnRepository _repository; |
| | | 18 | | private readonly OrderRepository _orderRepository; |
| | | 19 | | private readonly OrdersDataServices _ordersDataServices; |
| | | 20 | | private readonly OzonJsonDataBuilder _jsonDataBuilder; |
| | | 21 | | private readonly OzonClientServices _ozonClientServices; |
| | | 22 | | private readonly ClientStatusDataServices _clientStatusServices; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Номера, которых нет среди наших заказов. В выдаче Ozon много чужих отмен, и на каждом батче |
| | | 26 | | /// каждого прогона они заново прогонялись через поиск по префиксу с заведомо нулевым результатом. |
| | | 27 | | /// |
| | | 28 | | /// Кэш живёт ровно столько, сколько экземпляр сервиса, то есть один прогон загрузки: заказ, |
| | | 29 | | /// импортированный в середине прогона, свяжется на следующем — при перехлёсте в два часа |
| | | 30 | | /// возврат всё равно будет перечитан. |
| | | 31 | | /// </summary> |
| | 0 | 32 | | private readonly HashSet<string> _numbersWithoutOrders = new(StringComparer.OrdinalIgnoreCase); |
| | | 33 | | |
| | | 34 | | /// <summary>Потолок на случай гигантской полной сверки — кэш не должен расти без предела.</summary> |
| | | 35 | | private const int MaxCachedMissingNumbers = 100_000; |
| | | 36 | | |
| | 0 | 37 | | public OrderReturnDataServices( |
| | 0 | 38 | | OrderReturnRepository repository, |
| | 0 | 39 | | OrderRepository orderRepository, |
| | 0 | 40 | | OrdersDataServices ordersDataServices, |
| | 0 | 41 | | OzonJsonDataBuilder jsonDataBuilder, |
| | 0 | 42 | | OzonClientServices ozonClientServices, |
| | 0 | 43 | | ClientStatusDataServices clientStatusServices) |
| | | 44 | | { |
| | 0 | 45 | | _repository = repository; |
| | 0 | 46 | | _orderRepository = orderRepository; |
| | 0 | 47 | | _ordersDataServices = ordersDataServices; |
| | 0 | 48 | | _jsonDataBuilder = jsonDataBuilder; |
| | 0 | 49 | | _ozonClientServices = ozonClientServices; |
| | 0 | 50 | | _clientStatusServices = clientStatusServices; |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Синхронизировать возвраты из ответа API в БД. Сопоставляет с заказами по PostingNumber. |
| | | 55 | | /// Использует батч-операции для устранения N+1 запросов. |
| | | 56 | | /// </summary> |
| | | 57 | | /// <param name="response">Ответ API /v1/returns/list.</param> |
| | | 58 | | /// <param name="ozonClientId">Идентификатор клиента Ozon в нашей системе.</param> |
| | | 59 | | public async Task<ReturnsSyncResult> SyncFromApiResponseAsync(ReturnListResponse response, int ozonClientId) |
| | | 60 | | { |
| | 0 | 61 | | if (response?.Returns == null || response.Returns.Count == 0) |
| | 0 | 62 | | return ReturnsSyncResult.Empty; |
| | | 63 | | |
| | 0 | 64 | | var orderIdsToMarkReturned = new HashSet<int>(); |
| | | 65 | | |
| | 0 | 66 | | var numbersToLookup = response.Returns |
| | 0 | 67 | | .SelectMany(r => new[] { r.OrderNumber, r.PostingNumber }) |
| | 0 | 68 | | .Where(n => !string.IsNullOrEmpty(n)) |
| | 0 | 69 | | .Select(n => n!) |
| | 0 | 70 | | .Distinct() |
| | 0 | 71 | | .Where(n => !_numbersWithoutOrders.Contains(n)) |
| | 0 | 72 | | .ToList(); |
| | | 73 | | |
| | 0 | 74 | | var orderIdsByNumber = await _orderRepository.GetOrderIdsByShipmentNumbersAsync(numbersToLookup, ozonClientId); |
| | | 75 | | |
| | 0 | 76 | | if (_numbersWithoutOrders.Count < MaxCachedMissingNumbers) |
| | | 77 | | { |
| | 0 | 78 | | foreach (var number in numbersToLookup.Where(n => !orderIdsByNumber.ContainsKey(n))) |
| | 0 | 79 | | _numbersWithoutOrders.Add(number); |
| | | 80 | | } |
| | | 81 | | |
| | 0 | 82 | | var entities = new List<OrderReturn>(); |
| | 0 | 83 | | foreach (var ozonReturn in response.Returns) |
| | | 84 | | { |
| | 0 | 85 | | var entity = MapToOrderReturn(ozonReturn, ozonClientId); |
| | | 86 | | |
| | 0 | 87 | | if (!string.IsNullOrEmpty(entity.OrderNumber) && orderIdsByNumber.TryGetValue(entity.OrderNumber, out var or |
| | | 88 | | { |
| | 0 | 89 | | entity.OrderId = orderIdByOrder; |
| | 0 | 90 | | orderIdsToMarkReturned.Add(orderIdByOrder); |
| | | 91 | | } |
| | 0 | 92 | | else if (!string.IsNullOrEmpty(entity.PostingNumber) && orderIdsByNumber.TryGetValue(entity.PostingNumber, o |
| | | 93 | | { |
| | 0 | 94 | | entity.OrderId = orderIdByPosting; |
| | 0 | 95 | | orderIdsToMarkReturned.Add(orderIdByPosting); |
| | | 96 | | } |
| | | 97 | | |
| | 0 | 98 | | entity.RawDataJson = JsonConvert.SerializeObject(ozonReturn); |
| | 0 | 99 | | entities.Add(entity); |
| | | 100 | | } |
| | | 101 | | |
| | | 102 | | try |
| | | 103 | | { |
| | 0 | 104 | | var upsert = await _repository.UpsertBatchFromOzonReturnsAsync(entities); |
| | | 105 | | |
| | 0 | 106 | | if (orderIdsToMarkReturned.Count > 0) |
| | 0 | 107 | | await _orderRepository.SetIsReturnedForOrderIdsAsync(orderIdsToMarkReturned, true); |
| | | 108 | | |
| | | 109 | | // Статус заказа в Ozon перезапрашиваем только там, где возврат реально изменился, и одним |
| | | 110 | | // батчем. Раньше это был последовательный /v3/posting/fbs/get на каждый связанный заказ |
| | | 111 | | // в каждом батче каждого прогона — при полном окне это тысячи запросов на ровном месте. |
| | 0 | 112 | | var changedOrderIds = upsert.Changed |
| | 0 | 113 | | .Where(r => r.OrderId.HasValue) |
| | 0 | 114 | | .Select(r => r.OrderId!.Value) |
| | 0 | 115 | | .Distinct() |
| | 0 | 116 | | .ToList(); |
| | | 117 | | |
| | 0 | 118 | | if (changedOrderIds.Count > 0) |
| | | 119 | | { |
| | 0 | 120 | | var ordersForStatusUpdate = await _orderRepository.GetOrdersForStatusUpdateAsync(changedOrderIds); |
| | 0 | 121 | | await UpdateOrderStatusesFromOzonAsync(ordersForStatusUpdate, ozonClientId); |
| | | 122 | | } |
| | | 123 | | |
| | 0 | 124 | | return new ReturnsSyncResult( |
| | 0 | 125 | | upsert.Processed, |
| | 0 | 126 | | upsert.Inserted, |
| | 0 | 127 | | upsert.Changed.Count, |
| | 0 | 128 | | orderIdsToMarkReturned.Count); |
| | | 129 | | } |
| | | 130 | | finally |
| | | 131 | | { |
| | | 132 | | // Батч обработан — трекер больше не нужен. При ошибке или успешном сохранении |
| | | 133 | | // сбрасываем ChangeTracker, чтобы не накапливать сущности и не заражать последующие батчи. |
| | 0 | 134 | | _repository.ClearChangeTracker(); |
| | | 135 | | } |
| | 0 | 136 | | } |
| | | 137 | | |
| | | 138 | | /// <summary> |
| | | 139 | | /// Сбросить ChangeTracker репозитория возвратов. |
| | | 140 | | /// </summary> |
| | 0 | 141 | | public void ClearChangeTracker() => _repository.ClearChangeTracker(); |
| | | 142 | | |
| | | 143 | | /// <summary> |
| | | 144 | | /// Привести IsReturned в соответствие с наличием записей в OrderReturns. |
| | | 145 | | /// Вызывается на полной сверке — гонять по всей таблице заказов на каждом инкрементальном тике незачем. |
| | | 146 | | /// </summary> |
| | | 147 | | public async Task<(int Cleared, int Set)> ReconcileIsReturnedFlagAsync() => |
| | 0 | 148 | | await _orderRepository.ReconcileIsReturnedFlagAsync(); |
| | | 149 | | |
| | | 150 | | /// <summary> |
| | | 151 | | /// Максимальный VisualStatusChangeMoment среди сохранённых возвратов клиента — граница |
| | | 152 | | /// инкрементальной загрузки. null, если возвратов у клиента ещё нет. |
| | | 153 | | /// </summary> |
| | | 154 | | public async Task<DateTime?> GetLastSyncedStatusMomentAsync(int ozonClientId) => |
| | 0 | 155 | | await _repository.GetMaxVisualStatusChangeMomentAsync(ozonClientId); |
| | | 156 | | |
| | | 157 | | /// <summary> |
| | | 158 | | /// Обновляет статус заказов (ClientStatus) из Ozon API батч-запросом. Вызывается только для заказов, |
| | | 159 | | /// у которых при импорте реально изменился статус возврата или компенсации. |
| | | 160 | | /// </summary> |
| | | 161 | | private async Task UpdateOrderStatusesFromOzonAsync(List<Order> orders, int ozonClientId) |
| | | 162 | | { |
| | | 163 | | try |
| | | 164 | | { |
| | 0 | 165 | | var targets = orders |
| | 0 | 166 | | .Where(o => !string.IsNullOrEmpty(o.ShipmentNumber)) |
| | 0 | 167 | | .ToList(); |
| | 0 | 168 | | if (targets.Count == 0) |
| | 0 | 169 | | return; |
| | | 170 | | |
| | 0 | 171 | | var client = targets[0].OzonClient ?? await _ozonClientServices.GetOzonClientAsync(ozonClientId); |
| | 0 | 172 | | if (client == null || client.ClientType != ClientType.OZON || |
| | 0 | 173 | | string.IsNullOrEmpty(client.DecryptClientId) || string.IsNullOrEmpty(client.DecryptApiKey)) |
| | 0 | 174 | | return; |
| | | 175 | | |
| | 0 | 176 | | _jsonDataBuilder.SetClient(client.DecryptClientId ?? "", client.DecryptApiKey ?? ""); |
| | | 177 | | |
| | 0 | 178 | | var shipmentNumbers = targets |
| | 0 | 179 | | .Select(o => o.ShipmentNumber!) |
| | 0 | 180 | | .Where(s => !string.IsNullOrWhiteSpace(s)) |
| | 0 | 181 | | .Distinct() |
| | 0 | 182 | | .ToList(); |
| | | 183 | | |
| | | 184 | | // Success=false означает «запрос упал», а не «статуса нет» — такие заказы пропускаем, |
| | | 185 | | // их подхватит следующий прогон, когда возврат снова попадёт в изменённые. |
| | 0 | 186 | | var statuses = await _jsonDataBuilder.GetProductStatusBatch(shipmentNumbers); |
| | | 187 | | |
| | 0 | 188 | | var statusCache = new Dictionary<string, ClientStatus>(StringComparer.OrdinalIgnoreCase); |
| | 0 | 189 | | var changedOrders = new List<Order>(); |
| | | 190 | | |
| | 0 | 191 | | foreach (var order in targets) |
| | | 192 | | { |
| | 0 | 193 | | var apiPosting = OzonPostingNumberHelper.GetOzonApiPostingNumber(order.ShipmentNumber); |
| | 0 | 194 | | var hasStatus = statuses.TryGetValue(order.ShipmentNumber!, out var apiStatus) || |
| | 0 | 195 | | (!string.IsNullOrEmpty(apiPosting) && statuses.TryGetValue(apiPosting, out apiStatus)); |
| | | 196 | | |
| | 0 | 197 | | if (!hasStatus || !apiStatus.Success || string.IsNullOrEmpty(apiStatus.Status)) |
| | | 198 | | continue; |
| | | 199 | | |
| | 0 | 200 | | var newStatusName = OzonStatus.OrderStatuses.TryGetValue(apiStatus.Status, out var mappedStatus) |
| | 0 | 201 | | ? mappedStatus |
| | 0 | 202 | | : apiStatus.Status; |
| | | 203 | | |
| | 0 | 204 | | if (order.ClientStatus?.Name?.Equals(newStatusName, StringComparison.OrdinalIgnoreCase) == true) |
| | | 205 | | continue; |
| | | 206 | | |
| | 0 | 207 | | if (!statusCache.TryGetValue(newStatusName, out var clientStatus)) |
| | | 208 | | { |
| | 0 | 209 | | clientStatus = await _clientStatusServices.GetClientStatusByNameAsync(newStatusName); |
| | 0 | 210 | | if (clientStatus == null) |
| | | 211 | | { |
| | 0 | 212 | | clientStatus = new ClientStatus { Name = newStatusName }; |
| | 0 | 213 | | await _clientStatusServices.AddClientStatus(clientStatus); |
| | | 214 | | } |
| | | 215 | | |
| | 0 | 216 | | statusCache[newStatusName] = clientStatus; |
| | | 217 | | } |
| | | 218 | | |
| | 0 | 219 | | order.ClientStatus = clientStatus; |
| | 0 | 220 | | order.ClientStatusId = clientStatus.Id; |
| | 0 | 221 | | changedOrders.Add(order); |
| | 0 | 222 | | } |
| | | 223 | | |
| | 0 | 224 | | if (changedOrders.Count > 0) |
| | 0 | 225 | | await _ordersDataServices.UpdateOrders(changedOrders); |
| | 0 | 226 | | } |
| | 0 | 227 | | catch |
| | | 228 | | { |
| | | 229 | | // Игнорируем ошибки обновления статуса — не блокируем синхронизацию возвратов |
| | 0 | 230 | | } |
| | 0 | 231 | | } |
| | | 232 | | |
| | | 233 | | /// <summary>Преобразовать ответ API в сущность OrderReturn.</summary> |
| | | 234 | | public static OrderReturn MapToOrderReturn(OzonReturn ozonReturn, int ozonClientId) |
| | | 235 | | { |
| | 0 | 236 | | var entity = new OrderReturn |
| | 0 | 237 | | { |
| | 0 | 238 | | OzonReturnId = ozonReturn.Id, |
| | 0 | 239 | | OzonClientId = ozonClientId, |
| | 0 | 240 | | PostingNumber = ozonReturn.PostingNumber, |
| | 0 | 241 | | OrderNumber = ozonReturn.OrderNumber, |
| | 0 | 242 | | ReturnReasonName = ozonReturn.ReturnReasonName, |
| | 0 | 243 | | ReturnType = ozonReturn.Type, |
| | 0 | 244 | | Schema = ozonReturn.Schema, |
| | 0 | 245 | | OzonOrderId = ozonReturn.OrderId, |
| | 0 | 246 | | SourceId = ozonReturn.SourceId, |
| | 0 | 247 | | ClearingId = ozonReturn.ClearingId, |
| | 0 | 248 | | ReturnClearingId = ozonReturn.ReturnClearingId |
| | 0 | 249 | | }; |
| | | 250 | | |
| | 0 | 251 | | if (ozonReturn.Place != null) |
| | | 252 | | { |
| | 0 | 253 | | entity.PlaceId = ozonReturn.Place.Id; |
| | 0 | 254 | | entity.PlaceName = ozonReturn.Place.Name; |
| | 0 | 255 | | entity.PlaceAddress = ozonReturn.Place.Address; |
| | | 256 | | } |
| | | 257 | | |
| | 0 | 258 | | if (ozonReturn.TargetPlace != null) |
| | | 259 | | { |
| | 0 | 260 | | entity.TargetPlaceId = ozonReturn.TargetPlace.Id; |
| | 0 | 261 | | entity.TargetPlaceName = ozonReturn.TargetPlace.Name; |
| | 0 | 262 | | entity.TargetPlaceAddress = ozonReturn.TargetPlace.Address; |
| | | 263 | | } |
| | | 264 | | |
| | 0 | 265 | | if (ozonReturn.Storage != null) |
| | | 266 | | { |
| | 0 | 267 | | entity.StorageSumPrice = (decimal?)(ozonReturn.Storage.Sum?.Price ?? 0); |
| | 0 | 268 | | entity.StorageSumCurrency = ozonReturn.Storage.Sum?.CurrencyCode; |
| | 0 | 269 | | entity.StorageDays = ozonReturn.Storage.Days; |
| | 0 | 270 | | entity.StorageTarificationFirstDate = ozonReturn.Storage.TarificationFirstDate; |
| | 0 | 271 | | entity.StorageTarificationStartDate = ozonReturn.Storage.TarificationStartDate; |
| | 0 | 272 | | entity.StorageArrivedMoment = ozonReturn.Storage.ArrivedMoment; |
| | 0 | 273 | | entity.UtilizationSumPrice = (decimal?)(ozonReturn.Storage.UtilizationSum?.Price ?? 0); |
| | 0 | 274 | | entity.UtilizationSumCurrency = ozonReturn.Storage.UtilizationSum?.CurrencyCode; |
| | 0 | 275 | | entity.UtilizationForecastDate = ozonReturn.Storage.UtilizationForecastDate; |
| | | 276 | | } |
| | | 277 | | |
| | 0 | 278 | | if (ozonReturn.Product != null) |
| | | 279 | | { |
| | 0 | 280 | | entity.ProductSku = ozonReturn.Product.Sku; |
| | 0 | 281 | | entity.ProductOfferId = ozonReturn.Product.OfferId; |
| | 0 | 282 | | entity.ProductName = ozonReturn.Product.Name; |
| | 0 | 283 | | entity.ProductPrice = (decimal?)(ozonReturn.Product.Price?.Price ?? 0); |
| | 0 | 284 | | entity.ProductPriceCurrency = ozonReturn.Product.Price?.CurrencyCode; |
| | 0 | 285 | | entity.ProductCommissionPercent = ozonReturn.Product.CommissionPercent; |
| | 0 | 286 | | entity.ProductCommission = (decimal?)(ozonReturn.Product.Commission?.Price ?? 0); |
| | 0 | 287 | | entity.ProductQuantity = ozonReturn.Product.Quantity; |
| | | 288 | | } |
| | | 289 | | |
| | 0 | 290 | | if (ozonReturn.Logistic != null) |
| | | 291 | | { |
| | 0 | 292 | | entity.TechnicalReturnMoment = ozonReturn.Logistic.TechnicalReturnMoment; |
| | 0 | 293 | | entity.FinalMoment = ozonReturn.Logistic.FinalMoment; |
| | 0 | 294 | | entity.CancelledWithCompensationMoment = ozonReturn.Logistic.CancelledWithCompensationMoment; |
| | 0 | 295 | | entity.ReturnDate = ozonReturn.Logistic.ReturnDate; |
| | 0 | 296 | | entity.LogisticBarcode = ozonReturn.Logistic.Barcode; |
| | | 297 | | } |
| | | 298 | | |
| | 0 | 299 | | if (ozonReturn.Visual?.Status != null) |
| | | 300 | | { |
| | 0 | 301 | | entity.VisualStatusId = ozonReturn.Visual.Status.Id; |
| | 0 | 302 | | entity.VisualStatusDisplayName = ozonReturn.Visual.Status.DisplayName; |
| | 0 | 303 | | entity.VisualStatusSysName = ozonReturn.Visual.Status.SysName; |
| | 0 | 304 | | entity.VisualStatusChangeMoment = ozonReturn.Visual.ChangeMoment; |
| | | 305 | | } |
| | | 306 | | |
| | 0 | 307 | | if (ozonReturn.CompensationStatus?.Status != null) |
| | | 308 | | { |
| | 0 | 309 | | entity.CompensationStatusId = ozonReturn.CompensationStatus.Status.Id; |
| | 0 | 310 | | entity.CompensationStatusDisplayName = ozonReturn.CompensationStatus.Status.DisplayName; |
| | 0 | 311 | | entity.CompensationStatusSysName = ozonReturn.CompensationStatus.Status.SysName; |
| | 0 | 312 | | entity.CompensationStatusChangeMoment = ozonReturn.CompensationStatus.ChangeMoment; |
| | | 313 | | } |
| | | 314 | | |
| | 0 | 315 | | if (ozonReturn.AdditionalInfo != null) |
| | | 316 | | { |
| | 0 | 317 | | entity.IsOpened = ozonReturn.AdditionalInfo.IsOpened; |
| | 0 | 318 | | entity.IsSuperEconom = ozonReturn.AdditionalInfo.IsSuperEconom; |
| | | 319 | | } |
| | | 320 | | |
| | 0 | 321 | | return entity; |
| | | 322 | | } |
| | | 323 | | |
| | | 324 | | public async Task<OrderReturn?> GetByIdAsync(long id) => |
| | 0 | 325 | | await _repository.GetByIdAsync(id); |
| | | 326 | | |
| | | 327 | | public async Task<OrderReturn?> GetByOzonReturnIdAsync(long ozonReturnId) => |
| | 0 | 328 | | await _repository.GetByOzonReturnIdAsync(ozonReturnId); |
| | | 329 | | |
| | | 330 | | public async Task<List<OrderReturn>> GetByOrderIdAsync(int orderId) => |
| | 0 | 331 | | await _repository.GetByOrderIdAsync(orderId); |
| | | 332 | | |
| | | 333 | | public async Task<List<OrderReturn>> GetByOrderIdsAsync(IEnumerable<int> orderIds) => |
| | 0 | 334 | | await _repository.GetByOrderIdsAsync(orderIds); |
| | | 335 | | |
| | | 336 | | public async Task<List<OrderReturn>> GetByPostingNumberAsync(string postingNumber) => |
| | 0 | 337 | | await _repository.GetByPostingNumberAsync(postingNumber); |
| | | 338 | | |
| | | 339 | | public async Task<(List<OrderReturn> Items, int Total)> GetByOzonClientIdAsync( |
| | | 340 | | int ozonClientId, |
| | | 341 | | int skip = 0, |
| | | 342 | | int take = 50, |
| | | 343 | | string? statusSysName = null, |
| | | 344 | | string? postingNumber = null, |
| | | 345 | | string? orderNumber = null, |
| | | 346 | | string? returnReasonName = null, |
| | | 347 | | int? orderId = null, |
| | | 348 | | DateTime? fromDate = null, |
| | | 349 | | DateTime? toDate = null) |
| | | 350 | | { |
| | 0 | 351 | | IEnumerable<int>? clientIdsFilter = null; |
| | 0 | 352 | | if (!orderId.HasValue && ozonClientId <= 0) |
| | | 353 | | { |
| | 0 | 354 | | var clients = await _ozonClientServices.GetOzonClients(); |
| | 0 | 355 | | var ozonClientIds = clients.Where(c => c.ClientType == ClientType.OZON).Select(c => c.Id).ToList(); |
| | 0 | 356 | | if (ozonClientIds.Count > 0) |
| | 0 | 357 | | clientIdsFilter = ozonClientIds; |
| | | 358 | | } |
| | | 359 | | |
| | 0 | 360 | | return await _repository.GetByOzonClientIdAsync( |
| | 0 | 361 | | ozonClientId, skip, take, statusSysName, postingNumber, orderNumber, returnReasonName, orderId, fromDate, to |
| | 0 | 362 | | } |
| | | 363 | | |
| | | 364 | | public async Task<List<OrderReturn>> Get() => |
| | 0 | 365 | | await _repository.Get(); |
| | | 366 | | |
| | | 367 | | public async Task<int> Add(OrderReturn value) => |
| | 0 | 368 | | await _repository.Add(value); |
| | | 369 | | |
| | | 370 | | public async Task<int> Update(OrderReturn value) => |
| | 0 | 371 | | await _repository.Update(value); |
| | | 372 | | |
| | | 373 | | public async Task<int> Delete(OrderReturn value) => |
| | 0 | 374 | | await _repository.Delete(value); |
| | | 375 | | } |
| | | 376 | | |
| | | 377 | | /// <summary>Итог синхронизации одного батча возвратов.</summary> |
| | | 378 | | /// <param name="Processed">Сколько записей пришло из API.</param> |
| | | 379 | | /// <param name="Inserted">Из них создано впервые.</param> |
| | | 380 | | /// <param name="StatusChanged">У скольких изменился статус возврата или компенсации (включая новые).</param> |
| | | 381 | | /// <param name="LinkedOrders">Сколько заказов сопоставлено с возвратами в этом батче.</param> |
| | | 382 | | public sealed record ReturnsSyncResult(int Processed, int Inserted, int StatusChanged, int LinkedOrders) |
| | | 383 | | { |
| | | 384 | | public static readonly ReturnsSyncResult Empty = new(0, 0, 0, 0); |
| | | 385 | | } |