using DS.WMS.Core.Jobs;
using DS.WMS.Core.QuarztJobs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using Quartz.AspNetCore;
namespace DS.Module.QuartzModuleInstall
{
public static class QuartzModuleInstall
{
///
/// 添加费用模块定时任务
///
///
///
public static void AddFeeQuartzModuleInstall(this IServiceCollection services, IConfiguration configuration)
{
//获取进项发票
var jobKey = new JobKey("InInvoice");
services.AddQuartz(q =>
{
// 配置 Quartz
q.UseMicrosoftDependencyInjectionJobFactory();
q.AddJob(opts => opts.WithIdentity(jobKey));
q.AddTrigger(opts => opts
.ForJob(jobKey)
.WithIdentity("InInvoice-trigger")
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(60)
.RepeatForever()));
});
//获取银行流水
var BankStatementKey = new JobKey("BankStatement");
services.AddQuartz(q =>
{
// 配置 Quartz
q.UseMicrosoftDependencyInjectionJobFactory();
q.AddJob(opts => opts.WithIdentity(BankStatementKey));
q.AddTrigger(opts => opts
.ForJob(BankStatementKey)
.WithIdentity("BankStatement-trigger")
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(60)
.RepeatForever()));
});
var jobKey3 = new JobKey(nameof(FeeCustTemplateJob));
services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionJobFactory();
q.AddJob(opts => opts.WithIdentity(jobKey3));
q.AddTrigger(opts => opts
.ForJob(jobKey3)
.WithIdentity(nameof(FeeCustTemplateJob) + "-trigger")
.WithCronSchedule(configuration["JobConfig:" + jobKey3.Name])
);
});
// 添加 Quartz 主机服务
services.AddQuartzServer(q => q.WaitForJobsToComplete = true);
}
///
/// 添加操作模块定时任务
///
///
///
public static void AddOpQuartzModuleInstall(this IServiceCollection services, IConfiguration configuration)
{
var jobKey1 = new JobKey(nameof(WSLReportJob));
services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionJobFactory();
q.AddJob(opts => opts.WithIdentity(jobKey1));
q.AddTrigger(opts => opts
.ForJob(jobKey1)
.WithIdentity(nameof(WSLReportJob) + "-trigger")
.WithCronSchedule(configuration["JobConfig:" + jobKey1.Name])
);
});
//var jobKey2 = new JobKey(nameof(WSLWeeklyReportJob));
//services.AddQuartz(q =>
//{
// q.UseMicrosoftDependencyInjectionJobFactory();
// q.AddJob(opts => opts.WithIdentity(jobKey2));
// q.AddTrigger(opts => opts
// .ForJob(jobKey2)
// .WithIdentity(nameof(WSLWeeklyReportJob) + "-trigger")
// .WithCronSchedule(configuration["JobConfig:" + jobKey2.Name])
// );
//});
//var jobKey2 = new JobKey(nameof(BackgroundTaskJob));
//services.AddQuartz(q =>
//{
// // 配置 Quartz
// q.UseMicrosoftDependencyInjectionJobFactory();
// q.AddJob(opts => opts.WithIdentity(jobKey2));
// q.AddTrigger(opts => opts
// .ForJob(jobKey2)
// .WithIdentity(nameof(BackgroundTaskJob) + "-trigger")
// .WithSimpleSchedule(x => x
// .WithIntervalInMinutes(2)
// .RepeatForever()));
//});
services.AddQuartzServer(q => q.WaitForJobsToComplete = true);
}
}
}