From 9dfb8dea7f073e9c132096c076a70ec18c6cb408 Mon Sep 17 00:00:00 2001 From: H Vs Date: Mon, 5 Aug 2024 11:33:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Resolver/PregnancyHeartRateResolver.cs | 46 +++---------------- 1 file changed, 7 insertions(+), 39 deletions(-) diff --git a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs index 585912d..a81c37e 100644 --- a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs +++ b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs @@ -642,23 +642,22 @@ namespace HealthMonitor.Service.Resolver if (string.IsNullOrWhiteSpace(schedule_push)) { // 注册首次下推 -#if DEBUG - // await _serviceEtcd.PutValAsync(key, result, 60*1, false).ConfigureAwait(false); - var interval = 0; // 获取当前时间 DateTime now = DateTime.Now; - + var rand = new Random(); + var pushSec = rand.Next(59); + int pushMin = int.TryParse(heartRate.Serialno.AsSpan(heartRate.Serialno.Length - 1), out pushMin) ? pushMin : 10; // 计算距离下一个$interval天后的8点的时间间隔 - DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute + 1, 58).AddDays(interval); + DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, 6, pushMin, pushSec).AddDays(interval); TimeSpan timeUntilNextRun = nextRunTime - now; - // 如果当前时间已经超过了8点,将等待到明天后的8点 if (timeUntilNextRun < TimeSpan.Zero) { - timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromMinutes(1)); - nextRunTime += timeUntilNextRun; + timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1)); + nextRunTime += TimeSpan.FromDays(1); } + var ttl = (long)timeUntilNextRun.TotalSeconds; var data = new { @@ -670,37 +669,6 @@ namespace HealthMonitor.Service.Resolver var result = JsonConvert.SerializeObject(data); await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); -#else - - var interval = 0; - // 获取当前时间 - DateTime now = DateTime.Now; - var rand=new Random(); - var pushSec = rand.Next(59); - int pushMin= int.TryParse(heartRate.Serialno.AsSpan(heartRate.Serialno.Length - 1), out pushMin) ? pushMin : 10; - // 计算距离下一个$interval天后的8点的时间间隔 - DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, 6, pushMin, pushSec).AddDays(interval); - TimeSpan timeUntilNextRun = nextRunTime - now; - - - if (timeUntilNextRun < TimeSpan.Zero) - { - timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1)); - nextRunTime += TimeSpan.FromDays(1); - } - - var ttl =(long)timeUntilNextRun.TotalSeconds; - var data = new - { - imei = heartRate.Serialno, - create_time = now.ToString("yyyy-MM-dd HH:mm:ss"), - ttl, - next_run_time = nextRunTime.ToString("yyyy-MM-dd HH:mm:ss") - }; - var result = JsonConvert.SerializeObject(data); - await _serviceEtcd.PutValAsync(key, result,ttl, false).ConfigureAwait(false); -#endif - } #endregion