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