49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Quartz;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WMS.Web.Domain.IService;
|
|
|
|
namespace WMS.Web.Domain.QuartzJob
|
|
{
|
|
//成品即时库存
|
|
public class InventoryQuartzJob : IJob
|
|
{
|
|
private readonly ILogger<InventoryQuartzJob> _logger;
|
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
private readonly IProductInventoryService _productInventoryService;
|
|
|
|
public InventoryQuartzJob(ILogger<InventoryQuartzJob> logger,
|
|
IServiceScopeFactory serviceScopeFactory, IProductInventoryService productInventoryService)
|
|
{
|
|
this._logger = logger;
|
|
_serviceScopeFactory = serviceScopeFactory;
|
|
_productInventoryService = productInventoryService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行方法
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <returns></returns>
|
|
public async Task Execute(IJobExecutionContext context)
|
|
{
|
|
try
|
|
{
|
|
if (DateTime.Now.Hour < 8 || DateTime.Now.Hour > 20) return;
|
|
|
|
_logger.LogInformation($"同步成品即时库存->开始定时任务");
|
|
var result = await _productInventoryService.Refresh();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogInformation($"同步成品即时库存:定时任务执行失败->{ex.Message}");
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|