封装单个测点数据的Tablet列
This commit is contained in:
parent
a0463d5ae1
commit
b5f929910c
@ -226,6 +226,7 @@ namespace JiShe.CollectBus.Plugins
|
|||||||
|
|
||||||
|
|
||||||
//string topicName = string.Format(ProtocolConst.AFNTopicNameFormat, aFn);
|
//string topicName = string.Format(ProtocolConst.AFNTopicNameFormat, aFn);
|
||||||
|
//todo 如何确定时标?目前集中器的采集频率,都是固定,数据上报的时候,根据当前时间,往后推测出应当采集的时间点作为时标。但是如果由于网络问题,数据一直没上报的情况改怎么计算?
|
||||||
|
|
||||||
await _producerBus.PublishAsync(ProtocolConst.SubscriberReceivedEventName, new MessageReceived
|
await _producerBus.PublishAsync(ProtocolConst.SubscriberReceivedEventName, new MessageReceived
|
||||||
{
|
{
|
||||||
|
|||||||
@ -167,7 +167,7 @@ namespace JiShe.CollectBus.Subscribers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_dbProvider.InsertAsync();
|
//_dbProvider.InsertAsync();
|
||||||
//todo 查找是否有下发任务
|
//todo 查找是否有下发任务
|
||||||
|
|
||||||
//await _messageReceivedEventRepository.InsertAsync(receivedMessage);
|
//await _messageReceivedEventRepository.InsertAsync(receivedMessage);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using JiShe.CollectBus.IoTDBProvider;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -9,7 +10,8 @@ namespace JiShe.CollectBus.IotSystems.AFNEntity
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// AFN单项数据实体
|
/// AFN单项数据实体
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AFNDataEntity
|
public class AFNDataEntity:IoTEntity
|
||||||
{
|
{
|
||||||
|
public string ItemCode { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -84,12 +84,13 @@ namespace JiShe.CollectBus.IoTDBProvider
|
|||||||
|
|
||||||
var tablet = BuildTablet(new[] { entity }, metadata);
|
var tablet = BuildTablet(new[] { entity }, metadata);
|
||||||
|
|
||||||
int result = await _currentSession.InsertAsync(tablet);
|
await _currentSession.InsertAsync(tablet);
|
||||||
|
|
||||||
if (result <= 0)
|
//int result = await _currentSession.InsertAsync(tablet);
|
||||||
{
|
//if (result <= 0)
|
||||||
_logger.LogError($"{typeof(T).Name}插入数据没有成功");
|
//{
|
||||||
}
|
// _logger.LogError($"{typeof(T).Name}插入数据没有成功");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -107,11 +108,12 @@ namespace JiShe.CollectBus.IoTDBProvider
|
|||||||
foreach (var batch in batches)
|
foreach (var batch in batches)
|
||||||
{
|
{
|
||||||
var tablet = BuildTablet(batch, metadata);
|
var tablet = BuildTablet(batch, metadata);
|
||||||
var result = await _currentSession.InsertAsync(tablet);
|
await _currentSession.InsertAsync(tablet);
|
||||||
if (result <= 0)
|
//var result = await _currentSession.InsertAsync(tablet);
|
||||||
{
|
//if (result <= 0)
|
||||||
_logger.LogWarning($"{typeof(T).Name} 批量插入数据第{batch}批次没有成功,共{batches}批次。");
|
//{
|
||||||
}
|
// _logger.LogWarning($"{typeof(T).Name} 批量插入数据第{batch}批次没有成功,共{batches}批次。");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,20 +417,52 @@ namespace JiShe.CollectBus.IoTDBProvider
|
|||||||
|
|
||||||
foreach (var prop in type.GetProperties())
|
foreach (var prop in type.GetProperties())
|
||||||
{
|
{
|
||||||
//按优先级顺序检查属性,避免重复反射
|
//先获取Tag标签和属性标签
|
||||||
ColumnInfo? column = prop.GetCustomAttribute<TAGColumnAttribute>() is not null ? new ColumnInfo(
|
ColumnInfo? column = prop.GetCustomAttribute<TAGColumnAttribute>() is not null ? new ColumnInfo(
|
||||||
name: prop.Name, //使用属性名
|
name: prop.Name,
|
||||||
category: ColumnCategory.TAG,
|
category: ColumnCategory.TAG,
|
||||||
dataType: GetDataTypeFromTypeName(prop.PropertyType.Name)
|
dataType: GetDataTypeFromTypeName(prop.PropertyType.Name), false
|
||||||
) : prop.GetCustomAttribute<ATTRIBUTEColumnAttribute>() is not null ? new ColumnInfo(
|
) : prop.GetCustomAttribute<ATTRIBUTEColumnAttribute>() is not null ? new ColumnInfo(
|
||||||
prop.Name,
|
prop.Name,
|
||||||
ColumnCategory.ATTRIBUTE,
|
ColumnCategory.ATTRIBUTE,
|
||||||
GetDataTypeFromTypeName(prop.PropertyType.Name)
|
GetDataTypeFromTypeName(prop.PropertyType.Name),false
|
||||||
) : prop.GetCustomAttribute<FIELDColumnAttribute>() is not null ? new ColumnInfo(
|
) : null;
|
||||||
prop.Name,
|
|
||||||
ColumnCategory.FIELD,
|
//最先检查是不是单测点
|
||||||
GetDataTypeFromTypeName(prop.PropertyType.Name)
|
if (prop.GetCustomAttribute<SingleMeasuringAttribute>() is not null)
|
||||||
) : 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)
|
if (column.HasValue)
|
||||||
{
|
{
|
||||||
@ -480,15 +514,32 @@ namespace JiShe.CollectBus.IoTDBProvider
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly struct ColumnInfo
|
private readonly struct ColumnInfo
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 列名
|
||||||
|
/// </summary>
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否是单测点
|
||||||
|
/// </summary>
|
||||||
|
public bool IsSingleMeasuring { get;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 列类型
|
||||||
|
/// </summary>
|
||||||
public ColumnCategory Category { get; }
|
public ColumnCategory Category { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据类型
|
||||||
|
/// </summary>
|
||||||
public TSDataType DataType { get; }
|
public TSDataType DataType { get; }
|
||||||
|
|
||||||
public ColumnInfo(string name, ColumnCategory category, TSDataType dataType)
|
public ColumnInfo(string name, ColumnCategory category, TSDataType dataType,bool isSingleMeasuring)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Category = category;
|
Category = category;
|
||||||
DataType = dataType;
|
DataType = dataType;
|
||||||
|
IsSingleMeasuring = isSingleMeasuring;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user