解决单侧点模式数据处理
This commit is contained in:
parent
2beca87bb2
commit
f036e9546d
@ -128,16 +128,16 @@ public class SampleAppService : CollectBusAppService, ISampleAppService
|
||||
/// <param name="measuring"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task TestSingleMeasuringAFNData(string measuring, object value)
|
||||
public async Task TestSingleMeasuringAFNData(string measuring, string value)
|
||||
{
|
||||
SingleMeasuringAFNDataEntity meter = new SingleMeasuringAFNDataEntity()
|
||||
var meter = new SingleMeasuringAFNDataEntity<string>()
|
||||
{
|
||||
SystemName = "energy",
|
||||
DeviceId = "402440506",
|
||||
DeviceType = "Ammeter",
|
||||
ProjectCode = "10059",
|
||||
Timestamps = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
||||
SingleMeasuring = new Tuple<string, object>(measuring, value)
|
||||
SingleMeasuring = new Tuple<string, string>(measuring, value)
|
||||
};
|
||||
await _iotDBProvider.InsertAsync(meter);
|
||||
}
|
||||
|
||||
@ -10,12 +10,12 @@ namespace JiShe.CollectBus.IotSystems.AFNEntity
|
||||
/// <summary>
|
||||
/// AFN单项数据实体
|
||||
/// </summary>
|
||||
public class SingleMeasuringAFNDataEntity:IoTEntity
|
||||
public class SingleMeasuringAFNDataEntity<T> : IoTEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 单项数据对象
|
||||
/// </summary>
|
||||
[SingleMeasuring(nameof(SingleMeasuring))]
|
||||
public Tuple<string, object> SingleMeasuring { get; set; }
|
||||
public Tuple<string, T> SingleMeasuring { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace JiShe.CollectBus.IoTDBProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于标识当前实体为单侧点模式,单侧点模式只有一个Filed标识字段,类型是Tuple<string,object>,Item1=>测点名称,Item2=>测点值
|
||||
/// 用于标识当前实体为单侧点模式,单侧点模式只有一个Filed标识字段,类型是Tuple<string,object>,Item1=>测点名称,Item2=>测点值,泛型
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class SingleMeasuringAttribute : Attribute
|
||||
|
||||
@ -150,6 +150,7 @@ namespace JiShe.CollectBus.IoTDBProvider
|
||||
var rowValues = new List<object>();
|
||||
foreach (var measurement in metadata.ColumnNames)
|
||||
{
|
||||
|
||||
PropertyInfo propertyInfo = typeof(T).GetProperty(measurement);
|
||||
if (propertyInfo == null)
|
||||
{
|
||||
@ -157,18 +158,14 @@ namespace JiShe.CollectBus.IoTDBProvider
|
||||
}
|
||||
|
||||
var value = propertyInfo.GetValue(entity);
|
||||
if (propertyInfo.IsDefined(typeof(SingleMeasuringAttribute), false))//表示当前对象是单测点模式,
|
||||
if (propertyInfo.IsDefined(typeof(SingleMeasuringAttribute), false) && value != null)//表示当前对象是单测点模式,
|
||||
{
|
||||
Tuple<string, object> valueTuple = (Tuple<string, object>)value!;
|
||||
//获得当前Field对应的是的在measurement column中的序号,然后直接更新 metadata 中datetype对应序号的数据类型
|
||||
var indexOf = metadata.ColumnNames.IndexOf(measurement);
|
||||
metadata.ColumnNames[indexOf] = valueTuple.Item1;
|
||||
Type item2Type = valueTuple.Item2.GetType();
|
||||
metadata.DataTypes[indexOf] = GetDataTypeFromTypeName(valueTuple.Item2.GetType().Name);
|
||||
Type tupleType = value.GetType();
|
||||
Type[] tupleArgs = tupleType.GetGenericArguments();
|
||||
Type item2Type = tupleArgs[1]; // T 的实际类型
|
||||
var item2 = tupleType.GetProperty("Item2")!.GetValue(value);
|
||||
|
||||
rowValues.Add(valueTuple.Item2);
|
||||
|
||||
//TSDataType singleMeasuringTSDataType =
|
||||
rowValues.Add(item2);
|
||||
|
||||
}
|
||||
else
|
||||
@ -435,34 +432,21 @@ namespace JiShe.CollectBus.IoTDBProvider
|
||||
if (singleMeasuringAttribute != null && column == null)
|
||||
{
|
||||
//warning: 单侧点模式注意事项
|
||||
//Entity实体 字段类型是 Tuple<string,object>,Item1=>测点名称,Item2=>测点值
|
||||
//Entity实体 字段类型是 Tuple<string,T>,Item1=>测点名称,Item2=>测点值,泛型
|
||||
//只有一个Filed字段。
|
||||
//MeasuringName 默认为 SingleMeasuringAttribute.FieldName。
|
||||
//DateTye 默认为 string,在获取对用的Value值的时候在进行重置。
|
||||
|
||||
Type tupleType = prop.PropertyType;
|
||||
Type[] tupleArgs = tupleType.GetGenericArguments();
|
||||
|
||||
column = new ColumnInfo(
|
||||
singleMeasuringAttribute.FieldName,
|
||||
ColumnCategory.FIELD,
|
||||
GetDataTypeFromTypeName(singleMeasuringAttribute.FieldName),
|
||||
GetDataTypeFromTypeName(tupleArgs[1].Name),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
////按优先级顺序检查属性,避免重复反射
|
||||
//column = prop.GetCustomAttribute<TAGColumnAttribute>() is not null ? new ColumnInfo(
|
||||
// name: prop.Name, //使用属性名
|
||||
// category: ColumnCategory.TAG,
|
||||
// dataType: GetDataTypeFromTypeName(prop.PropertyType.Name)
|
||||
//) : prop.GetCustomAttribute<ATTRIBUTEColumnAttribute>() is not null ? new ColumnInfo(
|
||||
// prop.Name,
|
||||
// ColumnCategory.ATTRIBUTE,
|
||||
// GetDataTypeFromTypeName(prop.PropertyType.Name)
|
||||
//) : prop.GetCustomAttribute<FIELDColumnAttribute>() is not null ? new ColumnInfo(
|
||||
// prop.Name,
|
||||
// ColumnCategory.FIELD,
|
||||
// GetDataTypeFromTypeName(prop.PropertyType.Name)
|
||||
//) : null;
|
||||
|
||||
if (column.HasValue)
|
||||
{
|
||||
columns.Add(column.Value);
|
||||
|
||||
@ -53,7 +53,8 @@ namespace JiShe.CollectBus.IoTDBProvider.Provider
|
||||
/// <returns></returns>
|
||||
public async Task<int> InsertAsync(Tablet tablet)
|
||||
{
|
||||
return await _sessionPool.InsertAlignedTabletAsync(tablet);
|
||||
var result = await _sessionPool.InsertAlignedTabletAsync(tablet);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -51,7 +51,13 @@ namespace JiShe.CollectBus.IoTDBProvider.Provider
|
||||
/// <returns></returns>
|
||||
public async Task<int> InsertAsync(Tablet tablet)
|
||||
{
|
||||
return await _sessionPool.InsertAsync(tablet);
|
||||
var result = await _sessionPool.InsertAsync(tablet);
|
||||
if (result != 0)
|
||||
{
|
||||
throw new Exception($"{nameof(TableSessionPoolAdapter)} ");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user