封装单个测点数据的Tablet列

This commit is contained in:
ChenYi 2025-04-10 23:31:43 +08:00
parent a0463d5ae1
commit b5f929910c
5 changed files with 99 additions and 29 deletions

View File

@ -226,6 +226,7 @@ namespace JiShe.CollectBus.Plugins
//string topicName = string.Format(ProtocolConst.AFNTopicNameFormat, aFn);
//todo 如何确定时标?目前集中器的采集频率,都是固定,数据上报的时候,根据当前时间,往后推测出应当采集的时间点作为时标。但是如果由于网络问题,数据一直没上报的情况改怎么计算?
await _producerBus.PublishAsync(ProtocolConst.SubscriberReceivedEventName, new MessageReceived
{

View File

@ -167,7 +167,7 @@ namespace JiShe.CollectBus.Subscribers
}
_dbProvider.InsertAsync();
//_dbProvider.InsertAsync();
//todo 查找是否有下发任务
//await _messageReceivedEventRepository.InsertAsync(receivedMessage);

View File

@ -1,4 +1,5 @@
using System;
using JiShe.CollectBus.IoTDBProvider;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -9,7 +10,8 @@ namespace JiShe.CollectBus.IotSystems.AFNEntity
/// <summary>
/// AFN单项数据实体
/// </summary>
public class AFNDataEntity
public class AFNDataEntity:IoTEntity
{
public string ItemCode { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JiShe.CollectBus.IoTDBProvider
{
/// <summary>
/// 用于标识当前实体为单个测点单侧点标识字段类型是Dictionary<string,object>
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class SingleMeasuringAttribute : Attribute
{
}
}

View File

@ -84,12 +84,13 @@ namespace JiShe.CollectBus.IoTDBProvider
var tablet = BuildTablet(new[] { entity }, metadata);
int result = await _currentSession.InsertAsync(tablet);
await _currentSession.InsertAsync(tablet);
if (result <= 0)
{
_logger.LogError($"{typeof(T).Name}插入数据没有成功");
}
//int result = await _currentSession.InsertAsync(tablet);
//if (result <= 0)
//{
// _logger.LogError($"{typeof(T).Name}插入数据没有成功");
//}
}
/// <summary>
@ -107,11 +108,12 @@ namespace JiShe.CollectBus.IoTDBProvider
foreach (var batch in batches)
{
var tablet = BuildTablet(batch, metadata);
var result = await _currentSession.InsertAsync(tablet);
if (result <= 0)
{
_logger.LogWarning($"{typeof(T).Name} 批量插入数据第{batch}批次没有成功,共{batches}批次。");
}
await _currentSession.InsertAsync(tablet);
//var result = await _currentSession.InsertAsync(tablet);
//if (result <= 0)
//{
// _logger.LogWarning($"{typeof(T).Name} 批量插入数据第{batch}批次没有成功,共{batches}批次。");
//}
}
}
@ -415,20 +417,52 @@ namespace JiShe.CollectBus.IoTDBProvider
foreach (var prop in type.GetProperties())
{
//按优先级顺序检查属性,避免重复反射
ColumnInfo? column = prop.GetCustomAttribute<TAGColumnAttribute>() is not null ? new ColumnInfo(
name: prop.Name, //使用属性名
category: ColumnCategory.TAG,
dataType: GetDataTypeFromTypeName(prop.PropertyType.Name)
) : prop.GetCustomAttribute<ATTRIBUTEColumnAttribute>() is not null ? new ColumnInfo(
prop.Name,
ColumnCategory.ATTRIBUTE,
GetDataTypeFromTypeName(prop.PropertyType.Name)
) : prop.GetCustomAttribute<FIELDColumnAttribute>() is not null ? new ColumnInfo(
prop.Name,
ColumnCategory.FIELD,
GetDataTypeFromTypeName(prop.PropertyType.Name)
) : null;
//先获取Tag标签和属性标签
ColumnInfo? column = prop.GetCustomAttribute<TAGColumnAttribute>() is not null ? new ColumnInfo(
name: prop.Name,
category: ColumnCategory.TAG,
dataType: GetDataTypeFromTypeName(prop.PropertyType.Name), false
) : prop.GetCustomAttribute<ATTRIBUTEColumnAttribute>() is not null ? new ColumnInfo(
prop.Name,
ColumnCategory.ATTRIBUTE,
GetDataTypeFromTypeName(prop.PropertyType.Name),false
) : null;
//最先检查是不是单测点
if (prop.GetCustomAttribute<SingleMeasuringAttribute>() is not null)
{
//单测点的情况下字段类型是Dictionary<string,object>
Dictionary<string, object> keyValuePairs = prop.GetValue(null) as Dictionary<string, object>;
column = new ColumnInfo(
keyValuePairs.Keys.First(),
ColumnCategory.FIELD,
GetDataTypeFromTypeName(prop.PropertyType.Name), false
);
}
else
{
//不是单测点的情况下,直接获取字段名称作为测点名称
column = prop.GetCustomAttribute<FIELDColumnAttribute>() is not null ? new ColumnInfo(
prop.Name,
ColumnCategory.FIELD,
GetDataTypeFromTypeName(prop.PropertyType.Name), false
) : null;
}
////按优先级顺序检查属性,避免重复反射
//column = prop.GetCustomAttribute<TAGColumnAttribute>() is not null ? new ColumnInfo(
// name: prop.Name, //使用属性名
// category: ColumnCategory.TAG,
// dataType: GetDataTypeFromTypeName(prop.PropertyType.Name)
//) : prop.GetCustomAttribute<ATTRIBUTEColumnAttribute>() is not null ? new ColumnInfo(
// prop.Name,
// ColumnCategory.ATTRIBUTE,
// GetDataTypeFromTypeName(prop.PropertyType.Name)
//) : prop.GetCustomAttribute<FIELDColumnAttribute>() is not null ? new ColumnInfo(
// prop.Name,
// ColumnCategory.FIELD,
// GetDataTypeFromTypeName(prop.PropertyType.Name)
//) : null;
if (column.HasValue)
{
@ -480,15 +514,32 @@ namespace JiShe.CollectBus.IoTDBProvider
/// </summary>
private readonly struct ColumnInfo
{
/// <summary>
/// 列名
/// </summary>
public string Name { get; }
/// <summary>
/// 是否是单测点
/// </summary>
public bool IsSingleMeasuring { get;}
/// <summary>
/// 列类型
/// </summary>
public ColumnCategory Category { get; }
/// <summary>
/// 数据类型
/// </summary>
public TSDataType DataType { get; }
public ColumnInfo(string name, ColumnCategory category, TSDataType dataType)
public ColumnInfo(string name, ColumnCategory category, TSDataType dataType,bool isSingleMeasuring)
{
Name = name;
Category = category;
DataType = dataType;
IsSingleMeasuring = isSingleMeasuring;
}
}