using JiShe.CollectBus.EnergySystems.TableViews;

namespace JiShe.CollectBus.EnergySystem
{
    public class CacheAppService : CollectBusAppService, ICacheAppService
    {
        public async Task SetHashByKey()
        {
            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)
            {
                await FreeRedisProvider.Instance.HSetAsync($"{RedisConst.CacheAmmeterFocusKey}:{group.Key}", group.ToDictionary(a => $"{a.ID}_{a.Address}", b => b));
            }
        }
    }
}
