| | | 1 | | using Newtonsoft.Json; |
| | | 2 | | using Newtonsoft.Json.Linq; |
| | | 3 | | using Services.ApiServices.ArmtekApi.Converters; |
| | | 4 | | |
| | | 5 | | namespace Services.ApiServices.ArmtekApi.Models.Response; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// getOrder2?STATUS=1 — RESP.STATUSES. Armtek возвращает это поле как объект с группами статусов |
| | | 9 | | /// либо как массив (в частности, <c>[]</c> для заказа без детализации). Конвертер поддерживает |
| | | 10 | | /// обе формы и не даёт штатному пустому массиву сорвать синхронизацию всего заказа. |
| | | 11 | | /// </summary> |
| | | 12 | | public class ArmtekOrderStatuses |
| | | 13 | | { |
| | | 14 | | [JsonProperty("Processing")] |
| | | 15 | | [JsonConverter(typeof(ArmtekResultsAsListConverter<ArmtekProcessingSubStatus>))] |
| | | 16 | | public List<ArmtekProcessingSubStatus> Processing { get; set; } = new(); |
| | | 17 | | |
| | | 18 | | [JsonProperty("Ready")] |
| | | 19 | | [JsonConverter(typeof(ArmtekResultsAsListConverter<ArmtekReadyStatus>))] |
| | | 20 | | public List<ArmtekReadyStatus> Ready { get; set; } = new(); |
| | | 21 | | |
| | | 22 | | [JsonProperty("Delivered")] |
| | | 23 | | [JsonConverter(typeof(ArmtekResultsAsListConverter<ArmtekDeliveredStatus>))] |
| | | 24 | | public List<ArmtekDeliveredStatus> Delivered { get; set; } = new(); |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary>Принимает объект STATUSES и массив объектов STATUSES, объединяя группы статусов.</summary> |
| | | 28 | | public sealed class ArmtekOrderStatusesConverter : JsonConverter<ArmtekOrderStatuses?> |
| | | 29 | | { |
| | | 30 | | public override ArmtekOrderStatuses? ReadJson(JsonReader reader, Type objectType, ArmtekOrderStatuses? existingValue |
| | | 31 | | bool hasExistingValue, JsonSerializer serializer) |
| | | 32 | | { |
| | | 33 | | if (reader.TokenType == JsonToken.Null) |
| | | 34 | | return null; |
| | | 35 | | |
| | | 36 | | var token = JToken.Load(reader); |
| | | 37 | | if (token.Type == JTokenType.Object) |
| | | 38 | | return token.ToObject<ArmtekOrderStatuses>(serializer); |
| | | 39 | | |
| | | 40 | | if (token.Type != JTokenType.Array) |
| | | 41 | | return new ArmtekOrderStatuses(); |
| | | 42 | | |
| | | 43 | | var combined = new ArmtekOrderStatuses(); |
| | | 44 | | foreach (var entry in token.Children<JObject>()) |
| | | 45 | | { |
| | | 46 | | var statuses = entry.ToObject<ArmtekOrderStatuses>(serializer); |
| | | 47 | | if (statuses is null) |
| | | 48 | | continue; |
| | | 49 | | |
| | | 50 | | combined.Processing.AddRange(statuses.Processing); |
| | | 51 | | combined.Ready.AddRange(statuses.Ready); |
| | | 52 | | combined.Delivered.AddRange(statuses.Delivered); |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | return combined; |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | public override void WriteJson(JsonWriter writer, ArmtekOrderStatuses? value, JsonSerializer serializer) => |
| | | 59 | | serializer.Serialize(writer, value); |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | /// <summary>Planned / Waiting / Confirmed / Shipped / WayQuan.</summary> |
| | | 63 | | public class ArmtekProcessingSubStatus |
| | | 64 | | { |
| | 6 | 65 | | [JsonProperty("SubStatus")] public string SubStatus { get; set; } = string.Empty; |
| | | 66 | | |
| | | 67 | | [JsonProperty("KWMENG")] |
| | | 68 | | [JsonConverter(typeof(ArmtekFlexibleStringConverter))] |
| | 0 | 69 | | public string? Kwmeng { get; set; } |
| | | 70 | | |
| | 2 | 71 | | [JsonProperty("Werks")] public string Werks { get; set; } = string.Empty; |
| | 2 | 72 | | [JsonProperty("WerksName")] public string WerksName { get; set; } = string.Empty; |
| | 2 | 73 | | [JsonProperty("LsegETP")] public string LsegEtp { get; set; } = string.Empty; |
| | 2 | 74 | | [JsonProperty("Date")] public string Date { get; set; } = string.Empty; |
| | 3 | 75 | | [JsonProperty("ExpectedDate")] public string ExpectedDate { get; set; } = string.Empty; |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | /// <summary>Готово к отгрузке на складе, ожидает комплектации.</summary> |
| | | 79 | | public class ArmtekReadyStatus |
| | | 80 | | { |
| | | 81 | | [JsonProperty("DELIVERY")] public string DeliveryNumber { get; set; } = string.Empty; |
| | | 82 | | [JsonProperty("DELIVERY_DATE")] public string DeliveryDate { get; set; } = string.Empty; |
| | | 83 | | |
| | | 84 | | [JsonProperty("KWMENG")] |
| | | 85 | | [JsonConverter(typeof(ArmtekFlexibleStringConverter))] |
| | | 86 | | public string? Kwmeng { get; set; } |
| | | 87 | | |
| | | 88 | | [JsonProperty("Werks")] public string Werks { get; set; } = string.Empty; |
| | | 89 | | [JsonProperty("ExpectedDate")] public string ExpectedDate { get; set; } = string.Empty; |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | /// <summary>Отгружено — привязка к фактуре.</summary> |
| | | 93 | | public class ArmtekDeliveredStatus |
| | | 94 | | { |
| | | 95 | | [JsonProperty("INVOICE")] public string Invoice { get; set; } = string.Empty; |
| | | 96 | | [JsonProperty("INVOICE_DATE")] public string InvoiceDate { get; set; } = string.Empty; |
| | | 97 | | |
| | | 98 | | [JsonProperty("KWMENG")] |
| | | 99 | | [JsonConverter(typeof(ArmtekFlexibleStringConverter))] |
| | | 100 | | public string? Kwmeng { get; set; } |
| | | 101 | | |
| | | 102 | | [JsonProperty("SUMMA")] |
| | | 103 | | [JsonConverter(typeof(ArmtekFlexibleStringConverter))] |
| | | 104 | | public string? Summa { get; set; } |
| | | 105 | | |
| | | 106 | | [JsonProperty("CURRENCY")] public string Currency { get; set; } = string.Empty; |
| | | 107 | | [JsonProperty("DELIVERY")] public string DeliveryNumber { get; set; } = string.Empty; |
| | | 108 | | } |