From 44ee10e2ff51109ce5e466b18caba3ca6673dc68 Mon Sep 17 00:00:00 2001 From: tongfei <244188119@qq.com> Date: Mon, 8 Apr 2024 14:53:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=96=B0=E7=89=A9=E6=96=99?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WMS.Web.Api/Controllers/TestController.cs | 4 ++ src/WMS.Web.Api/appsettings.json | 1 + src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml | 6 +++ src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml | 17 ++++++++ .../Options/QuartzJobOptions.cs | 4 ++ .../QuartzJob/MaterialsQuartzJob.cs | 40 +++++++++++++++++++ .../DependencyInjection/AppBuilder.cs | 13 ++++++ 7 files changed, 85 insertions(+) create mode 100644 src/WMS.Web.Domain/QuartzJob/MaterialsQuartzJob.cs diff --git a/src/WMS.Web.Api/Controllers/TestController.cs b/src/WMS.Web.Api/Controllers/TestController.cs index 2f1ca3aa..f9830953 100644 --- a/src/WMS.Web.Api/Controllers/TestController.cs +++ b/src/WMS.Web.Api/Controllers/TestController.cs @@ -344,6 +344,10 @@ namespace WMS.Web.Api.Controllers return await _sendMessageService.Execute(); } + /// + /// 同步新物料-和修改已启用批号管理的物料 + /// + /// [HttpGet] [Route("SyscMats")] public async Task SyscMats() diff --git a/src/WMS.Web.Api/appsettings.json b/src/WMS.Web.Api/appsettings.json index ae231610..e1d7dc71 100644 --- a/src/WMS.Web.Api/appsettings.json +++ b/src/WMS.Web.Api/appsettings.json @@ -87,6 +87,7 @@ "JobStartExpre": "0 0/30 * * * ?", "JobStartExpreAmount": "0 50 23 * * ?", "JobStartExpreSend": "0 0 12,16,20 * * ?", + "JobStartExpreMaterial": "0 30 23 * * ?", //a.是否启用集群:键和值 "JobStoreClusteredKey": "quartz.jobStore.clustered", diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml index cfb253b0..e7baa55d 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml @@ -786,5 +786,11 @@ + + + 同步新物料-和修改已启用批号管理的物料 + + + diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 9d313b43..7a291d13 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -4529,6 +4529,11 @@ 发送通知执行cron表达式:每天12,16,20整点发送 + + + 同步新物料执行cron表达式:每天23:30整点同步 + + 是否启用集群:键 @@ -4653,6 +4658,18 @@ + + + 物料同步执行定时任务 + + + + + 执行方法 + + + + 执行方法 diff --git a/src/WMS.Web.Domain/Options/QuartzJobOptions.cs b/src/WMS.Web.Domain/Options/QuartzJobOptions.cs index 89d5a6da..b5d826eb 100644 --- a/src/WMS.Web.Domain/Options/QuartzJobOptions.cs +++ b/src/WMS.Web.Domain/Options/QuartzJobOptions.cs @@ -95,6 +95,10 @@ namespace WMS.Web.Domain.Options /// public string JobStartExpreSend { get; set; } + /// + /// 同步新物料执行cron表达式:每天23:30整点同步 + /// + public string JobStartExpreMaterial { get; set; } /// /// 是否启用集群:键 diff --git a/src/WMS.Web.Domain/QuartzJob/MaterialsQuartzJob.cs b/src/WMS.Web.Domain/QuartzJob/MaterialsQuartzJob.cs new file mode 100644 index 00000000..cc5cd807 --- /dev/null +++ b/src/WMS.Web.Domain/QuartzJob/MaterialsQuartzJob.cs @@ -0,0 +1,40 @@ +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 MaterialsQuartzJob : IJob + { + private readonly ILogger _logger; + private readonly IServiceScopeFactory _serviceScopeFactory; + private readonly IMaterialService _materialService; + + public MaterialsQuartzJob(ILogger logger, + IServiceScopeFactory serviceScopeFactory, + IMaterialService materialService) + { + this._logger = logger; + _serviceScopeFactory = serviceScopeFactory; + _materialService = materialService; + } + + /// + /// 执行方法 + /// + /// + /// + public async Task Execute(IJobExecutionContext context) + { + await _materialService.SyncNewMaterials(); + } + } +} diff --git a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs index a208820a..710ee8a0 100644 --- a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs +++ b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs @@ -197,6 +197,7 @@ namespace WMS.Web.Repositories.DependencyInjection Services.AddTransient();//添加注入定时服务 Services.AddTransient();//添加注入定时服务 Services.AddTransient();//添加注入定时服务 + Services.AddTransient();//添加注入定时服务 //Services.AddTransient();//添加注入定时服务 Services.AddQuartz(q => { @@ -272,6 +273,18 @@ namespace WMS.Web.Repositories.DependencyInjection //.WithCronSchedule(CronScheduleBuilder.DailyAtHourAndMinute(options.JobStartHour[5], options.JobStartMinute[5])) .WithDescription("SendQuartzJobTriggerDecs")); #endregion + + #region 同步新物料信息 + var jobKey_material = new JobKey("MaterialsQuartzJob", options.QuartzJobValue); + q.AddJob(jobKey_material, j => j.WithDescription("MaterialsQuartzJob")); + q.AddTrigger(t => t + .WithIdentity("MaterialsQuartzJobTrigger") + .ForJob(jobKey_material) + .StartNow() + .WithCronSchedule(options.JobStartExpreMaterial) + //.WithCronSchedule(CronScheduleBuilder.DailyAtHourAndMinute(options.JobStartHour[5], options.JobStartMinute[5])) + .WithDescription("MaterialsQuartzJobTriggerDecs")); + #endregion }); //.net core核心托管-添加Quartz服务器 Services.AddQuartzServer(options =>