From e1d4126db08262f4247418cea8cdc350003b51dc Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Wed, 2 Apr 2025 17:46:33 +0800 Subject: [PATCH] =?UTF-8?q?iotdb=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectBusApplicationModule.cs | 2 ++ .../Samples/SampleAppService.cs | 30 ++++++++++++++++- .../Ammeters/ElectricityMeter.cs | 24 ++++++++++++++ .../JiShe.CollectBus.Domain.csproj | 1 + .../CollectBusHostModule.Configure.cs | 16 +++++----- src/JiShe.CollectBus.Host/appsettings.json | 32 +++++++++++-------- .../Provider/IoTEntity.cs | 4 +-- 7 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 src/JiShe.CollectBus.Domain/Ammeters/ElectricityMeter.cs diff --git a/src/JiShe.CollectBus.Application/CollectBusApplicationModule.cs b/src/JiShe.CollectBus.Application/CollectBusApplicationModule.cs index 86b36e7..085ab8e 100644 --- a/src/JiShe.CollectBus.Application/CollectBusApplicationModule.cs +++ b/src/JiShe.CollectBus.Application/CollectBusApplicationModule.cs @@ -15,6 +15,7 @@ using JiShe.CollectBus.Workers; using Volo.Abp.BackgroundWorkers.Hangfire; using JiShe.CollectBus.MongoDB; using JiShe.CollectBus.ScheduledMeterReading; +using JiShe.CollectBus.IoTDBProvider; namespace JiShe.CollectBus; @@ -25,6 +26,7 @@ namespace JiShe.CollectBus; typeof(AbpAutoMapperModule), typeof(AbpBackgroundWorkersHangfireModule), typeof(CollectBusFreeRedisModule), + typeof(CollectBusIoTDBModule), typeof(CollectBusFreeSqlModule) )] public class CollectBusApplicationModule : AbpModule diff --git a/src/JiShe.CollectBus.Application/Samples/SampleAppService.cs b/src/JiShe.CollectBus.Application/Samples/SampleAppService.cs index 6235a55..f76ce54 100644 --- a/src/JiShe.CollectBus.Application/Samples/SampleAppService.cs +++ b/src/JiShe.CollectBus.Application/Samples/SampleAppService.cs @@ -1,6 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; +using JiShe.CollectBus.Ammeters; using JiShe.CollectBus.FreeSql; +using JiShe.CollectBus.IoTDBProvider; using JiShe.CollectBus.IotSystems.PrepayModel; using Microsoft.AspNetCore.Authorization; @@ -8,6 +11,31 @@ namespace JiShe.CollectBus.Samples; public class SampleAppService : CollectBusAppService, ISampleAppService { + + private readonly IIoTDBProvider _iotDBProvider; + + public SampleAppService(IIoTDBProvider iotDBProvider) + { + _iotDBProvider = iotDBProvider; + } + + + public async Task AddReadingAsync() + { + ElectricityMeter meter = new ElectricityMeter() + { + SystemName = "Energy", + DeviceId = "402440506" + , + DeviceType = "Ammeter", + Current = 10, + MeterModel = "DDZY-1980", + ProjectCode = "10059", + Voltage = 10 + }; + await _iotDBProvider.InsertAsync(meter); + } + public Task GetAsync() { return Task.FromResult( diff --git a/src/JiShe.CollectBus.Domain/Ammeters/ElectricityMeter.cs b/src/JiShe.CollectBus.Domain/Ammeters/ElectricityMeter.cs new file mode 100644 index 0000000..d335fca --- /dev/null +++ b/src/JiShe.CollectBus.Domain/Ammeters/ElectricityMeter.cs @@ -0,0 +1,24 @@ +using JiShe.CollectBus.IoTDBProvider; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Ammeters +{ + public class ElectricityMeter : IoTEntity + { + [ATTRIBUTEColumn] + public string MeterModel { get; set; } + + [FIELDColumn] + public double Voltage { get; set; } + + [FIELDColumn] + public double Current { get; set; } + + [FIELDColumn] + public double Power => Voltage * Current; + } +} diff --git a/src/JiShe.CollectBus.Domain/JiShe.CollectBus.Domain.csproj b/src/JiShe.CollectBus.Domain/JiShe.CollectBus.Domain.csproj index 20068a5..16eef7f 100644 --- a/src/JiShe.CollectBus.Domain/JiShe.CollectBus.Domain.csproj +++ b/src/JiShe.CollectBus.Domain/JiShe.CollectBus.Domain.csproj @@ -24,6 +24,7 @@ + diff --git a/src/JiShe.CollectBus.Host/CollectBusHostModule.Configure.cs b/src/JiShe.CollectBus.Host/CollectBusHostModule.Configure.cs index 3516bbb..40f498e 100644 --- a/src/JiShe.CollectBus.Host/CollectBusHostModule.Configure.cs +++ b/src/JiShe.CollectBus.Host/CollectBusHostModule.Configure.cs @@ -290,15 +290,15 @@ namespace JiShe.CollectBus.Host var producerConfig = new ProducerConfig(); context.Services - .ConfigureKafkaTestOptions(options => - { +// .ConfigureKafkaTestOptions(options => +// { -#if DEBUG - options.CleanTopicsOnStart = true;// 测试时,每次启动都删除topic,生产环境不需要 -#endif - options.CreateTopicsIfNotExists = true; - options.TopicNames = ProtocolConstExtensions.GetAllTopicNames(); - }) +//#if DEBUG +// options.CleanTopicsOnStart = true;// 测试时,每次启动都删除topic,生产环境不需要 +//#endif +// options.CreateTopicsIfNotExists = true; +// options.TopicNames = ProtocolConstExtensions.GetAllTopicNames(); +// }) .AddMassTransit(x => { x.UsingInMemory((context, cfg) => cfg.ConfigureEndpoints(context)); diff --git a/src/JiShe.CollectBus.Host/appsettings.json b/src/JiShe.CollectBus.Host/appsettings.json index 69bdcc1..b506272 100644 --- a/src/JiShe.CollectBus.Host/appsettings.json +++ b/src/JiShe.CollectBus.Host/appsettings.json @@ -1,4 +1,4 @@ - { +{ "Serilog": { "Using": [ "Serilog.Sinks.Console", @@ -20,7 +20,7 @@ { "Name": "Console" }, - { + { "Name": "File", "Args": { "path": "logs/logs-.txt", @@ -33,17 +33,17 @@ "SelfUrl": "http://localhost:44315", "CorsOrigins": "http://localhost:4200,http://localhost:3100" }, - "ConnectionStrings": { - "Default": "mongodb://admin:admin02023@118.190.144.92:37117,118.190.144.92:37119,118.190.144.92:37120/JiSheCollectBus?authSource=admin&maxPoolSize=400&minPoolSize=10&waitQueueTimeoutMS=5000", - "Kafka": "121.42.242.91:29092,121.42.242.91:39092,121.42.242.91:49092", - "PrepayDB": "server=118.190.144.92;database=jishe.sysdb;uid=sa;pwd=admin@2023;Encrypt=False;Trust Server Certificate=False", - "EnergyDB": "server=118.190.144.92;database=db_energy;uid=sa;pwd=admin@2023;Encrypt=False;Trust Server Certificate=False" - }, - "Redis": { - "Configuration": "118.190.144.92:6379,syncTimeout=30000,abortConnect=false,connectTimeout=30000,allowAdmin=true", - "DefaultDB": "14", - "HangfireDB": "15" - }, + "ConnectionStrings": { + "Default": "mongodb://admin:admin02023@118.190.144.92:37117,118.190.144.92:37119,118.190.144.92:37120/JiSheCollectBus?authSource=admin&maxPoolSize=400&minPoolSize=10&waitQueueTimeoutMS=5000", + "Kafka": "121.42.242.91:29092,121.42.242.91:39092,121.42.242.91:49092", + "PrepayDB": "server=118.190.144.92;database=jishe.sysdb;uid=sa;pwd=admin@2023;Encrypt=False;Trust Server Certificate=False", + "EnergyDB": "server=118.190.144.92;database=db_energy;uid=sa;pwd=admin@2023;Encrypt=False;Trust Server Certificate=False" + }, + "Redis": { + "Configuration": "118.190.144.92:6379,syncTimeout=30000,abortConnect=false,connectTimeout=30000,allowAdmin=true", + "DefaultDB": "14", + "HangfireDB": "15" + }, "Jwt": { "Audience": "JiShe.CollectBus", "SecurityKey": "dzehzRz9a8asdfasfdadfasdfasdfafsdadfasbasdf=", @@ -80,5 +80,11 @@ "Password": "123456", "Port": 5672 } + }, + "IoTDBOptions": { + "UserName": "root", + "Password": "root", + "ClusterList": [ "192.168.56.102:6667"], + "PoolSize": 10 } } \ No newline at end of file diff --git a/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTEntity.cs b/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTEntity.cs index 2b090de..45964fa 100644 --- a/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTEntity.cs +++ b/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTEntity.cs @@ -30,8 +30,8 @@ public string DeviceId { get; set; } /// - /// 时间戳 + /// 当前时间戳,单位秒 /// - public long Timestamps { get; set; } + public long Timestamps { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); } }