From d490f510dcfdfa298c42328a38029cbb897efd25 Mon Sep 17 00:00:00 2001 From: qsp89 Date: Fri, 21 Nov 2025 10:24:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E4=B8=89=E7=BB=B4=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=A2=9E=E5=8A=A0=E6=96=87=E6=9C=AC=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YunDa.Server.ISMSTcp/Program.cs | 3 ++ .../Services/ThingService.cs | 53 +++++++++++++++++-- .../Services/VirtualTerminalHandler.cs | 14 ++++- .../Services/ZzDataCacheContainer.cs | 4 +- .../YunDa.Server.ISMSTcp/appsettings.json | 6 +++ 5 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/YunDa.Server/YunDa.Server.ISMSTcp/Program.cs b/src/YunDa.Server/YunDa.Server.ISMSTcp/Program.cs index f07798f..ceea2f3 100644 --- a/src/YunDa.Server/YunDa.Server.ISMSTcp/Program.cs +++ b/src/YunDa.Server/YunDa.Server.ISMSTcp/Program.cs @@ -97,6 +97,9 @@ namespace YunDa.Server.ISMSTcp // 注册 WebApi 配置类 services.Configure(context.Configuration.GetSection("WebApi")); + + // 注册 ThingApiService配置 + services.Configure(context.Configuration.GetSection("ThingApiService")); }) .UseSerilog() .UseConsoleLifetime(); diff --git a/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/ThingService.cs b/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/ThingService.cs index bec3175..876cb0a 100644 --- a/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/ThingService.cs +++ b/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/ThingService.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Newtonsoft.Json.Linq; using StackExchange.Redis; using System; @@ -30,6 +31,15 @@ using static System.Net.Mime.MediaTypeNames; namespace YunDa.Server.ISMSTcp.Services { + //ThingApiService配置 + public class ThingApiServiceSettings + { + public string ApiServerUrl { get; set; } = string.Empty; + public string LoginCode { get; set; } = string.Empty; + public string LoginKey { get; set; } = string.Empty; + public string EsAuthorization { get; set; } = string.Empty; + } + public class ThingDeviceStatusModel { public string TwinID { get; set; } = string.Empty; @@ -623,16 +633,31 @@ namespace YunDa.Server.ISMSTcp.Services } //推送全体性能数据 + + private int _updateAllSimDatasCnt = 0; private async Task UpdateAllSimDatas() { + + /*******************推送遥测全体性能数据/*******************/ var telemeteringModels = await _telemeteringModelListRedis.HashSetGetAllAsync(_telemeteringModelListRediskey); - await UpdateYCSimDatasStatus(telemeteringModels); /*******************推送遥信全体性能数据/*******************/ var telesignalisationModels = await _telesignalisationModelListRedis.HashSetGetAllAsync(_telesignalisationModelListRediskey); - await UpdateYXSimDatasStatus(telesignalisationModels); + + if(_updateAllSimDatasCnt == 0) + { + await UpdateThingYCStatus(telemeteringModels); + await UpdateThingYXStatus(telesignalisationModels); + } + else + { + await UpdateYCSimDatasStatus(telemeteringModels); + await UpdateYXSimDatasStatus(telesignalisationModels); + } + + ++_updateAllSimDatasCnt; } //推送遥测性能数据 @@ -1213,14 +1238,36 @@ namespace YunDa.Server.ISMSTcp.Services private DateTime _apiTokenTime = DateTime.MinValue; private readonly SemaphoreSlim _apiTokenSemaphore = new SemaphoreSlim(1, 1); + private readonly ThingApiServiceSettings _thingApiServiceSettings; + public ThingApiService( - ILogger logger) + ILogger logger, + IOptions thingApiServiceSettings) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _deviceStatusChannel = Channel.CreateUnbounded>(); _alarmDataChannel = Channel.CreateUnbounded>(); + + _thingApiServiceSettings = thingApiServiceSettings.Value; + + if (!string.IsNullOrWhiteSpace(_thingApiServiceSettings.ApiServerUrl)) + _apiServerUrl = _thingApiServiceSettings.ApiServerUrl; + + if (!string.IsNullOrWhiteSpace(_thingApiServiceSettings.LoginCode)) + _loginCode = _thingApiServiceSettings.LoginCode; + + if (!string.IsNullOrWhiteSpace(_thingApiServiceSettings.LoginKey)) + _loginKey = _thingApiServiceSettings.LoginKey; + + if (!string.IsNullOrWhiteSpace(_thingApiServiceSettings.EsAuthorization)) + _esAuthorization = _thingApiServiceSettings.EsAuthorization; + + System.Console.WriteLine($"ThingApiService Url: {_apiServerUrl}"); + + + StartPushDeviceStatus(); StarPushAlarmStatus(); diff --git a/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/VirtualTerminalHandler.cs b/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/VirtualTerminalHandler.cs index 611585c..2949424 100644 --- a/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/VirtualTerminalHandler.cs +++ b/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/VirtualTerminalHandler.cs @@ -375,7 +375,19 @@ namespace YunDa.Server.ISMSTcp.Services { try { - _zzDataCacheContainer.Write(id, value, timestamp, ""); + string valStr = "不定"; + switch((int)value) + { + case 0: + valStr = "报警"; + break; + + case 1: + valStr = "正常"; + break; + } + + _zzDataCacheContainer.Write(id, value, timestamp, "", valStr); } catch (Exception ex) { diff --git a/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/ZzDataCacheContainer.cs b/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/ZzDataCacheContainer.cs index 549047d..1cce302 100644 --- a/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/ZzDataCacheContainer.cs +++ b/src/YunDa.Server/YunDa.Server.ISMSTcp/Services/ZzDataCacheContainer.cs @@ -272,14 +272,14 @@ namespace YunDa.Server.ISMSTcp.Services { string cmd = "CallVAByStat|B001"; - for (int i = 0; i < 3; i++) + for (int i = 0; i < 5; i++) { var sendResult = await _zTcpService.SendTcpMessageAsync(cmd, CancellationToken.None); if (sendResult.Success) { break; } - await Task.Delay(1000); + await Task.Delay(2000); } } } diff --git a/src/YunDa.Server/YunDa.Server.ISMSTcp/appsettings.json b/src/YunDa.Server/YunDa.Server.ISMSTcp/appsettings.json index e3a1c24..4410f15 100644 --- a/src/YunDa.Server/YunDa.Server.ISMSTcp/appsettings.json +++ b/src/YunDa.Server/YunDa.Server.ISMSTcp/appsettings.json @@ -52,6 +52,12 @@ "EnableCors": true, "AllowedOrigins": ["*"] }, + "ThingApiService":{ + "ApiServerUrl": "http://192.168.81.22", + "LoginCode": "admin", + "LoginKey": "Thing@123", + "EsAuthorization": "admin:uino", + }, "CommunicationFramework": { "Port": 7110, "WorkerThreads": 4,