S5InventoryDailyReconJob.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Admin.NET.Plugin.AiDOP.MaterialWarehouse;
  2. using Furion.Schedule;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Logging;
  5. namespace Admin.NET.Plugin.AiDOP.Job;
  6. /// <summary>S5 库存日终对账:每天 01:15,165 vs mdp_std_inventory。</summary>
  7. [JobDetail("job_s5_inventory_daily_recon",
  8. Description = "S5库存日终对账",
  9. GroupName = "default", Concurrent = false)]
  10. [Cron("15 1 * * *",
  11. TriggerId = "trigger_s5_inventory_daily_recon",
  12. Description = "每天01:15")]
  13. public sealed class S5InventoryDailyReconJob : IJob
  14. {
  15. private readonly IServiceScopeFactory _scopeFactory;
  16. private readonly ILogger _logger;
  17. public S5InventoryDailyReconJob(IServiceScopeFactory scopeFactory, ILoggerFactory loggerFactory)
  18. {
  19. _scopeFactory = scopeFactory;
  20. _logger = loggerFactory.CreateLogger(nameof(S5InventoryDailyReconJob));
  21. }
  22. public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
  23. {
  24. if (!AidopJobGate.ShouldRun(nameof(S5InventoryDailyReconJob), _logger)) return;
  25. using var scope = _scopeFactory.CreateScope();
  26. var recon = scope.ServiceProvider.GetRequiredService<InventoryReconService>();
  27. try
  28. {
  29. var diffs = await recon.RunDailyReconAsync(stoppingToken);
  30. _logger.LogInformation("[S5InventoryDailyReconJob] done diffs={Diffs}", diffs);
  31. }
  32. catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
  33. {
  34. throw;
  35. }
  36. catch (Exception ex)
  37. {
  38. _logger.LogError(ex, "[S5InventoryDailyReconJob] failed");
  39. }
  40. }
  41. }