45 lines
1.4 KiB
C#
Raw Normal View History

2025-03-17 08:35:19 +08:00
using JiShe.CollectBus.IotSystems.Records;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2025-03-18 13:56:38 +08:00
using JiShe.CollectBus.Common.Consts;
2025-03-17 15:51:40 +08:00
using JiShe.CollectBus.EnergySystems.TableViews;
using JiShe.CollectBus.FreeSql;
2025-03-17 08:35:19 +08:00
using Volo.Abp.Domain.Repositories;
2025-03-17 15:51:40 +08:00
using JiShe.CollectBus.IotSystems.PrepayModel;
2025-03-17 08:35:19 +08:00
namespace JiShe.CollectBus.EnergySystem
{
2025-03-17 15:51:40 +08:00
public class CacheAppService : CollectBusAppService, ICacheAppService
2025-03-17 08:35:19 +08:00
{
2025-03-17 15:51:40 +08:00
//public async Task<V_FocusAmmeter> GetHashByKey(string key)
//{
// await FreeRedisProvider.Instance.HGetAsync<V_FocusAmmeter>(key,);
//}
2025-03-17 08:35:19 +08:00
2025-03-17 15:51:40 +08:00
public async Task SetHashByKey(string key)
{
var data = await SqlProvider.Instance.Change(DbEnum.EnergyDB).Select<V_FocusAmmeter>().ToListAsync();
var groupData = data.GroupBy(a => $"{a.FocusAreaCode}{a.FocusAddress}").ToList();
foreach (var group in groupData)
{
2025-03-18 13:56:38 +08:00
try
{
var aa = group.ToDictionary(a => $"{a.ID}_{a.Address}" , b => b);
await FreeRedisProvider.Instance.HSetAsync($"{RedisConst.CacheAmmeterFocusKey}:{group.Key}", aa);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
2025-03-17 15:51:40 +08:00
}
}
2025-03-17 08:35:19 +08:00
}
}