完善IoTDB驱动,适配增量源码生成器
This commit is contained in:
parent
c03207aa21
commit
fa593de754
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.CodeAnalysis;
|
using JiShe.CollectBus.Analyzers.Shared;
|
||||||
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -40,20 +41,39 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
|||||||
private static ClassDeclarationSyntax GetClassDeclaration(GeneratorSyntaxContext context)
|
private static ClassDeclarationSyntax GetClassDeclaration(GeneratorSyntaxContext context)
|
||||||
{
|
{
|
||||||
var classDecl = (ClassDeclarationSyntax)context.Node;
|
var classDecl = (ClassDeclarationSyntax)context.Node;
|
||||||
var attributeType = context.SemanticModel.Compilation.GetTypeByMetadataName(AttributeFullName);
|
var semanticModel = context.SemanticModel;
|
||||||
|
|
||||||
foreach (var attribute in classDecl.AttributeLists.SelectMany(al => al.Attributes))
|
// 获取类符号
|
||||||
|
var classSymbol = semanticModel.GetDeclaredSymbol(classDecl) as INamedTypeSymbol;
|
||||||
|
if (classSymbol == null) return null;
|
||||||
|
|
||||||
|
// 检查是否包含 SourceAnalyzers 特性
|
||||||
|
var sourceAnalyzerAttr = classSymbol.GetAttributes().FirstOrDefault(attr => attr.AttributeClass?.ToDisplayString() == AttributeFullName);
|
||||||
|
|
||||||
|
// 必须包含 EntityType 参数
|
||||||
|
if (sourceAnalyzerAttr == null ||
|
||||||
|
sourceAnalyzerAttr.ConstructorArguments.Length == 0)
|
||||||
{
|
{
|
||||||
var symbol = context.SemanticModel.GetSymbolInfo(attribute).Symbol;
|
|
||||||
if (symbol is IMethodSymbol ctor &&
|
|
||||||
SymbolEqualityComparer.Default.Equals(ctor.ContainingType, attributeType))
|
|
||||||
{
|
|
||||||
return classDecl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return classDecl;
|
||||||
|
|
||||||
|
//var classDecl = (ClassDeclarationSyntax)context.Node;
|
||||||
|
//var attributeType = context.SemanticModel.Compilation.GetTypeByMetadataName(AttributeFullName);
|
||||||
|
|
||||||
|
//foreach (var attribute in classDecl.AttributeLists.SelectMany(al => al.Attributes))
|
||||||
|
//{
|
||||||
|
// var symbol = context.SemanticModel.GetSymbolInfo(attribute).Symbol;
|
||||||
|
// if (symbol is IMethodSymbol ctor &&
|
||||||
|
// SymbolEqualityComparer.Default.Equals(ctor.ContainingType, attributeType))
|
||||||
|
// {
|
||||||
|
// return classDecl;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 递归获取所有层级的属性
|
/// 递归获取所有层级的属性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -154,6 +174,25 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
|||||||
Compilation compilation,
|
Compilation compilation,
|
||||||
HashSet<ITypeSymbol> processedTypes)
|
HashSet<ITypeSymbol> processedTypes)
|
||||||
{
|
{
|
||||||
|
// 获取 SourceAnalyzers 特性的 EntityType 参数
|
||||||
|
var sourceAnalyzerAttr = classSymbol.GetAttributes()
|
||||||
|
.FirstOrDefault(attr =>
|
||||||
|
attr.AttributeClass?.ToDisplayString() == AttributeFullName);
|
||||||
|
|
||||||
|
// 解析 EntityType 枚举值
|
||||||
|
string entityTypeValue = "EntityTypeEnum.Other"; // 默认值
|
||||||
|
if (sourceAnalyzerAttr != null &&
|
||||||
|
sourceAnalyzerAttr.ConstructorArguments.Length > 0)
|
||||||
|
{
|
||||||
|
var arg = sourceAnalyzerAttr.ConstructorArguments[0];
|
||||||
|
if (arg.Kind == TypedConstantKind.Enum &&
|
||||||
|
arg.Type is INamedTypeSymbol enumType)
|
||||||
|
{
|
||||||
|
int enumValue = (int)arg.Value!;
|
||||||
|
entityTypeValue = GetEnumMemberName(enumType, enumValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var code = new StringBuilder();
|
var code = new StringBuilder();
|
||||||
code.AppendLine("// <auto-generated/>");
|
code.AppendLine("// <auto-generated/>");
|
||||||
code.AppendLine("#nullable enable");
|
code.AppendLine("#nullable enable");
|
||||||
@ -185,6 +224,8 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
|||||||
|
|
||||||
//类名称
|
//类名称
|
||||||
code.AppendLine($" public string EntityName {{get;}} = \"{classSymbol.Name}\";");
|
code.AppendLine($" public string EntityName {{get;}} = \"{classSymbol.Name}\";");
|
||||||
|
// 添加 EntityType 属性
|
||||||
|
code.AppendLine($" public EntityTypeEnum? EntityType {{ get; }} = {entityTypeValue};");
|
||||||
|
|
||||||
foreach (var prop in propList)
|
foreach (var prop in propList)
|
||||||
{
|
{
|
||||||
@ -487,8 +528,10 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
|||||||
|
|
||||||
foreach (var prop in propList)
|
foreach (var prop in propList)
|
||||||
{
|
{
|
||||||
var propType = prop.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
var entityType = prop.ContainingType.ToDisplayString();//entity 实体类型名称
|
||||||
var parentType = prop.ContainingType.ToDisplayString();
|
var propType = prop.Type;//实体属性的类型
|
||||||
|
var propTypeName = propType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||||
|
var declaredTypeName = propType.Name; // 直接获取类型名称(如 "Int32")
|
||||||
|
|
||||||
// 处理主属性
|
// 处理主属性
|
||||||
var propAttributes = prop.GetAttributes()
|
var propAttributes = prop.GetAttributes()
|
||||||
@ -503,9 +546,10 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
|||||||
mainMember.Append(
|
mainMember.Append(
|
||||||
$"new EntityMemberInfo(" +
|
$"new EntityMemberInfo(" +
|
||||||
$"\"{prop.Name}\", " +
|
$"\"{prop.Name}\", " +
|
||||||
$"typeof({propType}), " +
|
$"typeof({propTypeName}), " +
|
||||||
$"(e) => Get{prop.Name}(({parentType})e), " +
|
$"\"{declaredTypeName}\", " +
|
||||||
$"(e, v) => Set{prop.Name}(({parentType})e, ({propType})v))");
|
$"(e) => Get{prop.Name}(({entityType})e), " +
|
||||||
|
$"(e, v) => Set{prop.Name}(({entityType})e, ({propTypeName})v))");
|
||||||
|
|
||||||
if (attributeInitializers.Any())
|
if (attributeInitializers.Any())
|
||||||
{
|
{
|
||||||
@ -516,20 +560,22 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
|||||||
|
|
||||||
initializerLines.Add(mainMember.ToString());
|
initializerLines.Add(mainMember.ToString());
|
||||||
|
|
||||||
// 处理元组元素(假设不需要处理元组元素的特性)
|
// 处理元组元素,(暂不需要处理元组元素的特性)
|
||||||
if (prop.Type is INamedTypeSymbol { IsTupleType: true } tupleType)
|
if (prop.Type is INamedTypeSymbol { IsTupleType: true } tupleType)
|
||||||
{
|
{
|
||||||
foreach (var element in tupleType.TupleElements)
|
foreach (var element in tupleType.TupleElements)
|
||||||
{
|
{
|
||||||
var elementType = element.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
var elementType = element.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);//元组元素的类型
|
||||||
var elementName = element.Name;
|
var elementName = element.Name;//元组元素名称
|
||||||
|
var elementDeclaredName = element.Type.Name;//元组元素类型名称
|
||||||
|
|
||||||
initializerLines.Add(
|
initializerLines.Add(
|
||||||
$"new EntityMemberInfo(" +
|
$"new EntityMemberInfo(" +
|
||||||
$"\"{prop.Name}.{elementName}\", " +
|
$"\"{prop.Name}.{elementName}\", " +
|
||||||
$"typeof({elementType}), " +
|
$"typeof({elementType}), " +
|
||||||
$"(e) => Get{prop.Name}_{elementName}(({parentType})e), " +
|
$"\"{elementDeclaredName}\", " +
|
||||||
$"(e, v) => Set{prop.Name}_{elementName}(({parentType})e, ({elementType})v))");
|
$"(e) => Get{prop.Name}_{elementName}(({entityType})e), " +
|
||||||
|
$"(e, v) => Set{prop.Name}_{elementName}(({entityType})e, ({elementType})v))");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -621,5 +667,23 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
|||||||
{
|
{
|
||||||
return attribute.AttributeClass?.ToDisplayString() == "System.Runtime.CompilerServices.CompilerGeneratedAttribute";
|
return attribute.AttributeClass?.ToDisplayString() == "System.Runtime.CompilerServices.CompilerGeneratedAttribute";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取枚举的参数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enumType"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static string GetEnumMemberName(INamedTypeSymbol enumType, int value)
|
||||||
|
{
|
||||||
|
foreach (var member in enumType.GetMembers().OfType<IFieldSymbol>())
|
||||||
|
{
|
||||||
|
if (member.ConstantValue is int intValue && intValue == value)
|
||||||
|
{
|
||||||
|
return $"{enumType.ToDisplayString()}.{member.Name}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $"{enumType.ToDisplayString()}.Other";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,19 +0,0 @@
|
|||||||
using JiShe.CollectBus.IoTDB.Enums;
|
|
||||||
|
|
||||||
namespace JiShe.CollectBus.IoTDB.Attributes
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// IoTDB实体类型特性
|
|
||||||
/// </summary>
|
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
|
||||||
public class EntityTypeAttribute : System.Attribute
|
|
||||||
{
|
|
||||||
public EntityTypeEnum EntityType { get; }
|
|
||||||
|
|
||||||
|
|
||||||
public EntityTypeAttribute(EntityTypeEnum entityType)
|
|
||||||
{
|
|
||||||
EntityType = entityType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using JiShe.CollectBus.IoTDB.Enums;
|
|
||||||
|
|
||||||
namespace JiShe.CollectBus.IoTDB.Attributes
|
namespace JiShe.CollectBus.IoTDB.Attributes
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
12
modules/JiShe.CollectBus.IoTDB/Model/Class1.cs
Normal file
12
modules/JiShe.CollectBus.IoTDB/Model/Class1.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace JiShe.CollectBus.IoTDB.Model
|
||||||
|
{
|
||||||
|
internal class Class1
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using JiShe.CollectBus.Common.Attributes;
|
using JiShe.CollectBus.Common.Attributes;
|
||||||
|
using JiShe.CollectBus.Common.Consts;
|
||||||
using JiShe.CollectBus.IoTDB.Attributes;
|
using JiShe.CollectBus.IoTDB.Attributes;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.IoTDB.Model
|
namespace JiShe.CollectBus.IoTDB.Model
|
||||||
@ -20,6 +21,12 @@ namespace JiShe.CollectBus.IoTDB.Model
|
|||||||
[TAGColumn]
|
[TAGColumn]
|
||||||
public string ProjectId { get; set; }
|
public string ProjectId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据类型
|
||||||
|
/// </summary>
|
||||||
|
[TAGColumn]
|
||||||
|
public string DataType { get; set; } = IOTDBDataTypeConst.Data;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备类型集中器、电表、水表、流量计、传感器等
|
/// 设备类型集中器、电表、水表、流量计、传感器等
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -1,14 +1,12 @@
|
|||||||
using JiShe.CollectBus.Analyzers.Shared;
|
using JiShe.CollectBus.Analyzers.Shared;
|
||||||
using JiShe.CollectBus.IoTDB.Attributes;
|
using JiShe.CollectBus.IoTDB.Attributes;
|
||||||
using JiShe.CollectBus.IoTDB.Enums;
|
|
||||||
|
|
||||||
namespace JiShe.CollectBus.IoTDB.Model
|
namespace JiShe.CollectBus.IoTDB.Model
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Table模型单项数据实体
|
/// Table模型单项数据实体
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EntityType(EntityTypeEnum.TableModel)]
|
[SourceAnalyzers(EntityTypeEnum.TableModel)]
|
||||||
[SourceAnalyzers]
|
|
||||||
public class TableModelSingleMeasuringEntity<T> : IoTEntity
|
public class TableModelSingleMeasuringEntity<T> : IoTEntity
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,14 +1,12 @@
|
|||||||
using JiShe.CollectBus.Analyzers.Shared;
|
using JiShe.CollectBus.Analyzers.Shared;
|
||||||
using JiShe.CollectBus.IoTDB.Attributes;
|
using JiShe.CollectBus.IoTDB.Attributes;
|
||||||
using JiShe.CollectBus.IoTDB.Enums;
|
|
||||||
|
|
||||||
namespace JiShe.CollectBus.IoTDB.Model
|
namespace JiShe.CollectBus.IoTDB.Model
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tree模型单项数据实体
|
/// Tree模型单项数据实体
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EntityType(EntityTypeEnum.TreeModel)]
|
[SourceAnalyzers(EntityTypeEnum.TreeModel)]
|
||||||
[SourceAnalyzers]
|
|
||||||
public class TreeModelSingleMeasuringEntity<T> : IoTEntity
|
public class TreeModelSingleMeasuringEntity<T> : IoTEntity
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
using Apache.IoTDB;
|
using Apache.IoTDB;
|
||||||
using JiShe.CollectBus.IoTDB.Enums;
|
using JiShe.CollectBus.Analyzers.Shared;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.IoTDB.Provider
|
namespace JiShe.CollectBus.IoTDB.Provider
|
||||||
{
|
{
|
||||||
@ -9,9 +9,9 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
public class DeviceMetadata
|
public class DeviceMetadata
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IoTDB实体类型枚举
|
/// 实体类型枚举
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityTypeEnum EntityType { get; set; }
|
public EntityTypeEnum? EntityType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否有单测量值
|
/// 是否有单测量值
|
||||||
|
|||||||
@ -15,7 +15,7 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetDevicePath<T>(T entity) where T : IoTEntity
|
public static string GetDevicePath<T>(T entity) where T : IoTEntity
|
||||||
{
|
{
|
||||||
return $"root.{entity.SystemName.ToLower()}.`{entity.ProjectId}`.`{entity.DeviceType}`.`{entity.DeviceId}`";
|
return $"root.{entity.SystemName.ToLower()}.`{entity.ProjectId}`.`{entity.DeviceType}`.{entity.DataType}.`{entity.DeviceId}`";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -195,6 +195,8 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
metadata.EntityType = accessor.EntityType;
|
||||||
|
|
||||||
return await Task.FromResult(metaData);
|
return await Task.FromResult(metaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,23 +267,28 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
|
|
||||||
var accessor = SourceEntityAccessorFactory.GetAccessor<T>();
|
var accessor = SourceEntityAccessorFactory.GetAccessor<T>();
|
||||||
|
|
||||||
var entityTypeAttribute = typeof(T).GetCustomAttribute<EntityTypeAttribute>();
|
var memberCache = new Dictionary<string, EntityMemberInfo>(); // 缓存优化查询
|
||||||
|
// 预构建成员缓存(Key: NameOrPath)
|
||||||
|
foreach (var member in accessor.MemberList)
|
||||||
|
{
|
||||||
|
memberCache[member.NameOrPath] = member;
|
||||||
|
}
|
||||||
|
|
||||||
if (entityTypeAttribute == null)
|
if (accessor.EntityType == null || metadata.EntityType == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构{nameof(Tablet)}时 {nameof(T)}的EntityType 没有指定,属于异常情况,-101");
|
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构{nameof(Tablet)}时 {nameof(T)}的EntityType 没有指定,属于异常情况,-101");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metadata.EntityType != entityTypeAttribute.EntityType)
|
if (metadata.EntityType != accessor.EntityType)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构{nameof(Tablet)}时 {nameof(T)}的EntityType 和{nameof(DeviceMetadata)}的 EntityType 不一致,属于异常情况,-102");
|
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构{nameof(Tablet)}时 {nameof(T)}的EntityType 和{nameof(DeviceMetadata)}的 EntityType 不一致,属于异常情况,-102");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metadata.EntityType == Enums.EntityTypeEnum.TreeModel && _runtimeContext.UseTableSessionPool == true)
|
if (metadata.EntityType == EntityTypeEnum.TreeModel && _runtimeContext.UseTableSessionPool == true)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构{nameof(Tablet)}时 tree模型不能使用table模型Session连接,属于异常情况,-103");
|
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构{nameof(Tablet)}时 tree模型不能使用table模型Session连接,属于异常情况,-103");
|
||||||
}
|
}
|
||||||
else if (metadata.EntityType == Enums.EntityTypeEnum.TableModel && _runtimeContext.UseTableSessionPool == false)
|
else if (metadata.EntityType == EntityTypeEnum.TableModel && _runtimeContext.UseTableSessionPool == false)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构{nameof(Tablet)}时 table模型不能使用tree模型Session连接,属于异常情况,-104");
|
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构{nameof(Tablet)}时 table模型不能使用tree模型Session连接,属于异常情况,-104");
|
||||||
}
|
}
|
||||||
@ -300,12 +307,30 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
|
|
||||||
foreach (var measurement in tempColumnNames)
|
foreach (var measurement in tempColumnNames)
|
||||||
{
|
{
|
||||||
var value = accessor.GetPropertyValue(entity, measurement);
|
if (!memberCache.TryGetValue(measurement, out var member))
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构时{accessor.EntityName}没有找到{measurement}对应的member信息,-105");
|
||||||
|
}
|
||||||
|
|
||||||
|
var value = member.GetValue(entity);
|
||||||
|
|
||||||
|
// 特性查询优化
|
||||||
|
var attributes = member.CustomAttributes ?? Enumerable.Empty<Attribute>();
|
||||||
|
var singleMeasuringAttr = attributes.OfType<SingleMeasuringAttribute>().FirstOrDefault();
|
||||||
|
if (singleMeasuringAttr != null)//如果是单侧点
|
||||||
|
{
|
||||||
|
var tupleItemKey = $"{member.NameOrPath}.Item2";
|
||||||
|
if (!memberCache.TryGetValue(tupleItemKey, out var tupleMember))
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"{nameof(BuildTablet)} 构建存储结构时{accessor.EntityName} 没有找到{measurement}对应的member Item2 信息,-106");
|
||||||
|
}
|
||||||
|
|
||||||
|
value = tupleMember.GetValue(entity);
|
||||||
|
}
|
||||||
|
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
Type tupleType = value.GetType();
|
var tempValue = member.DeclaredTypeName.ToUpper() switch
|
||||||
var tempValue = tupleType.Name.ToUpper() switch
|
|
||||||
{
|
{
|
||||||
"DATETIME" => Convert.ToDateTime(value).GetDateTimeOffset().ToUnixTimeNanoseconds(),
|
"DATETIME" => Convert.ToDateTime(value).GetDateTimeOffset().ToUnixTimeNanoseconds(),
|
||||||
_ => value
|
_ => value
|
||||||
@ -319,70 +344,6 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//foreach (var measurement in tempColumnNames)
|
|
||||||
//{
|
|
||||||
|
|
||||||
// PropertyInfo propertyInfo = typeof(T).GetProperty(measurement);
|
|
||||||
// if (propertyInfo == null)
|
|
||||||
// {
|
|
||||||
// throw new Exception($"{nameof(BuildTablet)} 构建表模型{typeof(T).Name}时,没有找到{measurement}属性,属于异常情况,-101。");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var value = propertyInfo.GetValue(entity);
|
|
||||||
// if (propertyInfo.IsDefined(typeof(SingleMeasuringAttribute), false) && metadata.IsSingleMeasuring == true)//表示当前对象是单测点模式
|
|
||||||
// {
|
|
||||||
// if (value != null)
|
|
||||||
// {
|
|
||||||
// Type tupleType = value.GetType();
|
|
||||||
// Type[] tupleArgs = tupleType.GetGenericArguments();
|
|
||||||
// Type item2Type = tupleArgs[1]; // T 的实际类型
|
|
||||||
// var item1 = tupleType.GetProperty("Item1")!.GetValue(value);
|
|
||||||
// var item2 = tupleType.GetProperty("Item2")!.GetValue(value);
|
|
||||||
// if (item1 == null || item2 == null)
|
|
||||||
// {
|
|
||||||
// throw new Exception($"{nameof(BuildTablet)} 构建表模型{typeof(T).Name}时,单测点模式构建失败,没有获取测点名称或者测点值,-102。");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var indexOf = metadata.ColumnNames.IndexOf(measurement);
|
|
||||||
// metadata.ColumnNames[indexOf] = (string)item1!;
|
|
||||||
|
|
||||||
// rowValues.Add(item2);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// rowValues.Add(null);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //同时如果是单测点模式,且是table模型存储,路径只能通过DevicePathBuilder.GetDeviceTableName(entity)获取
|
|
||||||
// if (_runtimeContext.UseTableSessionPool)
|
|
||||||
// {
|
|
||||||
// tableNameOrTreePath = DevicePathBuilder.GetDeviceTableName(entity);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
|
|
||||||
// //需要根据value的类型,进行相应的值映射转换,例如datetime转换为long的时间戳值
|
|
||||||
// if (value != null)
|
|
||||||
// {
|
|
||||||
// Type tupleType = value.GetType();
|
|
||||||
// var tempValue = tupleType.Name.ToUpper() switch
|
|
||||||
// {
|
|
||||||
// "DATETIME" => Convert.ToDateTime(value).GetDateTimeOffset().ToUnixTimeNanoseconds(),
|
|
||||||
// _ => value
|
|
||||||
// };
|
|
||||||
|
|
||||||
// rowValues.Add(tempValue);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// rowValues.Add(value);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
values.Add(rowValues);
|
values.Add(rowValues);
|
||||||
|
|
||||||
//如果指定了路径
|
//如果指定了路径
|
||||||
@ -573,16 +534,20 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
var results = new List<T>();
|
var results = new List<T>();
|
||||||
var metadata = await GetMetadata<T>();
|
var metadata = await GetMetadata<T>();
|
||||||
|
|
||||||
var properties = typeof(T).GetProperties();
|
var accessor = SourceEntityAccessorFactory.GetAccessor<T>();
|
||||||
|
var memberCache = new Dictionary<string, EntityMemberInfo>(); // 缓存优化查询
|
||||||
|
|
||||||
|
// 预构建成员缓存(Key: NameOrPath)
|
||||||
|
foreach (var member in accessor.MemberList)
|
||||||
|
{
|
||||||
|
memberCache[member.NameOrPath] = member;
|
||||||
|
}
|
||||||
|
|
||||||
var columns = new List<string>() { "Timestamps" };
|
var columns = new List<string>() { "Timestamps" };
|
||||||
var dataTypes = new List<TSDataType>() { TSDataType.TIMESTAMP };
|
var dataTypes = new List<TSDataType>() { TSDataType.TIMESTAMP };
|
||||||
columns.AddRange(metadata.ColumnNames);
|
columns.AddRange(metadata.ColumnNames);
|
||||||
dataTypes.AddRange(metadata.DataTypes);
|
dataTypes.AddRange(metadata.DataTypes);
|
||||||
//metadata.ColumnNames.Insert(0, "Timestamps");
|
|
||||||
//metadata.DataTypes.Insert(0, TSDataType.TIMESTAMP);
|
|
||||||
|
|
||||||
var accessor = SourceEntityAccessorFactory.GetAccessor<T>();
|
|
||||||
|
|
||||||
while (dataSet.HasNext() && results.Count < pageSize)
|
while (dataSet.HasNext() && results.Count < pageSize)
|
||||||
{
|
{
|
||||||
@ -598,23 +563,20 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
var value = record.Values[indexOf];
|
var value = record.Values[indexOf];
|
||||||
TSDataType tSDataType = dataTypes[indexOf];
|
TSDataType tSDataType = dataTypes[indexOf];
|
||||||
|
|
||||||
var prop = properties.FirstOrDefault(p =>
|
if (!memberCache.TryGetValue(measurement, out var member) && !(value is System.DBNull))
|
||||||
p.Name.Equals(measurement, StringComparison.OrdinalIgnoreCase));
|
|
||||||
if (prop != null && !(value is System.DBNull))
|
|
||||||
{
|
{
|
||||||
|
throw new Exception($"{nameof(ParseResults)} 解析查询结果 {accessor.EntityName} 属性赋值出现异常,没有找到{measurement}对应的 member信息");
|
||||||
|
}
|
||||||
|
|
||||||
dynamic tempValue = GetTSDataValue(tSDataType, value);
|
dynamic tempValue = GetTSDataValue(tSDataType, value);
|
||||||
|
|
||||||
if (measurement.ToLower().EndsWith("time"))
|
if (measurement.ToLower().EndsWith("time"))
|
||||||
{
|
{
|
||||||
//typeof(T).GetProperty(measurement)?.SetValue(entity, TimestampHelper.ConvertToDateTime(tempValue, TimestampUnit.Nanoseconds));
|
member.Setter(entity, TimestampHelper.ConvertToDateTime(tempValue, TimestampUnit.Nanoseconds));
|
||||||
|
|
||||||
accessor.SetPropertyValue(entity, measurement, TimestampHelper.ConvertToDateTime(tempValue, TimestampUnit.Nanoseconds));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
accessor.SetPropertyValue(entity, measurement, tempValue);
|
member.Setter(entity, tempValue);
|
||||||
//typeof(T).GetProperty(measurement)?.SetValue(entity, tempValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -634,83 +596,58 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
private List<ColumnInfo> CollectColumnMetadata<T>(ISourceEntityAccessor<T> accessor)
|
private List<ColumnInfo> CollectColumnMetadata<T>(ISourceEntityAccessor<T> accessor)
|
||||||
{
|
{
|
||||||
var columns = new List<ColumnInfo>();
|
var columns = new List<ColumnInfo>();
|
||||||
|
var memberCache = new Dictionary<string, EntityMemberInfo>(); // 缓存优化查询
|
||||||
|
|
||||||
|
// 预构建成员缓存(Key: NameOrPath)
|
||||||
|
foreach (var member in accessor.MemberList)
|
||||||
|
{
|
||||||
|
memberCache[member.NameOrPath] = member;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var member in accessor.MemberList)
|
foreach (var member in accessor.MemberList)
|
||||||
{
|
{
|
||||||
//元组的子项字段详情不处理。
|
// 过滤元组子项
|
||||||
if (member.NameOrPath.Contains(".Item"))
|
if (member.NameOrPath.Contains(".Item")) continue;
|
||||||
|
|
||||||
|
// 类型名称处理
|
||||||
|
Type declaredType = member.DeclaredType;
|
||||||
|
var underlyingType = Nullable.GetUnderlyingType(declaredType);
|
||||||
|
string declaredTypeName = underlyingType?.Name ?? member.DeclaredTypeName;
|
||||||
|
|
||||||
|
// 特性查询优化
|
||||||
|
var attributes = member.CustomAttributes ?? Enumerable.Empty<Attribute>();
|
||||||
|
var tagAttr = attributes.OfType<TAGColumnAttribute>().FirstOrDefault();
|
||||||
|
var attrColumn = attributes.OfType<ATTRIBUTEColumnAttribute>().FirstOrDefault();
|
||||||
|
var fieldColumn = attributes.OfType<FIELDColumnAttribute>().FirstOrDefault();
|
||||||
|
var singleMeasuringAttr = attributes.OfType<SingleMeasuringAttribute>().FirstOrDefault();
|
||||||
|
|
||||||
|
// 构建ColumnInfo
|
||||||
|
ColumnInfo? column = null;
|
||||||
|
if (tagAttr != null)
|
||||||
{
|
{
|
||||||
continue;
|
column = new ColumnInfo(member.NameOrPath, ColumnCategory.TAG, GetDataTypeFromTypeName(declaredTypeName), false);
|
||||||
|
}
|
||||||
|
else if (attrColumn != null)
|
||||||
|
{
|
||||||
|
column = new ColumnInfo(member.NameOrPath, ColumnCategory.ATTRIBUTE, GetDataTypeFromTypeName(declaredTypeName), false);
|
||||||
|
}
|
||||||
|
else if (fieldColumn != null)
|
||||||
|
{
|
||||||
|
column = new ColumnInfo(member.NameOrPath, ColumnCategory.FIELD, GetDataTypeFromTypeName(declaredTypeName), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
string declaredTypeName = string.Empty;
|
// 单测模式处理
|
||||||
|
if (singleMeasuringAttr != null && column == null)
|
||||||
Type declaredType = member.DeclaredType;//属性的类型,如string,int等
|
|
||||||
|
|
||||||
// 处理可空类型
|
|
||||||
if (declaredType.IsGenericType && declaredType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
|
||||||
{
|
{
|
||||||
Type underlyingType = Nullable.GetUnderlyingType(declaredType);
|
var tupleItemKey = $"{member.NameOrPath}.Item2";
|
||||||
declaredTypeName = underlyingType.Name;
|
if (!memberCache.TryGetValue(tupleItemKey, out var tupleMember))
|
||||||
|
{
|
||||||
|
throw new Exception($"{nameof(CollectColumnMetadata)} {accessor.EntityName} {member.NameOrPath} 单侧点属性解析异常");
|
||||||
}
|
}
|
||||||
else
|
column = new ColumnInfo(member.NameOrPath, ColumnCategory.FIELD, GetDataTypeFromTypeName(tupleMember.DeclaredTypeName), true);
|
||||||
{
|
|
||||||
declaredTypeName = member.NameOrPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (column.HasValue) columns.Add(column.Value);
|
||||||
var tagAttr = member.CustomAttributes?.OfType<TAGColumnAttribute>().FirstOrDefault();
|
|
||||||
var attrColumn = member.CustomAttributes?.OfType<ATTRIBUTEColumnAttribute>().FirstOrDefault();
|
|
||||||
var fieldColumn = member.CustomAttributes?.OfType<FIELDColumnAttribute>().FirstOrDefault();
|
|
||||||
|
|
||||||
//判断是否是单测数据
|
|
||||||
var singleMeasuringAttribute = member.CustomAttributes?.OfType<SingleMeasuringAttribute>().FirstOrDefault();
|
|
||||||
|
|
||||||
//先获取Tag标签和属性标签
|
|
||||||
ColumnInfo? column = tagAttr != null ? new ColumnInfo(
|
|
||||||
name: member.NameOrPath,
|
|
||||||
category: ColumnCategory.TAG,
|
|
||||||
dataType: GetDataTypeFromTypeName(declaredTypeName),
|
|
||||||
false
|
|
||||||
) : attrColumn != null ? new ColumnInfo(
|
|
||||||
member.NameOrPath,
|
|
||||||
ColumnCategory.ATTRIBUTE,
|
|
||||||
GetDataTypeFromTypeName(declaredTypeName),
|
|
||||||
false
|
|
||||||
) : fieldColumn != null ? new ColumnInfo(
|
|
||||||
member.NameOrPath,
|
|
||||||
ColumnCategory.FIELD,
|
|
||||||
GetDataTypeFromTypeName(declaredTypeName),
|
|
||||||
false)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
//检查是不是单侧点模式
|
|
||||||
if (singleMeasuringAttribute != null && column == null)
|
|
||||||
{
|
|
||||||
//warning: 单侧点模式注意事项
|
|
||||||
//Entity实体 字段类型是 Tuple<string,T>,Item1=>测点名称,Item2=>测点值,泛型
|
|
||||||
//只有一个Filed字段。
|
|
||||||
//MeasuringName 默认为 SingleMeasuringAttribute.FieldName,以便于在获取对应的Value的时候重置为 Item1 的值。
|
|
||||||
|
|
||||||
Type tupleType = accessor.MemberList.Where(d => d.NameOrPath == $"{member.NameOrPath}.Item2").FirstOrDefault()?.DeclaredType;
|
|
||||||
|
|
||||||
if (tupleType == null)
|
|
||||||
{
|
|
||||||
throw new Exception($"{nameof(CollectColumnMetadata)} {accessor.EntityName} {member.NameOrPath} 属性解析异常");
|
|
||||||
}
|
|
||||||
|
|
||||||
column = new ColumnInfo(
|
|
||||||
member.NameOrPath,
|
|
||||||
ColumnCategory.FIELD,
|
|
||||||
GetDataTypeFromTypeName(tupleType.Name),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (column.HasValue)
|
|
||||||
{
|
|
||||||
columns.Add(column.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return columns;
|
return columns;
|
||||||
}
|
}
|
||||||
@ -740,15 +677,6 @@ namespace JiShe.CollectBus.IoTDB.Provider
|
|||||||
ProcessCategory(groupedColumns, ColumnCategory.ATTRIBUTE, metadata);
|
ProcessCategory(groupedColumns, ColumnCategory.ATTRIBUTE, metadata);
|
||||||
ProcessCategory(groupedColumns, ColumnCategory.FIELD, metadata);
|
ProcessCategory(groupedColumns, ColumnCategory.FIELD, metadata);
|
||||||
|
|
||||||
var entityTypeAttribute = typeof(T).GetCustomAttribute<EntityTypeAttribute>();
|
|
||||||
|
|
||||||
if (entityTypeAttribute == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"{nameof(BuildDeviceMetadata)} 构建设备元数据时 {nameof(IoTEntity)} 的EntityType 没有指定,属于异常情况,-101");
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata.EntityType = entityTypeAttribute.EntityType;
|
|
||||||
|
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -93,8 +93,9 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData
|
|||||||
{
|
{
|
||||||
SystemName = _applicationOptions.SystemType,
|
SystemName = _applicationOptions.SystemType,
|
||||||
DeviceId = $"{data.DeviceId}",
|
DeviceId = $"{data.DeviceId}",
|
||||||
DeviceType = $"{data.DeviceType.ToString()}.{IOTDBDataType.Data}",
|
DeviceType = $"{data.DeviceType.ToString()}",
|
||||||
ProjectId = $"{data.ProjectId}",
|
ProjectId = $"{data.ProjectId}",
|
||||||
|
DataType = IOTDBDataTypeConst.Data,
|
||||||
Timestamps = data.TimeSpan!.Value.GetFormatTime(analysisBaseDto.DensityUnit, analysisBaseDto.TimeDensity).GetDateTimeOffset().ToUnixTimeNanoseconds(),
|
Timestamps = data.TimeSpan!.Value.GetFormatTime(analysisBaseDto.DensityUnit, analysisBaseDto.TimeDensity).GetDateTimeOffset().ToUnixTimeNanoseconds(),
|
||||||
SingleMeasuring = (data.FiledName ?? string.Empty, data.DataValue ?? default)
|
SingleMeasuring = (data.FiledName ?? string.Empty, data.DataValue ?? default)
|
||||||
};
|
};
|
||||||
@ -196,8 +197,9 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData
|
|||||||
{
|
{
|
||||||
SystemName = _applicationOptions.SystemType,
|
SystemName = _applicationOptions.SystemType,
|
||||||
DeviceId = $"{item.DeviceId}",
|
DeviceId = $"{item.DeviceId}",
|
||||||
DeviceType = $"{item.DeviceType}.{IOTDBDataType.Data}",
|
DeviceType = $"{item.DeviceType}",
|
||||||
ProjectId = $"{item.ProjectId}",
|
ProjectId = $"{item.ProjectId}",
|
||||||
|
DataType = IOTDBDataTypeConst.Data,
|
||||||
Timestamps = item.TimeSpan!.Value.GetFormatTime(analysisBaseDto.DensityUnit, analysisBaseDto.TimeDensity).GetDateTimeOffset().ToUnixTimeNanoseconds(), // TODO:这里暂时格式化15分钟数据,需要进行调整
|
Timestamps = item.TimeSpan!.Value.GetFormatTime(analysisBaseDto.DensityUnit, analysisBaseDto.TimeDensity).GetDateTimeOffset().ToUnixTimeNanoseconds(), // TODO:这里暂时格式化15分钟数据,需要进行调整
|
||||||
SingleMeasuring =(item.FiledName ?? string.Empty, item.DataValue ?? default)
|
SingleMeasuring =(item.FiledName ?? string.Empty, item.DataValue ?? default)
|
||||||
};
|
};
|
||||||
@ -280,8 +282,9 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData
|
|||||||
{
|
{
|
||||||
SystemName = _applicationOptions.SystemType,
|
SystemName = _applicationOptions.SystemType,
|
||||||
DeviceId = $"{data.DeviceId}",
|
DeviceId = $"{data.DeviceId}",
|
||||||
DeviceType = $"{data.DeviceType}.{IOTDBDataType.Status}",
|
DeviceType = $"{data.DeviceType}",
|
||||||
ProjectId = $"{data.ProjectId}",
|
ProjectId = $"{data.ProjectId}",
|
||||||
|
DataType = IOTDBDataTypeConst.Data,
|
||||||
Timestamps = timestamps,
|
Timestamps = timestamps,
|
||||||
SingleMeasuring = (data.FiledName!, data.DataValue!)
|
SingleMeasuring = (data.FiledName!, data.DataValue!)
|
||||||
};
|
};
|
||||||
@ -292,8 +295,9 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData
|
|||||||
{
|
{
|
||||||
SystemName = _applicationOptions.SystemType,
|
SystemName = _applicationOptions.SystemType,
|
||||||
DeviceId = $"{data.DeviceId}",
|
DeviceId = $"{data.DeviceId}",
|
||||||
DeviceType = $"{data.DeviceType}.{IOTDBDataType.Status}",
|
DeviceType = $"{data.DeviceType}",
|
||||||
ProjectId = $"{data.ProjectId}",
|
ProjectId = $"{data.ProjectId}",
|
||||||
|
DataType = IOTDBDataTypeConst.Data,
|
||||||
Timestamps = timestamps,
|
Timestamps = timestamps,
|
||||||
SingleMeasuring = (ConcentratorStatusFieldConst.FrameData, analysisBaseDto.HexMessage ?? string.Empty)
|
SingleMeasuring = (ConcentratorStatusFieldConst.FrameData, analysisBaseDto.HexMessage ?? string.Empty)
|
||||||
};
|
};
|
||||||
@ -306,9 +310,10 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData
|
|||||||
{
|
{
|
||||||
SystemName = _applicationOptions.SystemType,
|
SystemName = _applicationOptions.SystemType,
|
||||||
DeviceId = $"{data.DeviceId}",
|
DeviceId = $"{data.DeviceId}",
|
||||||
DeviceType = $"{data.DeviceType}.{IOTDBDataType.Status}",
|
DeviceType = $"{data.DeviceType}",
|
||||||
ProjectId = $"{data.ProjectId}",
|
ProjectId = $"{data.ProjectId}",
|
||||||
Timestamps = timestamps,
|
Timestamps = timestamps,
|
||||||
|
DataType = IOTDBDataTypeConst.Status,
|
||||||
SingleMeasuring = (ConcentratorStatusFieldConst.RecordingTime, (data.TimeSpan.HasValue ? data.TimeSpan.Value : DateTime.Now).GetDateTimeOffset().ToUnixTimeNanoseconds())
|
SingleMeasuring = (ConcentratorStatusFieldConst.RecordingTime, (data.TimeSpan.HasValue ? data.TimeSpan.Value : DateTime.Now).GetDateTimeOffset().ToUnixTimeNanoseconds())
|
||||||
};
|
};
|
||||||
_runtimeContext.UseTableSessionPool = false; // 使树模型池
|
_runtimeContext.UseTableSessionPool = false; // 使树模型池
|
||||||
@ -318,8 +323,9 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData
|
|||||||
{
|
{
|
||||||
SystemName = _applicationOptions.SystemType,
|
SystemName = _applicationOptions.SystemType,
|
||||||
DeviceId = $"{data.DeviceId}",
|
DeviceId = $"{data.DeviceId}",
|
||||||
DeviceType = $"{data.DeviceType}.{IOTDBDataType.Status}",
|
DeviceType = $"{data.DeviceType}",
|
||||||
ProjectId = $"{data.ProjectId}",
|
ProjectId = $"{data.ProjectId}",
|
||||||
|
DataType = IOTDBDataTypeConst.Status,
|
||||||
Timestamps = timestamps,
|
Timestamps = timestamps,
|
||||||
SingleMeasuring = (ConcentratorStatusFieldConst.Remark, data.FiledDesc ?? string.Empty)
|
SingleMeasuring = (ConcentratorStatusFieldConst.Remark, data.FiledDesc ?? string.Empty)
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
using JiShe.CollectBus.Analyzers.Shared;
|
using JiShe.CollectBus.Analyzers.Shared;
|
||||||
using JiShe.CollectBus.IoTDB.Attributes;
|
using JiShe.CollectBus.IoTDB.Attributes;
|
||||||
using JiShe.CollectBus.IoTDB.Enums;
|
|
||||||
using JiShe.CollectBus.IoTDB.Model;
|
using JiShe.CollectBus.IoTDB.Model;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.Ammeters
|
namespace JiShe.CollectBus.Ammeters
|
||||||
{
|
{
|
||||||
[EntityType(EntityTypeEnum.TableModel)]
|
[SourceAnalyzers(EntityTypeEnum.TableModel)]
|
||||||
[SourceAnalyzers]
|
|
||||||
public class ElectricityMeter : IoTEntity
|
public class ElectricityMeter : IoTEntity
|
||||||
{
|
{
|
||||||
[ATTRIBUTEColumn]
|
[ATTRIBUTEColumn]
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
using JiShe.CollectBus.Analyzers.Shared;
|
using JiShe.CollectBus.Analyzers.Shared;
|
||||||
using JiShe.CollectBus.IoTDB.Attributes;
|
using JiShe.CollectBus.IoTDB.Attributes;
|
||||||
using JiShe.CollectBus.IoTDB.Enums;
|
|
||||||
using JiShe.CollectBus.IoTDB.Model;
|
using JiShe.CollectBus.IoTDB.Model;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.Ammeters
|
namespace JiShe.CollectBus.Ammeters
|
||||||
{
|
{
|
||||||
[EntityType(EntityTypeEnum.TreeModel)]
|
[SourceAnalyzers(EntityTypeEnum.TreeModel)]
|
||||||
[SourceAnalyzers]
|
|
||||||
public class ElectricityMeterTreeModel : IoTEntity
|
public class ElectricityMeterTreeModel : IoTEntity
|
||||||
{
|
{
|
||||||
[ATTRIBUTEColumn]
|
[ATTRIBUTEColumn]
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using JiShe.CollectBus.Analyzers.Shared;
|
using JiShe.CollectBus.Analyzers.Shared;
|
||||||
using JiShe.CollectBus.IoTDB.Attributes;
|
using JiShe.CollectBus.IoTDB.Attributes;
|
||||||
using JiShe.CollectBus.IoTDB.Enums;
|
|
||||||
using JiShe.CollectBus.IoTDB.Model;
|
using JiShe.CollectBus.IoTDB.Model;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
@ -9,8 +8,7 @@ namespace JiShe.CollectBus.IotSystems.MeterReadingRecords
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 抄读任务数据
|
/// 抄读任务数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EntityType(EntityTypeEnum.TableModel)]
|
[SourceAnalyzers(EntityTypeEnum.TableModel)]
|
||||||
[SourceAnalyzers]
|
|
||||||
public class MeterReadingTelemetryPacketInfo : IoTEntity
|
public class MeterReadingTelemetryPacketInfo : IoTEntity
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -19,6 +19,11 @@ namespace JiShe.CollectBus.Analyzers.Shared
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Type DeclaredType { get; set; }
|
public Type DeclaredType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 声明的类型的名称
|
||||||
|
/// </summary>
|
||||||
|
public string DeclaredTypeName { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取值
|
/// 获取值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -38,11 +43,13 @@ namespace JiShe.CollectBus.Analyzers.Shared
|
|||||||
public EntityMemberInfo(
|
public EntityMemberInfo(
|
||||||
string nameOrPath,
|
string nameOrPath,
|
||||||
Type declaredType,
|
Type declaredType,
|
||||||
|
string declaredTypeName,
|
||||||
Func<object, object> getter,
|
Func<object, object> getter,
|
||||||
Action<object, object> setter)
|
Action<object, object> setter)
|
||||||
{
|
{
|
||||||
NameOrPath = nameOrPath;
|
NameOrPath = nameOrPath;
|
||||||
this.DeclaredType = declaredType;
|
this.DeclaredType = declaredType;
|
||||||
|
DeclaredTypeName = declaredTypeName;
|
||||||
Getter = getter;
|
Getter = getter;
|
||||||
Setter = setter;
|
Setter = setter;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,24 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace JiShe.CollectBus.IoTDB.Enums
|
namespace JiShe.CollectBus.Analyzers.Shared
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IoTDB实体类型枚举
|
/// 实体类型枚举
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum EntityTypeEnum
|
public enum EntityTypeEnum
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 树模型
|
/// IoTDB树模型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
TreeModel = 1,
|
TreeModel = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 表模型
|
/// IoTDB表模型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
TableModel = 2,
|
TableModel = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 其他情况
|
||||||
|
/// </summary>
|
||||||
|
Other = 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12,6 +12,11 @@ namespace JiShe.CollectBus.Analyzers.Shared
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
string EntityName { get; }
|
string EntityName { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实体类型
|
||||||
|
/// </summary>
|
||||||
|
EntityTypeEnum? EntityType { get;}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取属性值
|
/// 获取属性值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -8,5 +8,12 @@ namespace JiShe.CollectBus.Analyzers.Shared
|
|||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public class SourceAnalyzersAttribute : Attribute
|
public class SourceAnalyzersAttribute : Attribute
|
||||||
{
|
{
|
||||||
|
public EntityTypeEnum EntityType { get; }
|
||||||
|
|
||||||
|
|
||||||
|
public SourceAnalyzersAttribute(EntityTypeEnum entityType)
|
||||||
|
{
|
||||||
|
EntityType = entityType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
shared/JiShe.CollectBus.Common/Consts/IOTDBDataTypeConst.cs
Normal file
29
shared/JiShe.CollectBus.Common/Consts/IOTDBDataTypeConst.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace JiShe.CollectBus.Common.Consts
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IOTDB数据树类型
|
||||||
|
/// </summary>
|
||||||
|
public class IOTDBDataTypeConst
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 数据
|
||||||
|
/// </summary>
|
||||||
|
public const string Data = "Data";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 事件
|
||||||
|
/// </summary>
|
||||||
|
public const string Event = "Event";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 状态
|
||||||
|
/// </summary>
|
||||||
|
public const string Status = "Status";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -152,26 +152,6 @@ namespace JiShe.CollectBus.Common.Consts
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// IOTDB数据树类型
|
|
||||||
/// </summary>
|
|
||||||
public class IOTDBDataType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 数据
|
|
||||||
/// </summary>
|
|
||||||
public const string Data = "Data";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 事件
|
|
||||||
/// </summary>
|
|
||||||
public const string Event = "Event";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 状态
|
|
||||||
/// </summary>
|
|
||||||
public const string Status = "Status";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 集中器状态字段
|
/// 集中器状态字段
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user