diff --git a/modules/JiShe.CollectBus.IoTDB/JiShe.CollectBus.IoTDB.csproj b/modules/JiShe.CollectBus.IoTDB/JiShe.CollectBus.IoTDB.csproj index 0e8250e..c24a807 100644 --- a/modules/JiShe.CollectBus.IoTDB/JiShe.CollectBus.IoTDB.csproj +++ b/modules/JiShe.CollectBus.IoTDB/JiShe.CollectBus.IoTDB.csproj @@ -11,5 +11,7 @@ + + diff --git a/modules/JiShe.CollectBus.IoTDB/Model/IoTEntity.cs b/modules/JiShe.CollectBus.IoTDB/Model/IoTEntity.cs index a079bd4..48bc248 100644 --- a/modules/JiShe.CollectBus.IoTDB/Model/IoTEntity.cs +++ b/modules/JiShe.CollectBus.IoTDB/Model/IoTEntity.cs @@ -1,9 +1,10 @@ -using JiShe.CollectBus.IoTDB.Attribute; +using JiShe.CollectBus.Common.Attributes; +using JiShe.CollectBus.IoTDB.Attribute; namespace JiShe.CollectBus.IoTDB.Model { /// - /// IoT实体基类,此类适用于多个数据测点记录场景,单个测点请使用子类 SingleMeasuring + /// IoT实体基类,此类适用于多个数据测点记录场景,单个测点请使用子类 SingleMeasuring,新增字段只能现有字段末尾添加,否则会导致数据写入失败。 /// public abstract class IoTEntity { diff --git a/modules/JiShe.CollectBus.IoTDB/Options/IoTDBOptions.cs b/modules/JiShe.CollectBus.IoTDB/Options/IoTDBOptions.cs index 251e48b..68b2770 100644 --- a/modules/JiShe.CollectBus.IoTDB/Options/IoTDBOptions.cs +++ b/modules/JiShe.CollectBus.IoTDB/Options/IoTDBOptions.cs @@ -26,7 +26,7 @@ /// /// 连接池大小 /// - public int PoolSize { get; set; } = 2; + public int PoolSize { get; set; } = 8; /// /// 查询时,每次查询的数据量,默认1024 diff --git a/modules/JiShe.CollectBus.IoTDB/Provider/SessionPoolAdapter.cs b/modules/JiShe.CollectBus.IoTDB/Provider/SessionPoolAdapter.cs index ee71cf1..26ea4c7 100644 --- a/modules/JiShe.CollectBus.IoTDB/Provider/SessionPoolAdapter.cs +++ b/modules/JiShe.CollectBus.IoTDB/Provider/SessionPoolAdapter.cs @@ -70,7 +70,7 @@ namespace JiShe.CollectBus.IoTDB.Provider var result = await _sessionPool.InsertAlignedTabletAsync(tablet); if (result != 0) { - throw new Exception($"{nameof(SessionPoolAdapter)} Tree模型数据入库没有成功,返回结果为:{result}"); + throw new Exception($"{nameof(SessionPoolAdapter)} Tree模型数据入库没有成功,返回结果为:{result},请检查IoTEntity继承子类属性索引是否有变动。"); } //await CloseAsync(); return result; diff --git a/modules/JiShe.CollectBus.IoTDB/Provider/TableSessionPoolAdapter.cs b/modules/JiShe.CollectBus.IoTDB/Provider/TableSessionPoolAdapter.cs index dc4f0ee..8edb112 100644 --- a/modules/JiShe.CollectBus.IoTDB/Provider/TableSessionPoolAdapter.cs +++ b/modules/JiShe.CollectBus.IoTDB/Provider/TableSessionPoolAdapter.cs @@ -68,7 +68,7 @@ namespace JiShe.CollectBus.IoTDB.Provider var result = await _sessionPool.InsertAsync(tablet); if (result != 0) { - throw new Exception($"{nameof(TableSessionPoolAdapter)} table模型数据入库没有成功,返回结果为:{result}"); + throw new Exception($"{nameof(TableSessionPoolAdapter)} table模型数据入库没有成功,返回结果为:{result},请检查IoTEntity继承子类属性索引是否有变动。"); } //await CloseAsync(); diff --git a/services/JiShe.CollectBus.Application/CollectBusApplicationModule.cs b/services/JiShe.CollectBus.Application/CollectBusApplicationModule.cs index ce2e5aa..8b3da38 100644 --- a/services/JiShe.CollectBus.Application/CollectBusApplicationModule.cs +++ b/services/JiShe.CollectBus.Application/CollectBusApplicationModule.cs @@ -66,12 +66,17 @@ public class CollectBusApplicationModule : AbpModule .ToList(); foreach (var type in types) await context.AddBackgroundWorkerAsync(type); - Task.Run(() => - { - //默认初始化表计信息 - var dbContext = context.ServiceProvider.GetRequiredService(); - dbContext.InitAmmeterCacheData(); - //await dbContext.InitWatermeterCacheData(); - }).ConfigureAwait(false); + //Task.Run(() => + //{ + // //默认初始化表计信息 + // var dbContext = context.ServiceProvider.GetRequiredService(); + // dbContext.InitAmmeterCacheData(); + // //await dbContext.InitWatermeterCacheData(); + //}).ConfigureAwait(false); + + + //默认初始化表计信息 + var dbContext = context.ServiceProvider.GetRequiredService(); + _= dbContext.InitAmmeterCacheData(); } } \ No newline at end of file diff --git a/services/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj b/services/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj index b43d994..b9d899c 100644 --- a/services/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj +++ b/services/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj @@ -23,15 +23,14 @@ - + - - + diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs index 5a7ef51..0b5f28a 100644 --- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs +++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs @@ -286,52 +286,51 @@ namespace JiShe.CollectBus.ScheduledMeterReading public virtual async Task InitAmmeterCacheData(string gatherCode = "") { //此处代码不要删除 - //#if DEBUG - // var timeDensity = "15"; - // var redisCacheMeterInfoHashKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoHashKey, SystemType, "JiSheCollectBus2", MeterTypeEnum.Ammeter, timeDensity)}"; - // var redisCacheMeterInfoSetIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoSetIndexKey, SystemType, "JiSheCollectBus2", MeterTypeEnum.Ammeter, timeDensity)}"; - // var redisCacheMeterInfoZSetScoresIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoZSetScoresIndexKey, SystemType, "JiSheCollectBus2", MeterTypeEnum.Ammeter, timeDensity)}"; +#if DEBUG + var timeDensity = "15"; + var redisCacheMeterInfoHashKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoHashKey, SystemType, "JiSheCollectBus2", MeterTypeEnum.Ammeter, timeDensity)}"; + var redisCacheMeterInfoSetIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoSetIndexKey, SystemType, "JiSheCollectBus2", MeterTypeEnum.Ammeter, timeDensity)}"; + var redisCacheMeterInfoZSetScoresIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoZSetScoresIndexKey, SystemType, "JiSheCollectBus2", MeterTypeEnum.Ammeter, timeDensity)}"; - // List meterInfos = new List(); - // List focusAddressDataLista = new List(); - // var timer1 = Stopwatch.StartNew(); + List meterInfos = new List(); + 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.FocusAddress)); - // 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.FocusAddress)); + 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); - // return; - //#else - // var meterInfos = await GetAmmeterInfoList(gatherCode); - //#endif - var meterInfos = await GetAmmeterInfoList(gatherCode); + timer1.Stop(); + _logger.LogError($"读取数据总共花费时间{timer1.ElapsedMilliseconds}毫秒"); + DeviceGroupBalanceControl.InitializeCache(focusAddressDataLista, _kafkaOptions.NumPartitions); + return; +#else + var meterInfos = await GetAmmeterInfoList(gatherCode); +#endif if (meterInfos == null || meterInfos.Count <= 0) { throw new NullReferenceException($"{nameof(InitAmmeterCacheData)} 初始化电表缓存数据时,电表数据为空"); diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs index b0b6bba..883537c 100644 --- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs +++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs @@ -35,6 +35,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading //[Route($"/energy/app/scheduled")] public class EnergySystemScheduledMeterReadingService : BasicScheduledMeterReadingService { + string systemType = string.Empty; string serverTagName = string.Empty; private readonly ILogger _logger; private readonly IIoTDbProvider _dbProvider; @@ -59,12 +60,13 @@ namespace JiShe.CollectBus.ScheduledMeterReading applicationOptions) { serverTagName = applicationOptions.Value.ServerTagName; + systemType = applicationOptions.Value.SystemType; _dbProvider = dbProvider; _logger = logger; _protocolService = protocolService; } - public sealed override string SystemType => SystemTypeConst.Energy; + public sealed override string SystemType => systemType; public sealed override string ServerTagName => serverTagName; diff --git a/services/JiShe.CollectBus.Domain/IotSystems/MeterReadingRecords/MeterReadingTelemetryPacketInfo.cs b/services/JiShe.CollectBus.Domain/IotSystems/MeterReadingRecords/MeterReadingTelemetryPacketInfo.cs index 552084f..4d406b8 100644 --- a/services/JiShe.CollectBus.Domain/IotSystems/MeterReadingRecords/MeterReadingTelemetryPacketInfo.cs +++ b/services/JiShe.CollectBus.Domain/IotSystems/MeterReadingRecords/MeterReadingTelemetryPacketInfo.cs @@ -1,4 +1,5 @@ using JiShe.CollectBus.Common; +using JiShe.CollectBus.Common.Attributes; using JiShe.CollectBus.IoTDB.Attribute; using JiShe.CollectBus.IoTDB.Enums; using JiShe.CollectBus.IoTDB.Model; @@ -18,7 +19,7 @@ namespace JiShe.CollectBus.IotSystems.MeterReadingRecords /// [FIELDColumn] public string ScoreValue { get; set; } - + /// /// 是否手动操作 /// @@ -89,6 +90,7 @@ namespace JiShe.CollectBus.IotSystems.MeterReadingRecords /// /// 抄读计量点 /// + [FIELDColumn] public int Pn { get; set; } /// @@ -107,6 +109,7 @@ namespace JiShe.CollectBus.IotSystems.MeterReadingRecords /// /// 帧序列域 SEQ /// + [FIELDColumn] public int Seq { get; set; } /// @@ -125,7 +128,7 @@ namespace JiShe.CollectBus.IotSystems.MeterReadingRecords /// 发送次数 /// [FIELDColumn] - public int SendNum { get; set; } + public int? SendNum { get; set; } /// /// 下次发送时间 diff --git a/services/JiShe.CollectBus.Domain/JiShe.CollectBus.Domain.csproj b/services/JiShe.CollectBus.Domain/JiShe.CollectBus.Domain.csproj index 44b8a3e..d7804a6 100644 --- a/services/JiShe.CollectBus.Domain/JiShe.CollectBus.Domain.csproj +++ b/services/JiShe.CollectBus.Domain/JiShe.CollectBus.Domain.csproj @@ -23,8 +23,10 @@ - + + + diff --git a/shared/JiShe.CollectBus.IncrementalGenerator/ComplexTypeSourceGenerator.cs b/shared/JiShe.CollectBus.IncrementalGenerator/ComplexTypeSourceGenerator.cs index 1530a2c..6b0982e 100644 --- a/shared/JiShe.CollectBus.IncrementalGenerator/ComplexTypeSourceGenerator.cs +++ b/shared/JiShe.CollectBus.IncrementalGenerator/ComplexTypeSourceGenerator.cs @@ -20,12 +20,13 @@ namespace JiShe.CollectBus.IncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { - Debugger.Launch(); + //Debugger.Launch(); context.RegisterPostInitializationOutput(ctx => { ctx.AddSource("DebugInit.g.cs", "// Generator initialized"); }); + // 步骤1:筛选带有 [GenerateAccessors] 的类 var classDeclarations = context.SyntaxProvider @@ -42,29 +43,7 @@ namespace JiShe.CollectBus.IncrementalGenerator } private static bool IsClassWithAttribute(SyntaxNode node) => node is ClassDeclarationSyntax cds && cds.AttributeLists.Count > 0; - - //private static ClassDeclarationSyntax? GetClassDeclaration(GeneratorSyntaxContext context) - //{ - // var classDecl = (ClassDeclarationSyntax)context.Node; - // foreach (var attributeList in classDecl.AttributeLists) - // { - // foreach (var attribute in attributeList.Attributes) - // { - // var symbol = context.SemanticModel.GetSymbolInfo(attribute).Symbol; - // if (symbol is IMethodSymbol ctor) - // { - // string sdd = ctor.ContainingType.Name; - // var attributeType = context.SemanticModel.Compilation.GetTypeByMetadataName(AttributeFullName); - // if (ctor.ContainingType?.OriginalDefinition?.Equals(attributeType, SymbolEqualityComparer.Default) == true) - // { - // return classDecl; - // } - // } - - // } - // } - // return null; - //} + private static ClassDeclarationSyntax? GetClassDeclaration(GeneratorSyntaxContext context) { @@ -75,7 +54,7 @@ namespace JiShe.CollectBus.IncrementalGenerator { var symbol = context.SemanticModel.GetSymbolInfo(attribute).Symbol; if (symbol is IMethodSymbol ctor && - ctor.ContainingType?.OriginalDefinition?.Equals(attributeType, SymbolEqualityComparer.Default) == true) + SymbolEqualityComparer.Default.Equals(ctor.ContainingType, attributeType)) { return classDecl; } @@ -89,14 +68,28 @@ namespace JiShe.CollectBus.IncrementalGenerator SourceProductionContext context) { var processedTypes = new HashSet(SymbolEqualityComparer.Default); - + + if (!classes.Any()) + { + context.ReportDiagnostic(Diagnostic.Create( + new DiagnosticDescriptor("GEN002", "No Targets", + "No classes with [GenerateAccessors] found", "Debug", DiagnosticSeverity.Warning, true), + Location.None)); + } foreach (var classDecl in classes.Distinct()) { var model = compilation.GetSemanticModel(classDecl.SyntaxTree); var classSymbol = model.GetDeclaredSymbol(classDecl) as INamedTypeSymbol; - if (classSymbol == null || !processedTypes.Add(classSymbol)) continue; + if (classSymbol == null || !processedTypes.Add(classSymbol)) + { + context.ReportDiagnostic(Diagnostic.Create( + new DiagnosticDescriptor("GEN003", "Invalid Symbol", + $"Class symbol is null for {classDecl.Identifier.Text}", "Error", DiagnosticSeverity.Error, true), + Location.None)); + continue; + } context.ReportDiagnostic(Diagnostic.Create( new DiagnosticDescriptor( @@ -114,6 +107,9 @@ namespace JiShe.CollectBus.IncrementalGenerator Location.None)); var code = BuildAccessorsForType(classSymbol, compilation, processedTypes); + + System.Diagnostics.Debug.WriteLine($"Generated code for {classSymbol.Name}:\n{code}"); // 调试输出 + context.AddSource($"{classSymbol.Name}Extension.g.cs", SourceText.From(code, Encoding.UTF8)); } } @@ -124,6 +120,8 @@ namespace JiShe.CollectBus.IncrementalGenerator HashSet processedTypes) { var code = new StringBuilder(); + code.AppendLine("#pragma warning disable CS0419 // 禁用警告"); + code.AppendLine("// Generated code for " + classSymbol.Name); code.AppendLine("// "); code.AppendLine("#nullable enable"); code.AppendLine($"namespace {classSymbol.ContainingNamespace.ToDisplayString()};"); @@ -143,8 +141,14 @@ namespace JiShe.CollectBus.IncrementalGenerator return code.ToString(); } - private static string GetGenericParams(INamedTypeSymbol symbol) - => symbol.IsGenericType ? $"<{string.Join(", ", symbol.TypeParameters.Select(t => t.Name))}>" : ""; + //private static string GetGenericParams(INamedTypeSymbol symbol) + // => symbol.IsGenericType ? $"<{string.Join(", ", symbol.TypeParameters.Select(t => t.Name))}>" : ""; + public static string GetGenericParams(INamedTypeSymbol symbol) + { + if (!symbol.IsGenericType) return ""; + var parameters = symbol.TypeParameters.Select(t => t.Name); + return $"<{string.Join(", ", parameters)}>"; + } private static void GeneratePropertyAccessors( IPropertySymbol prop, diff --git a/shared/JiShe.CollectBus.IncrementalGenerator/JiShe.CollectBus.IncrementalGenerator.csproj b/shared/JiShe.CollectBus.IncrementalGenerator/JiShe.CollectBus.IncrementalGenerator.csproj index c36ce2b..533676e 100644 --- a/shared/JiShe.CollectBus.IncrementalGenerator/JiShe.CollectBus.IncrementalGenerator.csproj +++ b/shared/JiShe.CollectBus.IncrementalGenerator/JiShe.CollectBus.IncrementalGenerator.csproj @@ -1,14 +1,27 @@  - enable - netstandard2.0 - - true + net8.0 + true + true + false + bin + false latest + true + true + + Generated + enable + + + + true + all + diff --git a/web/JiShe.CollectBus.Host/appsettings.json b/web/JiShe.CollectBus.Host/appsettings.json index e8b49d2..f0effb4 100644 --- a/web/JiShe.CollectBus.Host/appsettings.json +++ b/web/JiShe.CollectBus.Host/appsettings.json @@ -5,7 +5,7 @@ "Serilog.Sinks.File" ], "MinimumLevel": { - "Default": "Warning", + "Default": "Information", "Override": { "Microsoft": "Warning", "Volo.Abp": "Warning", @@ -87,7 +87,7 @@ "UserName": "root", "Password": "root", "ClusterList": [ "192.168.1.9:6667" ], - "PoolSize": 2, + "PoolSize": 32, "DataBaseName": "energy", "OpenDebugMode": true, "UseTableSessionPoolByDefault": false @@ -142,9 +142,9 @@ } }, "ServerApplicationOptions": { - "ServerTagName": "JiSheCollectBus100", - "SystemType": null, - "FirstCollectionTime": "2025-04-22 16:07:00", + "ServerTagName": "JiSheCollectBus4", + "SystemType": "Energy", + "FirstCollectionTime": "2025-04-28 15:07:00", "AutomaticVerificationTime": "16:07:00", "AutomaticTerminalVersionTime": "17:07:00", "AutomaticTelematicsModuleTime": "17:30:00",