diff --git a/modules/JiShe.CollectBus.Analyzers/ComplexTypeSourceAnalyzers.cs b/modules/JiShe.CollectBus.Analyzers/ComplexTypeSourceAnalyzers.cs index ea0ef13..3b82bf2 100644 --- a/modules/JiShe.CollectBus.Analyzers/ComplexTypeSourceAnalyzers.cs +++ b/modules/JiShe.CollectBus.Analyzers/ComplexTypeSourceAnalyzers.cs @@ -452,7 +452,7 @@ namespace JiShe.CollectBus.IncrementalGenerator Compilation compilation, INamedTypeSymbol classSymbol) { - code.AppendLine(" public List PropertyList {get;} = new List()"); + code.AppendLine(" public List PropertyNameList {get;} = new List()"); code.AppendLine(" {"); List tempPropList = new List(); foreach (var prop in propList) @@ -477,39 +477,53 @@ namespace JiShe.CollectBus.IncrementalGenerator /// - /// 生成当前类属性信息集合 + /// 生成当前类属性信息集合(支持嵌套元组) /// - /// 属性集合 - /// - /// - /// private static void GeneratePropertyInfoListForSourceEntity( IEnumerable propList, StringBuilder code, Compilation compilation, INamedTypeSymbol classSymbol) { - code.AppendLine(" public List PropertyList {get;} = new List()"); + code.AppendLine(" public List PropertyInfoList { get; } = new List"); code.AppendLine(" {"); - List tempPropList = new List(); + + var initializerLines = new List(); + foreach (var prop in propList) { + // 主属性 + AddPropertyInitializer(classSymbol, prop, initializerLines); + + // 处理元组嵌套属性 if (prop.Type is INamedTypeSymbol { IsTupleType: true } tupleType) { foreach (var element in tupleType.TupleElements) { - tempPropList.Add($"\"{prop.Name}.{element.Name}\""); + // 生成形如:typeof(ValueTuple).GetProperty("Item1") + var tupleTypeName = tupleType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + initializerLines.Add( + $"typeof({tupleTypeName}).GetProperty(\"{element.Name}\") ?? " + + $"throw new InvalidOperationException(\"Tuple element {element.Name} not found\")"); } } - else - { - tempPropList.Add($"\"{prop.Name}\""); - } } - code.Append(string.Join(",", tempPropList)); - + code.AppendLine(string.Join(",\n", initializerLines)); code.AppendLine(" };"); } + + private static void AddPropertyInitializer( + INamedTypeSymbol classSymbol, + IPropertySymbol prop, + List initializerLines) + { + var classType = classSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + initializerLines.Add( + $"typeof({classType}).GetProperty(\"{prop.Name}\", " + + "System.Reflection.BindingFlags.Public | " + + "System.Reflection.BindingFlags.Instance) ?? " + + $"throw new InvalidOperationException(\"Property {prop.Name} not found\")"); + } } } \ No newline at end of file diff --git a/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntityAccessor.cs b/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntityAccessor.cs deleted file mode 100644 index e0bedd4..0000000 --- a/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntityAccessor.cs +++ /dev/null @@ -1,77 +0,0 @@ -// -#nullable enable -using System; -using System.Collections.Generic; -using JiShe.CollectBus.Analyzers.Shared; -namespace JiShe.CollectBus.IoTDB.Model; - -public sealed class TableModelSingleMeasuringEntityAccessor3 : ISourceEntityAccessor> -{ - public static string GetSingleColumn_Item1(global::JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity obj) => obj.SingleColumn.Item1; - public static void SetSingleColumn_Item1(global::JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity obj, string value) => obj.SingleColumn = (value, obj.SingleColumn.Item2); - public static T GetSingleColumn_Item2(global::JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity obj) => obj.SingleColumn.Item2; - public static void SetSingleColumn_Item2(global::JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity obj, T value) => obj.SingleColumn = (obj.SingleColumn.Item1, value); - public static string GetSystemName(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.SystemName; - public static void SetSystemName(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, string value) => obj.SystemName = value; - public static string GetProjectId(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.ProjectId; - public static void SetProjectId(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, string value) => obj.ProjectId = value; - public static string GetDeviceType(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.DeviceType; - public static void SetDeviceType(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, string value) => obj.DeviceType = value; - public static string GetDeviceId(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.DeviceId; - public static void SetDeviceId(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, string value) => obj.DeviceId = value; - public static long GetTimestamps(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.Timestamps; - public static void SetTimestamps(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, long value) => obj.Timestamps = value; - public List PropertyNameList { get; } = new List() - { -"SingleColumn.Item1","SingleColumn.Item2","SystemName","ProjectId","DeviceType","DeviceId","Timestamps" }; - public object GetPropertyValue(JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity targetEntity, string propertyName) - { - return propertyName switch - { - "SingleColumn.Item1" => GetSingleColumn_Item1(targetEntity), - "SingleColumn.Item2" => GetSingleColumn_Item2(targetEntity), - "SystemName" => GetSystemName(targetEntity), - "ProjectId" => GetProjectId(targetEntity), - "DeviceType" => GetDeviceType(targetEntity), - "DeviceId" => GetDeviceId(targetEntity), - "Timestamps" => GetTimestamps(targetEntity), - _ => throw new ArgumentException($"Unknown property: {propertyName}") - }; - } - public void SetPropertyValue(JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity targetEntity, string propertyName, object value) - { - switch (propertyName) - { - case "SingleColumn.Item1": - SetSingleColumn_Item1( - targetEntity, (string)value); - break; - case "SingleColumn.Item2": - SetSingleColumn_Item2( - targetEntity, (T)value); - break; - case "SystemName": - SetSystemName( - targetEntity, (string)value); - break; - case "ProjectId": - SetProjectId( - targetEntity, (string)value); - break; - case "DeviceType": - SetDeviceType( - targetEntity, (string)value); - break; - case "DeviceId": - SetDeviceId( - targetEntity, (string)value); - break; - case "Timestamps": - SetTimestamps( - targetEntity, (long)value); - break; - default: - throw new ArgumentException($"Unknown property: {propertyName}"); - } - } -} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs index a469147..73ecd15 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs @@ -715,10 +715,10 @@ namespace JiShe.CollectBus.Protocol.T37612012 /// public virtual List Generate_DataUnit(DataTimeMark timeMark) { - List values = new List - { - SplitDataTime(timeMark.DataTime)//数据时间 - }; + List values = new List(); + + values.AddRange(SplitDataTime(timeMark.DataTime));//数据时间 + if (timeMark.Density > 0) values.Add(timeMark.Density.HexToDecStr().PadLeft(2, '0'));//密度 if (timeMark.Point > 0) @@ -727,13 +727,13 @@ namespace JiShe.CollectBus.Protocol.T37612012 } - private string SplitDataTime(DateTime dataTime) + private List SplitDataTime(DateTime dataTime) { //2101060815 - List values = new List() { $"{dataTime}:YY", $"{dataTime}:MM", $"{dataTime}:dd", $"{dataTime}:HH", $"{dataTime}:mm", }; - + List values = new List() { $"{dataTime:yy}", $"{dataTime:MM}", $"{dataTime:dd}", $"{dataTime:HH}", $"{dataTime:mm}", }; values.Reverse(); - return string.Join("", values); + return values; + //return string.Join("", values); } #endregion diff --git a/services/JiShe.CollectBus.Application/DataChannels/DataChannelManageService.cs b/services/JiShe.CollectBus.Application/DataChannels/DataChannelManageService.cs index c129194..17ae182 100644 --- a/services/JiShe.CollectBus.Application/DataChannels/DataChannelManageService.cs +++ b/services/JiShe.CollectBus.Application/DataChannels/DataChannelManageService.cs @@ -125,13 +125,13 @@ namespace JiShe.CollectBus.DataChannels // 批量写入数据库 await _dbProvider.BatchInsertAsync(metadata, records); - // 限流推送Kafka - await DeviceGroupBalanceControl.ProcessWithThrottleAsync( - items: records, - deviceIdSelector: data => data.DeviceId, - processor: async (data, groupIndex) => - await KafkaProducerIssuedMessageAction(topicName, data, groupIndex) - ); + //// 限流推送Kafka + //await DeviceGroupBalanceControl.ProcessWithThrottleAsync( + // items: records, + // deviceIdSelector: data => data.DeviceId, + // processor: async (data, groupIndex) => + // await KafkaProducerIssuedMessageAction(topicName, data, groupIndex) + //); } catch (Exception ex) { diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs index e75ad84..47b8a99 100644 --- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs +++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs @@ -336,47 +336,47 @@ namespace JiShe.CollectBus.ScheduledMeterReading //此处代码不要删除 #if DEBUG - //var timeDensity = "15"; - //var serverTagName = "JiSheCollectBus2"; - //var redisCacheMeterInfoHashKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoHashKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}"; - //var redisCacheMeterInfoSetIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoSetIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}"; - //var redisCacheMeterInfoZSetScoresIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoZSetScoresIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}"; + var timeDensity = "15"; + var serverTagName = "JiSheCollectBus2"; + var redisCacheMeterInfoHashKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoHashKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}"; + var redisCacheMeterInfoSetIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoSetIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}"; + var redisCacheMeterInfoZSetScoresIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoZSetScoresIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}"; List meterInfos = new List(); - //List focusAddressDataLista = new List(); - //var timer1 = Stopwatch.StartNew(); + List focusAddressDataLista = new List(); + var timer1 = Stopwatch.StartNew(); - //var allIds = new HashSet(); - //decimal? score = null; - //string member = null; + var allIds = new HashSet(); + decimal? score = null; + string member = null; - //while (true) - //{ - // var page = await _redisDataCacheService.GetAllPagedData( - // redisCacheMeterInfoHashKeyTemp, - // redisCacheMeterInfoZSetScoresIndexKeyTemp, - // pageSize: 1000, - // lastScore: score, - // lastMember: member); + while (true) + { + var page = await _redisDataCacheService.GetAllPagedData( + redisCacheMeterInfoHashKeyTemp, + redisCacheMeterInfoZSetScoresIndexKeyTemp, + pageSize: 1000, + lastScore: score, + lastMember: member); - // meterInfos.AddRange(page.Items); - // focusAddressDataLista.AddRange(page.Items.Select(d => $"{d.MeterId}")); - // foreach (var item in page.Items) - // { - // if (!allIds.Add(item.MemberId)) - // { - // _logger.LogError($"{item.MemberId}Duplicate data found!"); - // } - // } - // if (!page.HasNext) break; - // score = page.NextScore; - // member = page.NextMember; - //} + meterInfos.AddRange(page.Items); + focusAddressDataLista.AddRange(page.Items.Select(d => $"{d.MeterId}")); + foreach (var item in page.Items) + { + if (!allIds.Add(item.MemberId)) + { + _logger.LogError($"{item.MemberId}Duplicate data found!"); + } + } + if (!page.HasNext) break; + score = page.NextScore; + member = page.NextMember; + } - //timer1.Stop(); - //_logger.LogError($"电表初始化读取数据总共花费时间{timer1.ElapsedMilliseconds}毫秒"); - //DeviceGroupBalanceControl.InitializeCache(focusAddressDataLista, _kafkaOptions.NumPartitions); + timer1.Stop(); + _logger.LogError($"电表初始化读取数据总共花费时间{timer1.ElapsedMilliseconds}毫秒"); + DeviceGroupBalanceControl.InitializeCache(focusAddressDataLista, _kafkaOptions.NumPartitions); return; #else var meterInfos = await GetAmmeterInfoList(gatherCode);