From b5f929910c0b312cf8b1917150ddb7909e5b3b15 Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Thu, 10 Apr 2025 23:31:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=E5=8D=95=E4=B8=AA=E6=B5=8B?= =?UTF-8?q?=E7=82=B9=E6=95=B0=E6=8D=AE=E7=9A=84Tablet=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plugins/TcpMonitor.cs | 1 + .../Subscribers/SubscriberAppService.cs | 2 +- .../IotSystems/AFNEntity/AFNDataEntity.cs | 6 +- .../Attribute/SingleMeasuringAttribute.cs | 16 +++ .../Provider/IoTDBProvider.cs | 103 +++++++++++++----- 5 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 src/JiShe.CollectBus.IoTDBProvider/Attribute/SingleMeasuringAttribute.cs diff --git a/src/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs b/src/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs index ea84d9b..c348a3d 100644 --- a/src/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs +++ b/src/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs @@ -226,6 +226,7 @@ namespace JiShe.CollectBus.Plugins //string topicName = string.Format(ProtocolConst.AFNTopicNameFormat, aFn); + //todo 如何确定时标?目前集中器的采集频率,都是固定,数据上报的时候,根据当前时间,往后推测出应当采集的时间点作为时标。但是如果由于网络问题,数据一直没上报的情况改怎么计算? await _producerBus.PublishAsync(ProtocolConst.SubscriberReceivedEventName, new MessageReceived { diff --git a/src/JiShe.CollectBus.Application/Subscribers/SubscriberAppService.cs b/src/JiShe.CollectBus.Application/Subscribers/SubscriberAppService.cs index a9cb5f8..c22e4dc 100644 --- a/src/JiShe.CollectBus.Application/Subscribers/SubscriberAppService.cs +++ b/src/JiShe.CollectBus.Application/Subscribers/SubscriberAppService.cs @@ -167,7 +167,7 @@ namespace JiShe.CollectBus.Subscribers } - _dbProvider.InsertAsync(); + //_dbProvider.InsertAsync(); //todo 查找是否有下发任务 //await _messageReceivedEventRepository.InsertAsync(receivedMessage); diff --git a/src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/AFNDataEntity.cs b/src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/AFNDataEntity.cs index 386baf3..5f0e44c 100644 --- a/src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/AFNDataEntity.cs +++ b/src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/AFNDataEntity.cs @@ -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 /// /// AFN单项数据实体 /// - public class AFNDataEntity + public class AFNDataEntity:IoTEntity { + public string ItemCode { get; set; } } } diff --git a/src/JiShe.CollectBus.IoTDBProvider/Attribute/SingleMeasuringAttribute.cs b/src/JiShe.CollectBus.IoTDBProvider/Attribute/SingleMeasuringAttribute.cs new file mode 100644 index 0000000..f69fd99 --- /dev/null +++ b/src/JiShe.CollectBus.IoTDBProvider/Attribute/SingleMeasuringAttribute.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.IoTDBProvider +{ + /// + /// 用于标识当前实体为单个测点,单侧点标识字段类型是Dictionary + /// + [AttributeUsage(AttributeTargets.Property)] + public class SingleMeasuringAttribute : Attribute + { + } +} diff --git a/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTDBProvider.cs b/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTDBProvider.cs index 6ad2caa..504709e 100644 --- a/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTDBProvider.cs +++ b/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTDBProvider.cs @@ -83,13 +83,14 @@ namespace JiShe.CollectBus.IoTDBProvider var metadata = GetMetadata(); var tablet = BuildTablet(new[] { entity }, metadata); + + await _currentSession.InsertAsync(tablet); - int result = 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}插入数据没有成功"); + //} } /// @@ -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() is not null ? new ColumnInfo( - name: prop.Name, //使用属性名 - category: ColumnCategory.TAG, - dataType: GetDataTypeFromTypeName(prop.PropertyType.Name) - ) : prop.GetCustomAttribute() is not null ? new ColumnInfo( - prop.Name, - ColumnCategory.ATTRIBUTE, - GetDataTypeFromTypeName(prop.PropertyType.Name) - ) : prop.GetCustomAttribute() is not null ? new ColumnInfo( - prop.Name, - ColumnCategory.FIELD, - GetDataTypeFromTypeName(prop.PropertyType.Name) - ) : null; + //先获取Tag标签和属性标签 + ColumnInfo? column = prop.GetCustomAttribute() is not null ? new ColumnInfo( + name: prop.Name, + category: ColumnCategory.TAG, + dataType: GetDataTypeFromTypeName(prop.PropertyType.Name), false + ) : prop.GetCustomAttribute() is not null ? new ColumnInfo( + prop.Name, + ColumnCategory.ATTRIBUTE, + GetDataTypeFromTypeName(prop.PropertyType.Name),false + ) : null; + + //最先检查是不是单测点 + if (prop.GetCustomAttribute() is not null) + { + //单测点的情况下,字段类型是Dictionary + Dictionary keyValuePairs = prop.GetValue(null) as Dictionary; + column = new ColumnInfo( + keyValuePairs.Keys.First(), + ColumnCategory.FIELD, + GetDataTypeFromTypeName(prop.PropertyType.Name), false + ); + } + else + { + //不是单测点的情况下,直接获取字段名称作为测点名称 + column = prop.GetCustomAttribute() is not null ? new ColumnInfo( + prop.Name, + ColumnCategory.FIELD, + GetDataTypeFromTypeName(prop.PropertyType.Name), false + ) : null; + } + + ////按优先级顺序检查属性,避免重复反射 + //column = prop.GetCustomAttribute() is not null ? new ColumnInfo( + // name: prop.Name, //使用属性名 + // category: ColumnCategory.TAG, + // dataType: GetDataTypeFromTypeName(prop.PropertyType.Name) + //) : prop.GetCustomAttribute() is not null ? new ColumnInfo( + // prop.Name, + // ColumnCategory.ATTRIBUTE, + // GetDataTypeFromTypeName(prop.PropertyType.Name) + //) : prop.GetCustomAttribute() 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 /// private readonly struct ColumnInfo { + /// + /// 列名 + /// public string Name { get; } + + /// + /// 是否是单测点 + /// + public bool IsSingleMeasuring { get;} + + /// + /// 列类型 + /// public ColumnCategory Category { 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; Category = category; DataType = dataType; + IsSingleMeasuring = isSingleMeasuring; } }