diff --git a/modules/JiShe.CollectBus.IoTDB/Attribute/SingleMeasuringAttribute.cs b/modules/JiShe.CollectBus.IoTDB/Attribute/SingleMeasuringAttribute.cs
index cebb85a..5f0ca07 100644
--- a/modules/JiShe.CollectBus.IoTDB/Attribute/SingleMeasuringAttribute.cs
+++ b/modules/JiShe.CollectBus.IoTDB/Attribute/SingleMeasuringAttribute.cs
@@ -1,7 +1,7 @@
namespace JiShe.CollectBus.IoTDB.Attribute
{
///
- /// 用于标识当前实体为单侧点模式,单侧点模式只有一个Filed标识字段,类型是Tuple,Item1=>测点名称,Item2=>测点值,泛型
+ /// 用于标识当前实体为单侧点模式,单侧点模式只有一个Filed标识字段,类型是Tuple,Item1=>测点名称,Item2=>测点值,泛型
///
[AttributeUsage(AttributeTargets.Property)]
public class SingleMeasuringAttribute : System.Attribute
diff --git a/modules/JiShe.CollectBus.IoTDB/Attribute/TableNameOrTreePathAttribute.cs b/modules/JiShe.CollectBus.IoTDB/Attribute/TableNameOrTreePathAttribute.cs
new file mode 100644
index 0000000..1b4f4f0
--- /dev/null
+++ b/modules/JiShe.CollectBus.IoTDB/Attribute/TableNameOrTreePathAttribute.cs
@@ -0,0 +1,18 @@
+using JiShe.CollectBus.IoTDB.Enums;
+
+namespace JiShe.CollectBus.IoTDB.Attribute
+{
+ ///
+ /// IoTDB实体存储路径或表名称,一般用于已经明确的存储路径或表名称,例如日志存储
+ ///
+ [AttributeUsage(AttributeTargets.Class)]
+ public class TableNameOrTreePathAttribute : System.Attribute
+ {
+ public string TableNameOrTreePath { get; }
+
+ public TableNameOrTreePathAttribute(string tableNameOrTreePath)
+ {
+ TableNameOrTreePath = tableNameOrTreePath;
+ }
+ }
+}
diff --git a/modules/JiShe.CollectBus.IoTDB/Model/IoTEntity.cs b/modules/JiShe.CollectBus.IoTDB/Model/IoTEntity.cs
index 6431e6f..73a90e0 100644
--- a/modules/JiShe.CollectBus.IoTDB/Model/IoTEntity.cs
+++ b/modules/JiShe.CollectBus.IoTDB/Model/IoTEntity.cs
@@ -3,7 +3,7 @@
namespace JiShe.CollectBus.IoTDB.Model
{
///
- /// IoT实体基类,此类适用于多个数据测点记录场景,单个测点请使用子类 SingleMeasuringEntity
+ /// IoT实体基类,此类适用于多个数据测点记录场景,单个测点请使用子类 SingleMeasuring
///
public abstract class IoTEntity
{
diff --git a/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntity.cs b/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntity.cs
new file mode 100644
index 0000000..4308dae
--- /dev/null
+++ b/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntity.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JiShe.CollectBus.IoTDB.Attribute;
+using JiShe.CollectBus.IoTDB.Enums;
+using JiShe.CollectBus.IoTDB.Provider;
+
+namespace JiShe.CollectBus.IoTDB.Model
+{
+ ///
+ /// Table模型单项数据实体
+ ///
+ [EntityType(EntityTypeEnum.TableModel)]
+ public class TableModelSingleMeasuringEntity : IoTEntity
+ {
+ ///
+ /// 单项数据键值对
+ ///
+ [SingleMeasuring(nameof(SingleColumn))]
+ public required Tuple SingleColumn { get; set; }
+ }
+}
diff --git a/modules/JiShe.CollectBus.IoTDB/Model/SingleMeasuringEntity.cs b/modules/JiShe.CollectBus.IoTDB/Model/TreeModelSingleMeasuringEntity.cs
similarity index 80%
rename from modules/JiShe.CollectBus.IoTDB/Model/SingleMeasuringEntity.cs
rename to modules/JiShe.CollectBus.IoTDB/Model/TreeModelSingleMeasuringEntity.cs
index 72a8ae6..9b3609c 100644
--- a/modules/JiShe.CollectBus.IoTDB/Model/SingleMeasuringEntity.cs
+++ b/modules/JiShe.CollectBus.IoTDB/Model/TreeModelSingleMeasuringEntity.cs
@@ -10,13 +10,13 @@ using JiShe.CollectBus.IoTDB.Provider;
namespace JiShe.CollectBus.IoTDB.Model
{
///
- /// 单项数据实体
+ /// Tree模型单项数据实体
///
[EntityType(EntityTypeEnum.TreeModel)]
- public class SingleMeasuringEntity : IoTEntity
+ public class TreeModelSingleMeasuringEntity : IoTEntity
{
///
- /// 单项数据对象
+ /// 单项数据键值对
///
[SingleMeasuring(nameof(SingleMeasuring))]
public required Tuple SingleMeasuring { get; set; }
diff --git a/modules/JiShe.CollectBus.IoTDB/Provider/DevicePathBuilder.cs b/modules/JiShe.CollectBus.IoTDB/Provider/DevicePathBuilder.cs
index a858c73..f9127db 100644
--- a/modules/JiShe.CollectBus.IoTDB/Provider/DevicePathBuilder.cs
+++ b/modules/JiShe.CollectBus.IoTDB/Provider/DevicePathBuilder.cs
@@ -30,6 +30,17 @@ namespace JiShe.CollectBus.IoTDB.Provider
var type = typeof(T);
return $"{type.Name.ToLower()}";
}
+
+ ///
+ /// 获取表名称,用作单侧点表模型特殊处理。
+ ///
+ ///
+ ///
+ ///
+ public static string GetDeviceTableName(T entity) where T : IoTEntity
+ {
+ return $"{entity.SystemName.ToLower()}.`{entity.ProjectCode}`.`{entity.DeviceType}`.`{entity.DeviceId}`";
+ }
}
}
diff --git a/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs b/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs
index 1fac82a..9b76a6f 100644
--- a/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs
+++ b/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs
@@ -159,7 +159,13 @@ namespace JiShe.CollectBus.IoTDB.Provider
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构{nameof(Tablet)}时 table模型不能使用tree模型Session连接,属于异常情况,-104");
}
-
+ string tableNameOrTreePath = string.Empty;
+ var tableNameOrTreePathAttribute = typeof(T).GetCustomAttribute();
+ if (tableNameOrTreePathAttribute != null)
+ {
+ tableNameOrTreePath = tableNameOrTreePathAttribute.TableNameOrTreePath;
+ }
+
foreach (var entity in entities)
{
timestamps.Add(entity.Timestamps);
@@ -198,6 +204,12 @@ namespace JiShe.CollectBus.IoTDB.Provider
{
rowValues.Add(null);
}
+
+ //同时如果是单测点模式,且是table模型存储,路径只能通过DevicePathBuilder.GetDeviceTableName(entity)获取
+ if (_runtimeContext.UseTableSessionPool)
+ {
+ tableNameOrTreePath = DevicePathBuilder.GetDeviceTableName(entity);
+ }
}
else
{
@@ -209,14 +221,23 @@ namespace JiShe.CollectBus.IoTDB.Provider
values.Add(rowValues);
- if (!_runtimeContext.UseTableSessionPool)//树模型
+ //如果指定了路径
+ if (!string.IsNullOrWhiteSpace(tableNameOrTreePath))
{
- devicePaths.Add(DevicePathBuilder.GetDevicePath(entity));
+ devicePaths.Add(tableNameOrTreePath);
}
else
{
- devicePaths.Add(DevicePathBuilder.GetTableName());
+ if (!_runtimeContext.UseTableSessionPool)//树模型
+ {
+ devicePaths.Add(DevicePathBuilder.GetDevicePath(entity));
+ }
+ else
+ {
+ devicePaths.Add(DevicePathBuilder.GetTableName());
+ }
}
+
}
if (devicePaths.Count > 1)
diff --git a/services/JiShe.CollectBus.Application/Samples/SampleAppService.cs b/services/JiShe.CollectBus.Application/Samples/SampleAppService.cs
index 101ab0f..7693636 100644
--- a/services/JiShe.CollectBus.Application/Samples/SampleAppService.cs
+++ b/services/JiShe.CollectBus.Application/Samples/SampleAppService.cs
@@ -9,6 +9,7 @@ using JiShe.CollectBus.IoTDB.Context;
using JiShe.CollectBus.IoTDB.Interface;
using JiShe.CollectBus.IoTDB.Model;
using JiShe.CollectBus.IoTDB.Options;
+using JiShe.CollectBus.IoTDB.Provider;
using JiShe.CollectBus.IotSystems.PrepayModel;
using JiShe.CollectBus.Kafka.Attributes;
using JiShe.CollectBus.Kafka.Internal;
@@ -150,14 +151,14 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS
}
///
- /// 测试单个测点数据项
+ /// 测试树模型单个测点数据项
///
///
///
[HttpGet]
- public async Task TestSingleMeasuringAFNData(string measuring, string value, DateTime time)
+ public async Task TestTreeModelSingleMeasuringEntity(string measuring, string value, DateTime time)
{
- var meter = new SingleMeasuringEntity()
+ var meter = new TreeModelSingleMeasuringEntity()
{
SystemName = "energy",
DeviceId = "402440506",
@@ -170,14 +171,14 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS
}
///
- /// 测试单个测点数据项2
+ /// 测试树模型单个测点数据项2
///
///
///
[HttpGet]
- public async Task TestSingleMeasuringAFNData2(string measuring, int value, DateTime time)
+ public async Task TestTreeModelSingleMeasuringEntity2(string measuring, int value, DateTime time)
{
- var meter = new SingleMeasuringEntity()
+ var meter = new TreeModelSingleMeasuringEntity()
{
SystemName = "energy",
DeviceId = "402440506",
@@ -189,6 +190,48 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS
await _iotDBProvider.InsertAsync(meter);
}
+ ///
+ /// 测试表模型单个测点数据项
+ ///
+ ///
+ ///
+ [HttpGet]
+ public async Task TestTableModelSingleMeasuringEntity(string measuring, string value, DateTime time)
+ {
+ var meter = new TableModelSingleMeasuringEntity()
+ {
+ SystemName = "energy",
+ DeviceId = "402440506",
+ DeviceType = "Ammeter",
+ ProjectCode = "10059",
+ Timestamps = time.GetDateTimeOffset().ToUnixTimeMilliseconds(),
+ SingleColumn = new Tuple(measuring, value)
+ };
+ _dbContext.UseTableSessionPool = true;
+ await _iotDBProvider.InsertAsync(meter);
+ }
+
+ ///
+ /// 测试表模型单个测点数据项2
+ ///
+ ///
+ ///
+ [HttpGet]
+ public async Task TestTableModelSingleMeasuringEntity2(string measuring, int value, DateTime time)
+ {
+ var meter = new TableModelSingleMeasuringEntity()
+ {
+ SystemName = "energy",
+ DeviceId = "402440506",
+ DeviceType = "Ammeter",
+ ProjectCode = "10059",
+ Timestamps = time.GetDateTimeOffset().ToUnixTimeMilliseconds(),
+ SingleColumn = new Tuple(measuring, value)
+ };
+ _dbContext.UseTableSessionPool = true;
+ await _iotDBProvider.InsertAsync(meter);
+ }
+
///
/// 测试设备分组均衡控制算法
///