From ee66d46595064c37ef383673537a2f55e2207efb Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Wed, 7 Jun 2023 15:50:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=90=AF=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E4=B8=8D=E7=AB=8B=E5=8D=B3?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=20=E4=BF=AE=E6=94=B9=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=97=B6=E7=AB=8B=E5=8D=B3=E7=94=9F=E6=95=88?= =?UTF-8?q?=20=E7=94=9F=E6=88=90=E7=82=B9=E5=B7=A1=E6=A3=80=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E7=B2=BE=E5=BA=A6=E8=A1=A5=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Listener/GenerateSpotInspectionPlanTimeWorker.cs | 7 ++++++- taskschedule/Tnb.TaskScheduler/TimeTaskService.cs | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs index fbce46ad..37857265 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs @@ -60,13 +60,18 @@ namespace JNPF.TaskScheduler.Listener // } // } + //丢失精度补齐 例如设定10分钟执行 但是这个破框架会再9:59 时进入这个方法导致不能正常执行 + //精确到分的定时任务可以不使用本地任务 采用数据接口的方式规避掉这个问题 + int second = DateTime.Now.Second;//当前的秒数 + int offsetMinute = second > 30 ? 1 : 0; + //整除表示一个周期到了 foreach (var item in eqpSpotInsTemEquipHsByCirculate) { TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm")).Ticks); TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(item.start_time.ToString("yyyy-MM-dd HH:mm")).Ticks); TimeSpan ts3 = ts1.Subtract(ts2).Duration(); - if (ts3.TotalMinutes * 10 / 60 % (10 * (double)item.plan_cycle)==0) + if ((ts3.TotalMinutes+offsetMinute) * 10 / 60 % (10 * (double)item.plan_cycle)==0) { tobeCreateTemplets.Add(item); } diff --git a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs index b96b3526..14d06b18 100644 --- a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs +++ b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs @@ -284,7 +284,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie // 非多租户模式启动自启任务 if (!KeyVariable.MultiTenancy) { - _repository.AsQueryable().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(AddTimerJob); + _repository.AsQueryable().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(x=>AddTimerJob(x,false));//modifyby zhoukeda 20230607 } } @@ -332,7 +332,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie /// 新增定时任务. /// /// - private async void AddTimerJob(TimeTaskEntity input) + private async void AddTimerJob(TimeTaskEntity input,bool startNow = true) { Action? action = null; ContentModel? comtentModel = input.ExecuteContent.ToObject(); @@ -369,7 +369,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie { interval = (starTime.ParseToDateTime() - DateTime.Now).TotalMilliseconds.ParseToInt(); } - if (taskMethod.StartNow) //modifyby zhoukeda 20230516 + if (startNow) //modifyby zhoukeda 20230516 { SpareTime.DoOnce(interval, action, "Once_" + input.Id); }