Merge branch 'dev' of https://310.jisheyun.com/daizan/JiShe.CollectBus into dev
This commit is contained in:
commit
53fa6f503c
@ -250,7 +250,8 @@ namespace JiShe.CollectBus.Protocol.T37612012.SendData
|
||||
Pn = request.Pn,
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter,request.DataUnit);
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -706,6 +706,36 @@ namespace JiShe.CollectBus.Protocol.T37612012
|
||||
/// <returns></returns>
|
||||
public static int CalculateFn(string dt1, string dt2) => dt2.HexToDec() * 8 + (8 - dt1.HexTo4BinZero().IndexOf("1"));
|
||||
|
||||
#region 下行
|
||||
/// <summary>
|
||||
/// 生成二类项采集项时间数据单元
|
||||
/// </summary>
|
||||
/// <param name="timeMark"></param>
|
||||
/// <param name="validLength"></param>
|
||||
/// <returns></returns>
|
||||
public virtual List<string> Generate_DataUnit(DataTimeMark timeMark)
|
||||
{
|
||||
List<string> values = new List<string>
|
||||
{
|
||||
SplitDataTime(timeMark.DataTime)//数据时间
|
||||
};
|
||||
if (timeMark.Density > 0)
|
||||
values.Add(timeMark.Density.HexToDecStr().PadLeft(2, '0'));//密度
|
||||
if (timeMark.Point > 0)
|
||||
values.Add(timeMark.Point.HexToDecStr().PadLeft(2, '0'));//数据点数
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
private string SplitDataTime(DateTime dataTime)
|
||||
{
|
||||
//2101060815
|
||||
List<string> values = new List<string>() { $"{dataTime}:YY", $"{dataTime}:MM", $"{dataTime}:dd", $"{dataTime}:HH", $"{dataTime}:mm", };
|
||||
|
||||
values.Reverse();
|
||||
return string.Join("", values);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 上行命令
|
||||
|
||||
@ -113,6 +113,11 @@ namespace JiShe.CollectBus.Protocol.T6452007
|
||||
}
|
||||
}
|
||||
|
||||
if (aFNStr == "0D")//二类数据
|
||||
{
|
||||
dataUnit = Generate_DataUnit(request.DataTimeMark);
|
||||
}
|
||||
|
||||
string afnMethonCode = $"AFN{aFNStr}_Fn_Send";
|
||||
if (base.T3761AFNHandlers != null && base.T3761AFNHandlers.TryGetValue(afnMethonCode
|
||||
, out var handler))
|
||||
|
||||
29
protocols/JiShe.CollectBus.Protocol/Models/DataTimeMark.cs
Normal file
29
protocols/JiShe.CollectBus.Protocol/Models/DataTimeMark.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据时间标记
|
||||
/// </summary>
|
||||
public class DataTimeMark
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据时间
|
||||
/// </summary>
|
||||
public DateTime DataTime { get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// 数据点数
|
||||
/// </summary>
|
||||
public int Point { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 冻结密度(-1、采集项本身无密度位,0、无,1、15分钟,2、30分钟,3、60分钟,245、5分钟,255、1分钟)
|
||||
/// </summary>
|
||||
public int Density { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
namespace JiShe.CollectBus.Protocol.Models
|
||||
using JiShe.CollectBus.Common.BuildSendDatas;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 报文构建参数
|
||||
@ -21,9 +23,9 @@
|
||||
public required string ItemCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务时间戳
|
||||
/// 任务时间
|
||||
/// </summary>
|
||||
public long TimeStamp { get; set; }
|
||||
public DataTimeMark DataTimeMark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 集中器转发协议构建构建参数
|
||||
|
||||
@ -71,32 +71,49 @@ namespace JiShe.CollectBus.DataChannels
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task ScheduledMeterTaskReadding(ChannelReader<Tuple<string, List<MeterReadingTelemetryPacketInfo>>> _telemetryPacketInfoReader)
|
||||
{
|
||||
try
|
||||
{
|
||||
var metadata = await _dbProvider.GetMetadata<MeterReadingTelemetryPacketInfo>();
|
||||
var batchSize = 10000;
|
||||
var batchSize = 200_00;
|
||||
var timeout = TimeSpan.FromSeconds(5); // 默认超时时间为5秒
|
||||
var timer = Stopwatch.StartNew();
|
||||
long timeoutMilliseconds = 0;
|
||||
|
||||
List<MeterReadingTelemetryPacketInfo> taskInfoList = new List<MeterReadingTelemetryPacketInfo>();
|
||||
var startTime = DateTime.Now;
|
||||
var timer = new Stopwatch();
|
||||
while (true)
|
||||
{
|
||||
var canRead = await _telemetryPacketInfoReader.WaitToReadAsync();
|
||||
if (!canRead)
|
||||
var canRead = _telemetryPacketInfoReader.Count;
|
||||
if (canRead <= 0)
|
||||
{
|
||||
if (timeoutMilliseconds > 0)
|
||||
{
|
||||
_logger.LogError($"{nameof(ScheduledMeterTaskReadding)} 通道处理数据耗时{timeoutMilliseconds}毫秒");
|
||||
}
|
||||
timeoutMilliseconds = 0;
|
||||
//无消息时短等待1秒
|
||||
await Task.Delay(100_0);
|
||||
continue;
|
||||
}
|
||||
timer.Restart();
|
||||
|
||||
var startTime = DateTime.Now;
|
||||
string topicName = string.Empty;
|
||||
|
||||
while (taskInfoList != null && taskInfoList.Count < batchSize && (DateTime.Now - startTime) < timeout)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_telemetryPacketInfoReader.TryRead(out var dataItem))
|
||||
{
|
||||
topicName = dataItem.Item1;
|
||||
taskInfoList.AddRange(dataItem.Item2);
|
||||
}
|
||||
else
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
//无消息时短暂等待
|
||||
await Task.Delay(5);
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,16 +126,25 @@ namespace JiShe.CollectBus.DataChannels
|
||||
deviceIdSelector: data => data.DeviceId,
|
||||
processor: (data, groupIndex) =>
|
||||
{
|
||||
// _ = KafkaProducerIssuedMessageAction(dateItem.Item1, data, groupIndex);
|
||||
//_ = KafkaProducerIssuedMessageAction(dateItem.Item1, data, groupIndex);
|
||||
}
|
||||
);
|
||||
|
||||
taskInfoList.Clear();
|
||||
}
|
||||
timer.Stop();
|
||||
|
||||
timeoutMilliseconds = timeoutMilliseconds + timer.ElapsedMilliseconds;
|
||||
|
||||
startTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kafka 推送消息
|
||||
|
||||
@ -32,6 +32,7 @@ using static IdentityModel.ClaimComparer;
|
||||
using JiShe.CollectBus.DataChannels;
|
||||
using JiShe.CollectBus.DataMigration.Options;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
{
|
||||
@ -257,7 +258,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
var tempTask = await AmmerterCreatePublishTaskAction(timeDensity, data, groupIndex, timestamps);
|
||||
if (tempTask == null || tempTask.Count <= 0)
|
||||
{
|
||||
_logger.LogWarning($"电表 {data.Name} 任务数据构建失败:{data.Serialize()}");
|
||||
//_logger.LogWarning($"电表 {data.Name} 任务数据构建失败:{data.Serialize()}");
|
||||
return;
|
||||
}
|
||||
_ = _dataChannelManage.ScheduledMeterTaskWriter(DataChannelManage.TaskDataChannel.Writer, Tuple.Create(ProtocolConst.AmmeterSubscriberWorkerAutoValveControlIssuedEventName, tempTask));
|
||||
@ -332,9 +333,10 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
//此处代码不要删除
|
||||
#if DEBUG
|
||||
var timeDensity = "15";
|
||||
var redisCacheMeterInfoHashKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoHashKey, SystemType, "JiSheCollectBus2", MeterTypeEnum.Ammeter, timeDensity)}";
|
||||
var redisCacheMeterInfoSetIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoSetIndexKey, SystemType, "JiSheCollectBus2", MeterTypeEnum.Ammeter, timeDensity)}";
|
||||
var redisCacheMeterInfoZSetScoresIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoZSetScoresIndexKey, SystemType, "JiSheCollectBus2", MeterTypeEnum.Ammeter, timeDensity)}";
|
||||
var serverTagName = "JiSheCollectBus2";
|
||||
var redisCacheMeterInfoHashKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoHashKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}";
|
||||
var redisCacheMeterInfoSetIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoSetIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}";
|
||||
var redisCacheMeterInfoZSetScoresIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoZSetScoresIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}";
|
||||
|
||||
List<AmmeterInfo> meterInfos = new List<AmmeterInfo>();
|
||||
List<string> focusAddressDataLista = new List<string>();
|
||||
@ -734,6 +736,12 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
FocusAddress = ammeterInfo.FocusAddress,
|
||||
Pn = ammeterInfo.MeteringCode,
|
||||
ItemCode = tempItem,
|
||||
DataTimeMark = new Protocol.DataTimeMark()
|
||||
{
|
||||
Density = ammeterInfo.TimeDensity,//todo 转换成协议的值
|
||||
Point = 1,
|
||||
DataTime = timestamps,
|
||||
}
|
||||
});
|
||||
if (builderResponse == null || builderResponse.Data.Length <= 0)
|
||||
{
|
||||
@ -1499,8 +1507,8 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
List<T> meterInfos = new List<T>();
|
||||
decimal? cursor = null;
|
||||
string member = null;
|
||||
bool hasNext;
|
||||
do
|
||||
|
||||
while (true)
|
||||
{
|
||||
var page = await _redisDataCacheService.GetAllPagedData<T>(
|
||||
redisCacheMeterInfoHashKeyTemp,
|
||||
@ -1510,11 +1518,14 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
lastMember: member);
|
||||
|
||||
meterInfos.AddRange(page.Items);
|
||||
cursor = page.HasNext ? page.NextScore : null;
|
||||
member = page.HasNext ? page.NextMember : null;
|
||||
hasNext = page.HasNext;
|
||||
} while (hasNext);
|
||||
if (!page.HasNext)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
cursor = page.NextScore;
|
||||
member = page.NextMember;
|
||||
}
|
||||
|
||||
//var page = await _redisDataCacheService.GetAllPagedData<T>(
|
||||
// redisCacheMeterInfoHashKeyTemp,
|
||||
@ -1530,8 +1541,12 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
_logger.LogError($"{nameof(CreateMeterPublishTask)} {meterType}的{timeDensity}分钟采集待下发任务创建失败,没有获取到缓存信息,-105");
|
||||
return;
|
||||
}
|
||||
timer.Stop();
|
||||
|
||||
_logger.LogError($"{nameof(CreateMeterPublishTask)} 构建采集待下发任务,缓存获取信息共花费{timer.ElapsedMilliseconds}毫秒");
|
||||
|
||||
timer.Restart();
|
||||
|
||||
await DeviceGroupBalanceControl.ProcessWithThrottleAsync(
|
||||
items: meterInfos,
|
||||
deviceIdSelector: data => data.MeterId.ToString(),
|
||||
|
||||
@ -166,7 +166,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
INNER JOIN TB_AmmeterInfo(nolock) AS C ON B.AmmeterID=C.ID
|
||||
INNER JOIN TB_FocusInfo(nolock) AS D ON D.ID=C.FocusID
|
||||
INNER JOIN TB_GatherInfo(NOLOCK) AS E ON E.ID=D.GatherInfoID
|
||||
WHERE A.IsForbid=0 and A.State<>-1 and E.GatherCode LIKE '%V4%' and A.TripTime";
|
||||
WHERE A.IsForbid=0 and A.State<>-1 and E.GatherCode LIKE '%V4%' ";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(currentTime))
|
||||
{
|
||||
|
||||
@ -204,6 +204,7 @@ namespace JiShe.CollectBus.Common.DeviceBalanceControl
|
||||
|
||||
int actualThreads = maxConcurrency ?? recommendedThreads;
|
||||
|
||||
|
||||
// 创建节流器
|
||||
using var throttler = new SemaphoreSlim(initialCount: actualThreads);
|
||||
|
||||
|
||||
@ -245,7 +245,7 @@ namespace JiShe.CollectBus.Common.Extensions
|
||||
/// <param name="dateLong"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public static DateTime ParseIntToDate(long dateLong)
|
||||
public static DateTime ParseIntToDate(this long dateLong)
|
||||
{
|
||||
if (dateLong < 10000101 || dateLong > 99991231)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user