iotdb封装

This commit is contained in:
ChenYi 2025-04-02 17:46:33 +08:00
parent a5f806c481
commit e1d4126db0
7 changed files with 85 additions and 24 deletions

View File

@ -15,6 +15,7 @@ using JiShe.CollectBus.Workers;
using Volo.Abp.BackgroundWorkers.Hangfire; using Volo.Abp.BackgroundWorkers.Hangfire;
using JiShe.CollectBus.MongoDB; using JiShe.CollectBus.MongoDB;
using JiShe.CollectBus.ScheduledMeterReading; using JiShe.CollectBus.ScheduledMeterReading;
using JiShe.CollectBus.IoTDBProvider;
namespace JiShe.CollectBus; namespace JiShe.CollectBus;
@ -25,6 +26,7 @@ namespace JiShe.CollectBus;
typeof(AbpAutoMapperModule), typeof(AbpAutoMapperModule),
typeof(AbpBackgroundWorkersHangfireModule), typeof(AbpBackgroundWorkersHangfireModule),
typeof(CollectBusFreeRedisModule), typeof(CollectBusFreeRedisModule),
typeof(CollectBusIoTDBModule),
typeof(CollectBusFreeSqlModule) typeof(CollectBusFreeSqlModule)
)] )]
public class CollectBusApplicationModule : AbpModule public class CollectBusApplicationModule : AbpModule

View File

@ -1,6 +1,9 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using JiShe.CollectBus.Ammeters;
using JiShe.CollectBus.FreeSql; using JiShe.CollectBus.FreeSql;
using JiShe.CollectBus.IoTDBProvider;
using JiShe.CollectBus.IotSystems.PrepayModel; using JiShe.CollectBus.IotSystems.PrepayModel;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -8,6 +11,31 @@ namespace JiShe.CollectBus.Samples;
public class SampleAppService : CollectBusAppService, ISampleAppService 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<SampleDto> GetAsync() public Task<SampleDto> GetAsync()
{ {
return Task.FromResult( return Task.FromResult(

View File

@ -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;
}
}

View File

@ -24,6 +24,7 @@
<ProjectReference Include="..\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" /> <ProjectReference Include="..\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Domain.Shared\JiShe.CollectBus.Domain.Shared.csproj" /> <ProjectReference Include="..\JiShe.CollectBus.Domain.Shared\JiShe.CollectBus.Domain.Shared.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.FreeSql\JiShe.CollectBus.FreeSql.csproj" /> <ProjectReference Include="..\JiShe.CollectBus.FreeSql\JiShe.CollectBus.FreeSql.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.IoTDBProvider\JiShe.CollectBus.IoTDBProvider.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -290,15 +290,15 @@ namespace JiShe.CollectBus.Host
var producerConfig = new ProducerConfig(); var producerConfig = new ProducerConfig();
context.Services context.Services
.ConfigureKafkaTestOptions(options => // .ConfigureKafkaTestOptions(options =>
{ // {
#if DEBUG //#if DEBUG
options.CleanTopicsOnStart = true;// 测试时每次启动都删除topic,生产环境不需要 // options.CleanTopicsOnStart = true;// 测试时每次启动都删除topic,生产环境不需要
#endif //#endif
options.CreateTopicsIfNotExists = true; // options.CreateTopicsIfNotExists = true;
options.TopicNames = ProtocolConstExtensions.GetAllTopicNames(); // options.TopicNames = ProtocolConstExtensions.GetAllTopicNames();
}) // })
.AddMassTransit(x => .AddMassTransit(x =>
{ {
x.UsingInMemory((context, cfg) => cfg.ConfigureEndpoints(context)); x.UsingInMemory((context, cfg) => cfg.ConfigureEndpoints(context));

View File

@ -80,5 +80,11 @@
"Password": "123456", "Password": "123456",
"Port": 5672 "Port": 5672
} }
},
"IoTDBOptions": {
"UserName": "root",
"Password": "root",
"ClusterList": [ "192.168.56.102:6667"],
"PoolSize": 10
} }
} }

View File

@ -30,8 +30,8 @@
public string DeviceId { get; set; } public string DeviceId { get; set; }
/// <summary> /// <summary>
/// 时间戳 /// 当前时间戳,单位秒
/// </summary> /// </summary>
public long Timestamps { get; set; } public long Timestamps { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
} }
} }