diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs index 1fc8d2a..5b82aa6 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs @@ -64,11 +64,13 @@ namespace JiShe.CollectBus.Protocol.T37612012 if (tB3761.DT?.Fn == (int)FN.登录) { // 登录回复 + //todo 更新Redis数据缓存 if (tB3761.SEQ.CON == (int)CON.需要对该帧进行确认) await LoginAsync(client, messageReceived, tB3761.A.Code, tB3761.A.A3?.D1_D7, tB3761.SEQ?.PSEQ); } else if (tB3761.DT?.Fn == (int)FN.心跳) { + //todo 更新Redis数据缓存,主要是TCP连接,当前服务器连接配置数量满了以后,如何解决监控策略,通知新采购服务器 // 心跳回复 //心跳帧有两种情况: //1. 集中器先有登录帧,再有心跳帧 diff --git a/protocols/JiShe.CollectBus.Protocol/JiShe.CollectBus.Protocol.csproj b/protocols/JiShe.CollectBus.Protocol/JiShe.CollectBus.Protocol.csproj index f75b5dd..6495b24 100644 --- a/protocols/JiShe.CollectBus.Protocol/JiShe.CollectBus.Protocol.csproj +++ b/protocols/JiShe.CollectBus.Protocol/JiShe.CollectBus.Protocol.csproj @@ -19,8 +19,7 @@ - - + diff --git a/protocols/JiShe.CollectBus.Protocol/Services/ProtocolService.cs b/protocols/JiShe.CollectBus.Protocol/Services/ProtocolService.cs index 0368151..e391fcd 100644 --- a/protocols/JiShe.CollectBus.Protocol/Services/ProtocolService.cs +++ b/protocols/JiShe.CollectBus.Protocol/Services/ProtocolService.cs @@ -36,7 +36,7 @@ namespace JiShe.CollectBus.Protocol.Services var keyValuePair = protocols.FirstOrDefault(a => ContainsExactPartRegex(deviceCode, a.Value.RegularExpression)); if (!keyValuePair.Key.IsNullOrWhiteSpace() || keyValuePair.Value != null) return keyValuePair.Value; if (isSpecial) throw new UserFriendlyException("The device protocol plugin does not exist!", ExceptionCode.NotFound); - var hasStandardProtocolPlugin = protocols.TryGetValue("StandardProtocolPlugin", out var protocolInfo); + var hasStandardProtocolPlugin = protocols.TryGetValue("T37612012ProtocolPlugin", out var protocolInfo); if (!hasStandardProtocolPlugin) throw new UserFriendlyException("Standard protocol plugin does not exist!", ExceptionCode.NotFound); return protocolInfo; } diff --git a/services/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj b/services/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj index 3ab9831..aefe5e4 100644 --- a/services/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj +++ b/services/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj @@ -19,8 +19,8 @@ - - + + diff --git a/services/JiShe.CollectBus.Application/Plugins/ServerMonitor.cs b/services/JiShe.CollectBus.Application/Plugins/ServerMonitor.cs index 2b3c15a..b90b372 100644 --- a/services/JiShe.CollectBus.Application/Plugins/ServerMonitor.cs +++ b/services/JiShe.CollectBus.Application/Plugins/ServerMonitor.cs @@ -5,7 +5,7 @@ using TouchSocket.Sockets; namespace JiShe.CollectBus.Plugins { - public partial class ServerMonitor(ILogger logger) : PluginBase, IServerStartedPlugin, IServerStopedPlugin + public partial class ServerMonitor(ILogger logger) : PluginBase, IServerStartedPlugin, IServerStoppedPlugin { public Task OnServerStarted(IServiceBase sender, ServiceStateEventArgs e) { @@ -31,7 +31,7 @@ namespace JiShe.CollectBus.Plugins return e.InvokeNext(); } - public Task OnServerStoped(IServiceBase sender,ServiceStateEventArgs e) + public Task OnServerStopped(IServiceBase sender,ServiceStateEventArgs e) { logger.LogInformation("服务已停止"); return e.InvokeNext(); diff --git a/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs b/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs index 6eadb0a..ab813fc 100644 --- a/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs +++ b/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs @@ -55,6 +55,7 @@ namespace JiShe.CollectBus.Plugins _logger.LogError("协议不存在!"); } var tcpSessionClient = (ITcpSessionClient)client; + TB3761? tB3761 = await protocolPlugin!.AnalyzeAsync(tcpSessionClient, messageHexString); if (tB3761 == null) { @@ -64,16 +65,15 @@ namespace JiShe.CollectBus.Plugins await e.InvokeNext(); } - //[GeneratorPlugin(typeof(ITcpConnectingPlugin))] + public async Task OnTcpConnecting(ITcpSession client, ConnectingEventArgs e) { var tcpSessionClient = (ITcpSessionClient)client; - + _logger.LogInformation($"[TCP] ID:{tcpSessionClient.Id} IP:{client.GetIPPort()}正在连接中..."); await e.InvokeNext(); } - //[GeneratorPlugin(typeof(ITcpConnectedPlugin))] public async Task OnTcpConnected(ITcpSession client, ConnectedEventArgs e) { var tcpSessionClient = (ITcpSessionClient)client; @@ -83,10 +83,9 @@ namespace JiShe.CollectBus.Plugins await e.InvokeNext(); } - //[GeneratorPlugin(typeof(ITcpClosedPlugin))]//ITcpSessionClient public async Task OnTcpClosed(ITcpSession client, ClosedEventArgs e) { - + //todo: 删除Redis缓存 var tcpSessionClient = (ITcpSessionClient)client; var entity = await _deviceRepository.FindAsync(a => a.ClientId == tcpSessionClient.Id); if (entity != null) diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs index 9dc2fc3..184452f 100644 --- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs +++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs @@ -97,39 +97,40 @@ namespace JiShe.CollectBus.ScheduledMeterReading public override async Task> GetAmmeterInfoList(string gatherCode = "V4-Gather-8890") { - //List ammeterInfos = new List(); - //ammeterInfos.Add(new AmmeterInfo() - //{ - // Baudrate = 2400, - // FocusAddress = "402440506", - // Name = "张家祠工务(三相电表)", - // FocusId = 95780, - // DatabaseBusiID = 1, - // MeteringCode = 1, - // AmmerterAddress = "402410040506", - // MeterId = 127035, - // TypeName = 3, - // DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679", - // TimeDensity = 15, - // BrandType = "", - //}); - //ammeterInfos.Add(new AmmeterInfo() - //{ - // Baudrate = 2400, - // FocusAddress = "542400504", - // Name = "五号配(长芦二所四排)(单相电表)", - // FocusId = 69280, - // DatabaseBusiID = 1, - // MeteringCode = 2, - // AmmerterAddress = "542410000504", - // MeterId = 95594, - // TypeName = 1, - // DataTypes = "581,589,592,597,601", - // TimeDensity = 15, - // BrandType = "", - //}); + List ammeterInfos = new List(); + ammeterInfos.Add(new AmmeterInfo() + { + Baudrate = 2400, + FocusAddress = "402440506", + Name = "张家祠工务(三相电表)", + FocusId = 95780, + DatabaseBusiID = 1, + MeteringCode = 1, + AmmerterAddress = "402410040506", + MeterId = 127035, + TypeName = 3, + DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679", + TimeDensity = 15, + BrandType = "DDS1980", + }); - //return ammeterInfos; + ammeterInfos.Add(new AmmeterInfo() + { + Baudrate = 2400, + FocusAddress = "542400504", + Name = "五号配(长芦二所四排)(单相电表)", + FocusId = 69280, + DatabaseBusiID = 1, + MeteringCode = 2, + AmmerterAddress = "542410000504", + MeterId = 95594, + TypeName = 1, + DataTypes = "581,589,592,597,601", + TimeDensity = 15, + BrandType = "DDS1980", + }); + + return ammeterInfos; string sql = $@"SELECT C.ID as MeterId,C.Name,C.FocusID as FocusId,C.SingleRate,C.MeteringCode,C.Code AS BrandType,C.Baudrate,C.Password,C.MeteringPort,C.[Address] AS AmmerterAddress,C.TypeName,C.Protocol,C.TripState,C.[State],B.[Address],B.AreaCode,B.AutomaticReport,D.DataTypes,B.TimeDensity,A.GatherCode,C.Special,C.[ProjectID],B.AbnormalState,B.LastTime,CONCAT(B.AreaCode, B.[Address]) AS FocusAddress,(select top 1 DatabaseBusiID from TB_Project where ID = B.ProjectID) AS DatabaseBusiID FROM TB_GatherInfo(NOLOCK) AS A diff --git a/shared/JiShe.CollectBus.Common/Consts/RedisConst.cs b/shared/JiShe.CollectBus.Common/Consts/RedisConst.cs index 53ad4f6..60340bc 100644 --- a/shared/JiShe.CollectBus.Common/Consts/RedisConst.cs +++ b/shared/JiShe.CollectBus.Common/Consts/RedisConst.cs @@ -28,7 +28,14 @@ namespace JiShe.CollectBus.Common.Consts /// public const string FifteenMinuteAcquisitionTimeInterval = "Fifteen"; + /// + /// 集中器连接信息缓存数据,{0}=>系统类型,{1}=>应用服务部署标记 + /// + public const string ConcentratorCacheHashKey = $"{CacheBasicDirectoryKey}{"{0}:{1}"}:Concentrator"; + + public const string MeterInfo = "MeterInfo"; + /// /// 缓存表计信息,{0}=>系统类型,{1}=>应用服务部署标记,{2}=>表计类别,{3}=>采集频率 /// diff --git a/web/JiShe.CollectBus.Host/Pages/Monitor.cshtml b/web/JiShe.CollectBus.Host/Pages/Monitor.cshtml index 3a7fbc7..7cf09e0 100644 --- a/web/JiShe.CollectBus.Host/Pages/Monitor.cshtml +++ b/web/JiShe.CollectBus.Host/Pages/Monitor.cshtml @@ -17,7 +17,7 @@ 后端服务 - +