| | | 1 | | using Hangfire; |
| | | 2 | | using Services.HangfireService; |
| | | 3 | | using SlqStudio.Application.Services.EmailService; |
| | | 4 | | |
| | | 5 | | namespace Services.BitrixStockServices; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Формирует Excel-отчёт синхронизации остатков и отправляет его на lex@interparts.ru. |
| | | 9 | | /// Запускается автоматически после завершения BuildReportAsync для каждого пресета. |
| | | 10 | | /// </summary> |
| | 10 | 11 | | public class SendSyncReportEmailJob( |
| | 10 | 12 | | IBitrixStockSyncReportService reportService, |
| | 10 | 13 | | IEmailService emailService) |
| | | 14 | | { |
| | | 15 | | private const string RecipientEmail = "lex@interparts.ru"; |
| | | 16 | | public const string QueueName = HangfireQueueNames.Main; |
| | | 17 | | |
| | | 18 | | [Queue(QueueName)] |
| | | 19 | | public async Task ExecuteAsync(string reportId, string presetName, CancellationToken ct = default) |
| | | 20 | | { |
| | 7 | 21 | | var (bytes, filename) = await BitrixStockSyncReportExcelBuilder.BuildAsync( |
| | 7 | 22 | | reportService, reportId, ct: ct); |
| | | 23 | | |
| | 14 | 24 | | if (bytes == null || bytes.Length == 0) return; |
| | | 25 | | |
| | 0 | 26 | | var subject = $"[Авто] Отчёт синхронизации: {presetName} — {BitrixStockMskDateTime.FormatNow()}"; |
| | 0 | 27 | | var body = $"Автоматический отчёт синхронизации остатков Ozon.\n" + |
| | 0 | 28 | | $"Пресет: {presetName}\n" + |
| | 0 | 29 | | $"Файл во вложении: {filename}"; |
| | | 30 | | |
| | 0 | 31 | | await emailService.SendEmailWithAttachmentAsync( |
| | 0 | 32 | | RecipientEmail, subject, body, bytes, filename, |
| | 0 | 33 | | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | 7 | 34 | | } |
| | | 35 | | } |