diff --git a/src/JiShe.CollectBus.Application/Samples/SampleAppService.cs b/src/JiShe.CollectBus.Application/Samples/SampleAppService.cs
index 43bf8a4..28b6ab0 100644
--- a/src/JiShe.CollectBus.Application/Samples/SampleAppService.cs
+++ b/src/JiShe.CollectBus.Application/Samples/SampleAppService.cs
@@ -14,6 +14,7 @@ using Microsoft.Extensions.Options;
using JiShe.CollectBus.IoTDBProvider.Context;
using Microsoft.Extensions.Logging;
using JiShe.CollectBus.Common.Helpers;
+using JiShe.CollectBus.IotSystems.AFNEntity;
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
using Microsoft.Extensions.DependencyInjection;
@@ -69,8 +70,21 @@ public class SampleAppService : CollectBusAppService, ISampleAppService
[HttpGet]
public async Task UseTableSessionPool()
{
- //_dbContext.UseTableSessionPool = true;
- _iotDBProvider.SwitchSessionPool(true);
+ ElectricityMeter meter2 = new ElectricityMeter()
+ {
+ SystemName = "energy",
+ DeviceId = "402440506",
+ DeviceType = "Ammeter",
+ Current = 10,
+ MeterModel = "DDZY-1980",
+ ProjectCode = "10059",
+ Voltage = 10,
+ Timestamps = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+ };
+
+ await _iotDBProvider.InsertAsync(meter2);
+
+ _dbContext.UseTableSessionPool = true;
ElectricityMeter meter = new ElectricityMeter()
{
@@ -110,6 +124,27 @@ public class SampleAppService : CollectBusAppService, ISampleAppService
}
+ ///
+ /// 测试单个测点数据项
+ ///
+ ///
+ ///
+ [HttpGet]
+ public async Task TestSingleMeasuringAFNData(string measuring, string value)
+ {
+ var meter = new SingleMeasuringAFNDataEntity()
+ {
+ SystemName = "energy",
+ DeviceId = "402440506",
+ DeviceType = "Ammeter",
+ ProjectCode = "10059",
+ Timestamps = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+ SingleMeasuring = new Tuple(measuring, value)
+ };
+ await _iotDBProvider.InsertAsync(meter);
+ }
+
+
public Task GetAsync()
{
return Task.FromResult(
diff --git a/src/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs b/src/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs
index a823798..7311c42 100644
--- a/src/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs
+++ b/src/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs
@@ -764,7 +764,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
continue;
}
- var redisCacheKey = $"{string.Format(RedisConst.CacheMeterInfoKey, SystemType, MeterTypeEnum.WaterMeter, itemTimeDensity.Key)}{item.Key}";
+ var redisCacheKey = $"{string.Format(RedisConst.CacheMeterInfoKey, SystemType, ServerTagName, MeterTypeEnum.WaterMeter, itemTimeDensity.Key)}{item.Key}";
Dictionary keyValuePairs = new Dictionary();
foreach (var subItem in item)
{
@@ -781,7 +781,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
NextTask = DateTime.Now.AddMinutes(1)
};
- var taskRedisCacheKey = string.Format(RedisConst.CacheTasksToBeIssuedKey, SystemType, MeterTypeEnum.WaterMeter, itemTimeDensity.Key);
+ var taskRedisCacheKey = string.Format(RedisConst.CacheTasksToBeIssuedKey, SystemType, ServerTagName, MeterTypeEnum.WaterMeter, itemTimeDensity.Key);
await FreeRedisProvider.Instance.SetAsync(taskRedisCacheKey, nextTask);
}
_logger.LogInformation($"{nameof(InitAmmeterCacheData)} 初始化水表缓存数据完成");
diff --git a/src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/AFNDataEntity.cs b/src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/SingleMeasuringAFNDataEntity.cs
similarity index 53%
rename from src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/AFNDataEntity.cs
rename to src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/SingleMeasuringAFNDataEntity.cs
index 5f0e44c..751e9e3 100644
--- a/src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/AFNDataEntity.cs
+++ b/src/JiShe.CollectBus.Domain/IotSystems/AFNEntity/SingleMeasuringAFNDataEntity.cs
@@ -10,8 +10,12 @@ namespace JiShe.CollectBus.IotSystems.AFNEntity
///
/// AFN单项数据实体
///
- public class AFNDataEntity:IoTEntity
+ public class SingleMeasuringAFNDataEntity : IoTEntity
{
- public string ItemCode { get; set; }
+ ///
+ /// 单项数据对象
+ ///
+ [SingleMeasuring(nameof(SingleMeasuring))]
+ public Tuple SingleMeasuring { get; set; }
}
}
diff --git a/src/JiShe.CollectBus.Host/appsettings.json b/src/JiShe.CollectBus.Host/appsettings.json
index 4416fd2..2c72f7d 100644
--- a/src/JiShe.CollectBus.Host/appsettings.json
+++ b/src/JiShe.CollectBus.Host/appsettings.json
@@ -35,12 +35,12 @@
},
"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": "192.168.0.151:29092,192.168.0.151:39092,192.168.0.151:49092",
+ "Kafka": "192.168.1.9:29092,192.168.1.9:39092,192.168.1.9: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": "192.168.0.151:6380,password=1q2w3e!@#,syncTimeout=30000,abortConnect=false,connectTimeout=30000,allowAdmin=true",
+ "Configuration": "192.168.1.9:6380,password=1q2w3e!@#,syncTimeout=30000,abortConnect=false,connectTimeout=30000,allowAdmin=true",
"DefaultDB": "14",
"HangfireDB": "15"
},
@@ -95,7 +95,7 @@
"Kafka": {
"Connections": {
"Default": {
- "BootstrapServers": "121.42.242.91:29092,121.42.242.91:39092,121.42.242.91:49092"
+ "BootstrapServers": "192.168.1.9:29092,192.168.1.9:39092,192.168.1.9:49092"
// "SecurityProtocol": "SASL_PLAINTEXT",
// "SaslMechanism": "PLAIN",
// "SaslUserName": "lixiao",
@@ -121,7 +121,7 @@
"IoTDBOptions": {
"UserName": "root",
"Password": "root",
- "ClusterList": [ "192.168.0.151:6667" ],
+ "ClusterList": [ "192.168.1.9:6667" ],
"PoolSize": 2,
"DataBaseName": "energy",
"OpenDebugMode": true,
diff --git a/src/JiShe.CollectBus.IoTDBProvider/Attribute/SingleMeasuringAttribute.cs b/src/JiShe.CollectBus.IoTDBProvider/Attribute/SingleMeasuringAttribute.cs
index f69fd99..ba5af69 100644
--- a/src/JiShe.CollectBus.IoTDBProvider/Attribute/SingleMeasuringAttribute.cs
+++ b/src/JiShe.CollectBus.IoTDBProvider/Attribute/SingleMeasuringAttribute.cs
@@ -7,10 +7,16 @@ using System.Threading.Tasks;
namespace JiShe.CollectBus.IoTDBProvider
{
///
- /// 用于标识当前实体为单个测点,单侧点标识字段类型是Dictionary
+ /// 用于标识当前实体为单侧点模式,单侧点模式只有一个Filed标识字段,类型是Tuple,Item1=>测点名称,Item2=>测点值,泛型
///
[AttributeUsage(AttributeTargets.Property)]
public class SingleMeasuringAttribute : Attribute
{
+ public string FieldName { get; set;}
+
+ public SingleMeasuringAttribute(string fieldName)
+ {
+ FieldName = fieldName;
+ }
}
}
diff --git a/src/JiShe.CollectBus.IoTDBProvider/Interface/IIoTDBProvider.cs b/src/JiShe.CollectBus.IoTDBProvider/Interface/IIoTDBProvider.cs
index b67f17d..0aad03e 100644
--- a/src/JiShe.CollectBus.IoTDBProvider/Interface/IIoTDBProvider.cs
+++ b/src/JiShe.CollectBus.IoTDBProvider/Interface/IIoTDBProvider.cs
@@ -11,11 +11,11 @@ namespace JiShe.CollectBus.IoTDBProvider
///
public interface IIoTDBProvider
{
- ///
- /// 切换 SessionPool
- ///
- /// 是否使用表模型
- void SwitchSessionPool(bool useTableSession);
+ /////
+ ///// 切换 SessionPool
+ /////
+ ///// 是否使用表模型
+ //void SwitchSessionPool(bool useTableSession);
///
/// 插入数据
diff --git a/src/JiShe.CollectBus.IoTDBProvider/Interface/IIoTDBSessionFactory.cs b/src/JiShe.CollectBus.IoTDBProvider/Interface/IIoTDBSessionFactory.cs
index b904ba0..c7d9b10 100644
--- a/src/JiShe.CollectBus.IoTDBProvider/Interface/IIoTDBSessionFactory.cs
+++ b/src/JiShe.CollectBus.IoTDBProvider/Interface/IIoTDBSessionFactory.cs
@@ -9,7 +9,7 @@ namespace JiShe.CollectBus.IoTDBProvider.Interface
///
/// Session 工厂接口
///
- public interface IIoTDBSessionFactory
+ public interface IIoTDBSessionFactory:IDisposable
{
IIoTDBSessionPool GetSessionPool(bool useTableSession);
}
diff --git a/src/JiShe.CollectBus.IoTDBProvider/Provider/DeviceMetadata.cs b/src/JiShe.CollectBus.IoTDBProvider/Provider/DeviceMetadata.cs
index 0d5b408..6bdbd56 100644
--- a/src/JiShe.CollectBus.IoTDBProvider/Provider/DeviceMetadata.cs
+++ b/src/JiShe.CollectBus.IoTDBProvider/Provider/DeviceMetadata.cs
@@ -12,10 +12,15 @@ namespace JiShe.CollectBus.IoTDBProvider
///
public class DeviceMetadata
{
+ ///
+ /// 是否有单测量值
+ ///
+ public bool IsSingleMeasuring { get; set; }
+
///
/// 测量值集合,用于构建Table的测量值,也就是columnNames参数
///
- public List ColumnNames { get; } = new();
+ public List ColumnNames { get; set; } = new();
///
/// 列类型集合,用于构建Table的列类型,也就是columnCategories参数
@@ -25,6 +30,6 @@ namespace JiShe.CollectBus.IoTDBProvider
///
/// 值类型集合,用于构建Table的值类型,也就是dataTypes参数
///
- public ListDataTypes { get; } = new();
+ public List DataTypes { get; } = new();
}
}
diff --git a/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTDBProvider.cs b/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTDBProvider.cs
index 504709e..705b2c1 100644
--- a/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTDBProvider.cs
+++ b/src/JiShe.CollectBus.IoTDBProvider/Provider/IoTDBProvider.cs
@@ -9,6 +9,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
+using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
@@ -24,12 +25,14 @@ namespace JiShe.CollectBus.IoTDBProvider
///
public class IoTDBProvider : IIoTDBProvider
{
- private IIoTDBSessionPool _currentSession;
private static readonly ConcurrentDictionary _metadataCache = new();
private readonly ILogger _logger;
private readonly IIoTDBSessionFactory _sessionFactory;
private readonly IoTDBRuntimeContext _runtimeContext;
+ private IIoTDBSessionPool CurrentSession =>
+ _sessionFactory.GetSessionPool(_runtimeContext.UseTableSessionPool);
+
public IoTDBProvider(
ILogger logger,
IIoTDBSessionFactory sessionFactory,
@@ -39,37 +42,6 @@ namespace JiShe.CollectBus.IoTDBProvider
_sessionFactory = sessionFactory;
_runtimeContext = runtimeContext;
- RefreshSessionPool();
- }
-
- private void RefreshSessionPool()
- {
- try
- {
- _currentSession?.Dispose();
- _currentSession = _sessionFactory.GetSessionPool(_runtimeContext.UseTableSessionPool);
- _currentSession.OpenAsync().ConfigureAwait(false).GetAwaiter().GetResult();
- }
- catch (Exception ex)
- {
- //自动回退到备用SessionPool
- _logger.LogError($"{nameof(RefreshSessionPool)} 切换SessionPool失败,回退到默认配置:{ex.Serialize()}");
- _runtimeContext.UseTableSessionPool = !_runtimeContext.UseTableSessionPool;
- _currentSession = _sessionFactory.GetSessionPool(_runtimeContext.UseTableSessionPool);
- }
- }
-
- ///
- /// 切换 SessionPool
- ///
- ///
- public void SwitchSessionPool(bool useTableSession)
- {
- if (_runtimeContext.UseTableSessionPool != useTableSession)
- {
- _runtimeContext.UseTableSessionPool = useTableSession;
- RefreshSessionPool();
- }
}
///
@@ -83,8 +55,8 @@ namespace JiShe.CollectBus.IoTDBProvider
var metadata = GetMetadata();
var tablet = BuildTablet(new[] { entity }, metadata);
-
- await _currentSession.InsertAsync(tablet);
+
+ await CurrentSession.InsertAsync(tablet);
//int result = await _currentSession.InsertAsync(tablet);
//if (result <= 0)
@@ -108,7 +80,7 @@ namespace JiShe.CollectBus.IoTDBProvider
foreach (var batch in batches)
{
var tablet = BuildTablet(batch, metadata);
- await _currentSession.InsertAsync(tablet);
+ await CurrentSession.InsertAsync(tablet);
//var result = await _currentSession.InsertAsync(tablet);
//if (result <= 0)
//{
@@ -127,7 +99,7 @@ namespace JiShe.CollectBus.IoTDBProvider
public async Task