| | | 1 | | using OzonDomains.Models; |
| | | 2 | | using OzonOrdersWeb.Areas.Studio2.ViewModels.Bitrix; |
| | | 3 | | |
| | | 4 | | namespace Services.BitrixStockServices; |
| | | 5 | | |
| | | 6 | | public static class BitrixStockAutoFilterFactory |
| | | 7 | | { |
| | | 8 | | public static RemainingStockFilter ResolveForSchedule( |
| | | 9 | | BitrixStockAutoSchedule schedule, |
| | | 10 | | IReadOnlyCollection<string>? activeStores = null) |
| | | 11 | | { |
| | 0 | 12 | | var stored = BitrixStockInventoryService.DeserializeFilter(schedule.FilterJson); |
| | 0 | 13 | | IReadOnlyList<string>? stores = stored.SelectedStoreTitles is { Count: > 0 } |
| | 0 | 14 | | ? stored.SelectedStoreTitles |
| | 0 | 15 | | : null; |
| | | 16 | | |
| | 0 | 17 | | if (string.Equals(schedule.ActionType, BitrixStockAutoActionTypes.Clear, StringComparison.OrdinalIgnoreCase)) |
| | | 18 | | { |
| | 0 | 19 | | return BitrixStockClearFilterTemplate.BuildFilter(schedule.OzonClientId, stores); |
| | | 20 | | } |
| | | 21 | | |
| | 0 | 22 | | return BitrixStockPushFilterTemplate.BuildFilter(schedule.OzonClientId, stores); |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | public static RemainingStockFilter BuildForSave( |
| | | 26 | | string actionType, |
| | | 27 | | int ozonClientId, |
| | | 28 | | IReadOnlyCollection<string>? activeStores, |
| | | 29 | | IReadOnlyList<string>? selectedStoreTitles, |
| | | 30 | | RemainingStockFilter? userExtras = null) |
| | | 31 | | { |
| | 0 | 32 | | var stores = selectedStoreTitles is { Count: > 0 } |
| | 0 | 33 | | ? selectedStoreTitles |
| | 0 | 34 | | : BitrixStockClearFilterTemplate.StoreTitles; |
| | | 35 | | |
| | 0 | 36 | | if (string.Equals(actionType, BitrixStockAutoActionTypes.Clear, StringComparison.OrdinalIgnoreCase)) |
| | | 37 | | { |
| | 0 | 38 | | return BitrixStockClearFilterTemplate.BuildFilter(ozonClientId, stores); |
| | | 39 | | } |
| | | 40 | | |
| | 0 | 41 | | return BitrixStockPushFilterTemplate.BuildFilter(ozonClientId, stores); |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | public static string DescribeFilter(RemainingStockFilter filter, string actionType) |
| | | 45 | | { |
| | 0 | 46 | | var parts = new List<string>(); |
| | 0 | 47 | | if (string.Equals(actionType, BitrixStockAutoActionTypes.Clear, StringComparison.OrdinalIgnoreCase)) |
| | | 48 | | { |
| | 0 | 49 | | parts.Add("OnlyInactive (как на странице остатков)"); |
| | 0 | 50 | | if (filter.OnlyInactive) |
| | | 51 | | { |
| | 0 | 52 | | parts.Add("Active=N"); |
| | 0 | 53 | | parts.Add("Ozon ≥ 1"); |
| | | 54 | | } |
| | | 55 | | } |
| | | 56 | | else |
| | | 57 | | { |
| | 0 | 58 | | parts.Add("OnlyActive (как на странице остатков)"); |
| | 0 | 59 | | if (filter.OnlyActive) |
| | | 60 | | { |
| | 0 | 61 | | parts.Add("Active=Y"); |
| | | 62 | | } |
| | | 63 | | |
| | 0 | 64 | | if (filter.DiffOzonWarehouses) |
| | | 65 | | { |
| | 0 | 66 | | parts.Add("расхождение Ozon / Bitrix"); |
| | | 67 | | } |
| | | 68 | | |
| | 0 | 69 | | if (filter.OzonAmountFrom.HasValue) |
| | | 70 | | { |
| | 0 | 71 | | parts.Add($"Ozon ≥ {filter.OzonAmountFrom.Value}"); |
| | | 72 | | } |
| | | 73 | | } |
| | | 74 | | |
| | 0 | 75 | | if (filter.SelectedStoreTitles?.Count > 0) |
| | | 76 | | { |
| | 0 | 77 | | parts.Add("склады: " + string.Join(", ", filter.SelectedStoreTitles)); |
| | | 78 | | } |
| | | 79 | | |
| | 0 | 80 | | if (filter.SelectedClientId.HasValue) |
| | | 81 | | { |
| | 0 | 82 | | parts.Add("клиент Ozon ID " + filter.SelectedClientId); |
| | | 83 | | } |
| | | 84 | | |
| | 0 | 85 | | return string.Join("; ", parts); |
| | | 86 | | } |
| | | 87 | | } |