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));