测试IoTDB实体约束

This commit is contained in:
ChenYi 2025-04-21 10:50:36 +08:00
parent cb6cfea4dd
commit 38283db1b2
4 changed files with 64 additions and 5 deletions

View File

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

View File

@ -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);
}
/// <summary>

View File

@ -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]

View File

@ -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; }
/// <summary>
/// 下发消息内容
/// </summary>
[FIELDColumn]
public string IssuedMessageHexString { get; set; }
///// <summary>
///// 下发消息Id
///// </summary>
//[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; }
}
}