140 lines
5.1 KiB
C#
140 lines
5.1 KiB
C#
using FreeRedis;
|
|
using JiShe.CollectBus.Ammeters;
|
|
using JiShe.CollectBus.Common.Consts;
|
|
using JiShe.CollectBus.Watermeter;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Application.Services;
|
|
using static FreeSql.Internal.GlobalFilter;
|
|
|
|
namespace JiShe.CollectBus.Workers
|
|
{
|
|
/// <summary>
|
|
/// 定时采集服务
|
|
/// </summary>
|
|
public abstract class BasicScheduledMeterReadingService : CollectBusAppService, IScheduledMeterReadingService
|
|
{
|
|
/// <summary>
|
|
/// 系统类型
|
|
/// </summary>
|
|
public abstract string SystemType { get; }
|
|
|
|
/// <summary>
|
|
/// 获取电表信息
|
|
/// </summary>
|
|
/// <param name="gatherCode">采集端Code</param>
|
|
/// <returns></returns>
|
|
public virtual Task<List<AmmeterInfo>> GetAmmeterInfoList(string gatherCode = "")
|
|
{
|
|
throw new NotImplementedException($"{nameof(GetAmmeterInfoList)}请根据不同系统类型进行实现");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化电表缓存数据
|
|
/// </summary>
|
|
/// <param name="gatherCode">采集端Code</param>
|
|
/// <returns></returns>
|
|
public virtual async Task InitAmmeterCacheData(string gatherCode = "")
|
|
{
|
|
var meterInfos = await GetAmmeterInfoList(gatherCode);
|
|
if (meterInfos == null || meterInfos.Count <= 0)
|
|
{
|
|
throw new NullReferenceException($"{nameof(InitWatermeterCacheData)} 初始化电表缓存数据时,电表数据为空");
|
|
}
|
|
|
|
//将表计信息根据集中器分组
|
|
var meterInfoGroup = meterInfos.GroupBy(x => x.FocusAddress).ToList();
|
|
foreach (var item in meterInfoGroup)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(item.Key))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var redisCacheKey = $"{string.Format(FreeRedisConst.CacheAmmeterInfoKey, SystemTypeConst.Energy)}{item.Key}";
|
|
Dictionary<string, AmmeterInfo> keyValuePairs = new Dictionary<string, AmmeterInfo>();
|
|
foreach (var subItem in item)
|
|
{
|
|
|
|
keyValuePairs.TryAdd($"{subItem.ID}", subItem);
|
|
}
|
|
await FreeRedisProvider.FreeRedis.HSetAsync(redisCacheKey, keyValuePairs);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取水表信息
|
|
/// </summary>
|
|
/// <param name="gatherCode">采集端Code</param>
|
|
/// <returns></returns>
|
|
public virtual async Task<List<WatermeterInfo>> GetWatermeterInfoList(string gatherCode = "")
|
|
{
|
|
throw new NotImplementedException($"{nameof(GetWatermeterInfoList)}请根据不同系统类型进行实现");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化水表缓存数据
|
|
/// </summary>
|
|
/// <param name="gatherCode">采集端Code</param>
|
|
/// <returns></returns>
|
|
public virtual async Task InitWatermeterCacheData(string gatherCode = "")
|
|
{
|
|
var meterInfos = await GetWatermeterInfoList(gatherCode);
|
|
if (meterInfos == null || meterInfos.Count <= 0)
|
|
{
|
|
throw new NullReferenceException($"{nameof(InitWatermeterCacheData)} 初始化水表缓存数据时,水表数据为空");
|
|
}
|
|
|
|
//将表计信息根据集中器分组
|
|
var meterInfoGroup = meterInfos.GroupBy(x => x.FocusAddress).ToList();
|
|
foreach (var item in meterInfoGroup)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(item.Key))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var redisCacheKey = $"{string.Format(FreeRedisConst.CacheWatermeterInfoKey, SystemTypeConst.Energy)}{item.Key}";
|
|
Dictionary<string, WatermeterInfo> keyValuePairs = new Dictionary<string, WatermeterInfo>();
|
|
foreach (var subItem in item)
|
|
{
|
|
|
|
keyValuePairs.TryAdd($"{subItem.ID}", subItem);
|
|
}
|
|
await FreeRedisProvider.FreeRedis.HSetAsync(redisCacheKey, keyValuePairs);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 1分钟采集电表数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual Task ScheduledMeterOneMinuteReading()
|
|
{
|
|
|
|
throw new NotImplementedException($"{nameof(ScheduledMeterOneMinuteReading)}请根据不同系统类型进行实现");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 5分钟采集电表数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual Task ScheduledMeterFiveMinuteReading()
|
|
{
|
|
throw new NotImplementedException($"{nameof(ScheduledMeterFiveMinuteReading)}请根据不同系统类型进行实现");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 15分钟采集电表数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual Task ScheduledMeterFifteenMinuteReading()
|
|
{
|
|
throw new NotImplementedException($"{nameof(ScheduledMeterFifteenMinuteReading)}请根据不同系统类型进行实现");
|
|
}
|
|
}
|
|
}
|