From 83df6abc46d7ae48ee6d3e6afcfead9757680d7c Mon Sep 17 00:00:00 2001 From: yanghongwei Date: Sat, 16 Aug 2025 17:33:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=BC=93=E5=AD=98=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=97=B6=E9=95=BF=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/DateTimeHelper.cs | 23 +++++++++++++++++++++++ Controllers/HomeController.cs | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 Common/DateTimeHelper.cs diff --git a/Common/DateTimeHelper.cs b/Common/DateTimeHelper.cs new file mode 100644 index 0000000..c6b1c8d --- /dev/null +++ b/Common/DateTimeHelper.cs @@ -0,0 +1,23 @@ +namespace LY.App.Common +{ + /// + /// 日期时间帮助类 + /// + public static class DateTimeHelper + { + + /// + /// //当前剩余秒数 + /// + /// + public static int GetRemainSeconds() + { + // 当前时间 + DateTime now = DateTime.Now; + // 当天结束时间(23:59:59.999) + DateTime endOfDay = now.Date.AddDays(1).AddTicks(-1); + int remainSeconds = (int)(endOfDay - DateTime.Now).TotalSeconds; + return remainSeconds; + } + } +} diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index c63b487..963c047 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -1,4 +1,5 @@ -using LY.App.Common.Redis; +using LY.App.Common; +using LY.App.Common.Redis; using LY.App.Device; using LY.App.Model; using LY.App.Service; @@ -48,7 +49,7 @@ namespace LY.App.Controllers var positions = await _positionService.Index(); var alarmCount = await _redisService.GetOrSetAsync(RedisKeyList.index_data(), async () => await _alarmService.IndexCount(), - TimeSpan.FromDays(1)); + TimeSpan.FromSeconds(DateTimeHelper.GetRemainSeconds())); var weather = await _redisService.GetOrSetAsync(RedisKeyList.Index_Weather, async () => await _weatherService.GetWeather(), TimeSpan.FromHours(3));