From 38283db1b2f659d203a8408d1ba46c86f3272149 Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Mon, 21 Apr 2025 10:50:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95IoTDB=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Provider/IoTDBProvider.cs | 2 +- .../Samples/SampleAppService.cs | 23 ++++++++-- .../Ammeters/ElectricityMeter.cs | 2 + .../Ammeters/ElectricityMeterTreeModel.cs | 42 +++++++++++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 services/JiShe.CollectBus.Domain/Ammeters/ElectricityMeterTreeModel.cs diff --git a/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs b/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs index 468506a..5b4e2a7 100644 --- a/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs +++ b/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs @@ -547,7 +547,7 @@ namespace JiShe.CollectBus.IoTDB.Provider if (entityTypeAttribute == null) { - throw new ArgumentException($"{nameof(BuildDeviceMetadata)} 构建设备元数据时 {nameof(IoTEntity)}的EntityType 没有指定,属于异常情况,-101"); + throw new ArgumentException($"{nameof(BuildDeviceMetadata)} 构建设备元数据时 {nameof(IoTEntity)} 的EntityType 没有指定,属于异常情况,-101"); } metadata.EntityType = entityTypeAttribute.EntityType; diff --git a/services/JiShe.CollectBus.Application/Samples/SampleAppService.cs b/services/JiShe.CollectBus.Application/Samples/SampleAppService.cs index e1080af..2988b96 100644 --- a/services/JiShe.CollectBus.Application/Samples/SampleAppService.cs +++ b/services/JiShe.CollectBus.Application/Samples/SampleAppService.cs @@ -68,7 +68,7 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS messageHexString = messageHexString + timestamps; } - ElectricityMeter meter = new ElectricityMeter() + ElectricityMeterTreeModel meter = new ElectricityMeterTreeModel() { SystemName = "energy", DeviceId = "402440506", @@ -90,7 +90,9 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS [HttpGet] public async Task UseTableSessionPool() { - ElectricityMeter meter2 = new ElectricityMeter() + var testTime = Convert.ToDateTime("2025-04-21 08:35:55"); + + ElectricityMeterTreeModel meter2 = new ElectricityMeterTreeModel() { SystemName = "energy", DeviceId = "402440506", @@ -99,13 +101,12 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS MeterModel = "DDZY-1980", ProjectCode = "10059", Voltage = 10, - Timestamps = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), + Timestamps = new DateTimeOffset(testTime).ToUnixTimeMilliseconds(), }; await _iotDBProvider.InsertAsync(meter2); _dbContext.UseTableSessionPool = true; - var testTime = Convert.ToDateTime("2025-04-21 08:32:55"); ElectricityMeter meter = new ElectricityMeter() { @@ -119,6 +120,20 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS Timestamps = new DateTimeOffset(testTime).ToUnixTimeMilliseconds(), }; await _iotDBProvider.InsertAsync(meter); + + ElectricityMeter meter3 = new ElectricityMeter() + { + SystemName = "energy", + DeviceId = "402440506", + DeviceType = "Ammeter", + Current = 10, + MeterModel = "DDZY-1980", + ProjectCode = "10059", + Voltage = 10, + Currentd = 22, + Timestamps = new DateTimeOffset(testTime).ToUnixTimeMilliseconds(), + }; + await _iotDBProvider.InsertAsync(meter); } /// diff --git a/services/JiShe.CollectBus.Domain/Ammeters/ElectricityMeter.cs b/services/JiShe.CollectBus.Domain/Ammeters/ElectricityMeter.cs index a6c09dc..cf936fe 100644 --- a/services/JiShe.CollectBus.Domain/Ammeters/ElectricityMeter.cs +++ b/services/JiShe.CollectBus.Domain/Ammeters/ElectricityMeter.cs @@ -4,10 +4,12 @@ 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.Ammeters { + [EntityType(EntityTypeEnum.TableModel)] public class ElectricityMeter : IoTEntity { [ATTRIBUTEColumn] diff --git a/services/JiShe.CollectBus.Domain/Ammeters/ElectricityMeterTreeModel.cs b/services/JiShe.CollectBus.Domain/Ammeters/ElectricityMeterTreeModel.cs new file mode 100644 index 0000000..ddc7daa --- /dev/null +++ b/services/JiShe.CollectBus.Domain/Ammeters/ElectricityMeterTreeModel.cs @@ -0,0 +1,42 @@ +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.Ammeters +{ + [EntityType(EntityTypeEnum.TreeModel)] + public class ElectricityMeterTreeModel : IoTEntity + { + [ATTRIBUTEColumn] + public string MeterModel { get; set; } + + /// + /// 下发消息内容 + /// + [FIELDColumn] + public string IssuedMessageHexString { get; set; } + + ///// + ///// 下发消息Id + ///// + //[FIELDColumn] + //public string IssuedMessageId { get; set; } + + [FIELDColumn] + public double Voltage { get; set; } + + [FIELDColumn] + public double Current { get; set; } + + [FIELDColumn] + public double Power => Voltage * Current; + + [FIELDColumn] + public double? Currentd { get; set; } + } +}