首页缓存计算时长调整

This commit is contained in:
yanghongwei 2025-08-16 17:33:02 +08:00
parent f94bdcc506
commit 83df6abc46
2 changed files with 26 additions and 2 deletions

23
Common/DateTimeHelper.cs Normal file
View File

@ -0,0 +1,23 @@
namespace LY.App.Common
{
/// <summary>
/// 日期时间帮助类
/// </summary>
public static class DateTimeHelper
{
/// <summary>
/// //当前剩余秒数
/// </summary>
/// <returns></returns>
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;
}
}
}

View File

@ -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.Device;
using LY.App.Model; using LY.App.Model;
using LY.App.Service; using LY.App.Service;
@ -48,7 +49,7 @@ namespace LY.App.Controllers
var positions = await _positionService.Index(); var positions = await _positionService.Index();
var alarmCount = await _redisService.GetOrSetAsync(RedisKeyList.index_data(), var alarmCount = await _redisService.GetOrSetAsync(RedisKeyList.index_data(),
async () => await _alarmService.IndexCount(), async () => await _alarmService.IndexCount(),
TimeSpan.FromDays(1)); TimeSpan.FromSeconds(DateTimeHelper.GetRemainSeconds()));
var weather = await _redisService.GetOrSetAsync(RedisKeyList.Index_Weather, var weather = await _redisService.GetOrSetAsync(RedisKeyList.Index_Weather,
async () => await _weatherService.GetWeather(), async () => await _weatherService.GetWeather(),
TimeSpan.FromHours(3)); TimeSpan.FromHours(3));