| | | 1 | | using System.Globalization; |
| | | 2 | | using System.Text; |
| | | 3 | | |
| | | 4 | | namespace Services.TransactionCommentAi; |
| | | 5 | | |
| | | 6 | | public static class TransactionCommentAiFallbackFormatter |
| | | 7 | | { |
| | 1 | 8 | | private static readonly CultureInfo Ru = CultureInfo.GetCultureInfo("ru-RU"); |
| | 1 | 9 | | private static readonly TimeZoneInfo RussianTimeZone = TimeZoneInfo.FindSystemTimeZoneById( |
| | 1 | 10 | | OperatingSystem.IsWindows() ? "Russian Standard Time" : "Europe/Moscow"); |
| | | 11 | | |
| | | 12 | | public static string Format(TransactionCommentAiContext context) |
| | | 13 | | { |
| | 5 | 14 | | var sb = new StringBuilder(); |
| | 5 | 15 | | var performedLocal = TimeZoneInfo.ConvertTimeFromUtc( |
| | 5 | 16 | | DateTime.SpecifyKind(context.PerformedAtUtc, DateTimeKind.Utc), |
| | 5 | 17 | | RussianTimeZone); |
| | | 18 | | |
| | 5 | 19 | | sb.AppendLine($"Тип: {context.TransactionTypeDisplayName} ({context.TransactionType})"); |
| | 5 | 20 | | sb.AppendLine( |
| | 5 | 21 | | $"Когда: {context.PerformedAtUtc:dd.MM.yyyy, HH:mm:ss} (UTC) / {performedLocal:HH:mm} (MSK)"); |
| | 5 | 22 | | sb.AppendLine($"Пользователь: {context.UserName}"); |
| | 5 | 23 | | sb.AppendLine(); |
| | | 24 | | |
| | 5 | 25 | | sb.AppendLine("Что произошло"); |
| | 5 | 26 | | sb.AppendLine( |
| | 5 | 27 | | $"Проведение: {context.Batch.TotalOrders} заказ(ов), отменено {context.Batch.CancelledCount}, статус «{conte |
| | | 28 | | |
| | 5 | 29 | | var first = context.Orders.FirstOrDefault(); |
| | 5 | 30 | | if (first != null) |
| | | 31 | | { |
| | 4 | 32 | | sb.AppendLine($"Заказ: {first.ShipmentNumber ?? first.OrderId.ToString(Ru)}"); |
| | 4 | 33 | | if (!string.IsNullOrWhiteSpace(first.Article)) |
| | 4 | 34 | | sb.AppendLine($"Товар: {first.Article}, qty {first.Quantity ?? 0}"); |
| | | 35 | | } |
| | | 36 | | |
| | 5 | 37 | | if (context.Batch.SplitCount > 0) |
| | 1 | 38 | | sb.AppendLine($"⚠ Split: {context.Batch.SplitCount} строк с частичным количеством."); |
| | | 39 | | |
| | 5 | 40 | | if (context.OneC?.Documents.Count > 0) |
| | | 41 | | { |
| | 1 | 42 | | var docs = string.Join(", ", context.OneC.Documents |
| | 1 | 43 | | .Select(d => d.DocumentNumber ?? d.TransactionId) |
| | 2 | 44 | | .Where(x => !string.IsNullOrWhiteSpace(x))); |
| | 1 | 45 | | sb.AppendLine($"1С: документы {docs}"); |
| | | 46 | | } |
| | | 47 | | |
| | 5 | 48 | | if (context.OzonShip is { Entries.Count: > 0 } ozon) |
| | | 49 | | { |
| | 1 | 50 | | sb.AppendLine( |
| | 1 | 51 | | $"Ozon: успешно {ozon.SuccessCount}, ошибок {ozon.FailedCount}, пропущено {ozon.SkippedCount}."); |
| | | 52 | | } |
| | | 53 | | |
| | 5 | 54 | | sb.AppendLine("(Авто-описание без AI — сервис генерации временно недоступен.)"); |
| | 5 | 55 | | return sb.ToString().Trim(); |
| | | 56 | | } |
| | | 57 | | } |