From 6b60d2c6d8aef55e74e569a0aecc1b8e4b00e762 Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Wed, 22 May 2024 12:01:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=99=E6=80=81=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Cloud/Client/CloudClient.cs | 2 ++ Service/Cloud/Client/CloudClientMgr.cs | 3 ++- Service/Init/StaticStationInfo.cs | 12 ++++++++++-- Service/System/SysConfigService.cs | 17 ++++++++++++++--- .../Controllers/System/SysConfigController.cs | 19 +++++++++++++++++-- .../Debug/net6.0/staticwebassets.build.json | 12 ++---------- 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index 49e2c8f..3a6f906 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -138,6 +138,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR Connected = false; if (AutoReConnect) { + Thread.Sleep(5000); Connect(); } } @@ -147,6 +148,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR Log.Error("connect cloud error", e); if (AutoReConnect) { + Thread.Sleep(5000); Connect(); } } diff --git a/Service/Cloud/Client/CloudClientMgr.cs b/Service/Cloud/Client/CloudClientMgr.cs index d694665..ba6e0b0 100644 --- a/Service/Cloud/Client/CloudClientMgr.cs +++ b/Service/Cloud/Client/CloudClientMgr.cs @@ -28,6 +28,7 @@ public class CloudClientMgr CloudClient.AutoReConnect = true; CloudClient.InitHandler(); - CloudClient.Connect(); + + // Task.Run(() => CloudClient.Connect()); } } \ No newline at end of file diff --git a/Service/Init/StaticStationInfo.cs b/Service/Init/StaticStationInfo.cs index c2bf035..bb18b56 100644 --- a/Service/Init/StaticStationInfo.cs +++ b/Service/Init/StaticStationInfo.cs @@ -40,7 +40,15 @@ public class StaticStationInfo public static int CloudServerPort { - get => int.Parse(Resolve(StationParamConst.CloudServerPort)); + get + { + string port = Resolve(StationParamConst.CloudServerPort); + if (string.IsNullOrWhiteSpace(port)) + { + return 33000; + } + return int.Parse(port); + } set => Set(StationParamConst.CloudServerPort, value); } @@ -93,7 +101,7 @@ public class StaticStationInfo return s; } - return "33000"; + return ""; } private static void Set(string key, object value) diff --git a/Service/System/SysConfigService.cs b/Service/System/SysConfigService.cs index bff4456..062268a 100644 --- a/Service/System/SysConfigService.cs +++ b/Service/System/SysConfigService.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System.Collections.Concurrent; +using System.ComponentModel; using Autofac; using Common.Enum; using Entity.Base; @@ -19,6 +20,7 @@ namespace Service.System [Scope("SingleInstance")] public class SysConfigService : BaseServices { + private static readonly ConcurrentDictionary Dictionary = new ConcurrentDictionary(); private readonly SysConfigMgr _sysConfigMgr; private readonly SysConfigRepository _sysConfigRep; @@ -168,6 +170,11 @@ namespace Service.System throw new InvalidParameterException("配置数据key格式错误"); } + if (Dictionary.TryGetValue(key, out string? value)) + { + return value; + } + SysConfig sysConfig = _sysConfigRep.QueryByClause(i => i.GroupCode == keys[0] && i.Code == keys[1]); if (sysConfig == null) { @@ -190,6 +197,10 @@ namespace Service.System throw new InvalidParameterException("配置数据key格式错误"); } + string newValue = Convert.ToString(value); + + Dictionary.AddOrUpdate(key, newValue, (s, s1) => newValue); + SysConfig sysConfig = _sysConfigRep.QueryByClause(i => i.GroupCode == keys[0] && i.Code == keys[1]); if (sysConfig == null) { @@ -197,14 +208,14 @@ namespace Service.System { GroupCode = keys[0], Code = keys[1], - Value = value.ToString(), + Value = newValue, SysFlag = YesNoEnum.N, Name = key }); } else { - sysConfig.Value = value.ToString(); + sysConfig.Value = newValue; _sysConfigRep.Update(sysConfig); } diff --git a/WebStarter/Controllers/System/SysConfigController.cs b/WebStarter/Controllers/System/SysConfigController.cs index f59279c..3b2277c 100644 --- a/WebStarter/Controllers/System/SysConfigController.cs +++ b/WebStarter/Controllers/System/SysConfigController.cs @@ -1,8 +1,8 @@ - -using Entity.Base; +using Entity.Base; using Entity.DbModel.System.SysBaseObject; using Entity.Dto.Req; using Microsoft.AspNetCore.Mvc; +using Service.Init; using Service.System; namespace WebStarter.Controllers.System @@ -72,5 +72,20 @@ namespace WebStarter.Controllers.System { await _sysConfigService.BatchDeleteConfig(input); } + + [HttpGet] + [Route("/api/sysConfig/GetStationNo")] + public string GetStationNo() + { + return StaticStationInfo.StationName; + } + + [HttpGet] + [Route("/api/sysConfig/SetStationNo/{stationNo}")] + public bool SetStationNo(string stationNo) + { + StaticStationInfo.StationName = stationNo; + return true; + } } } diff --git a/WebStarter/obj/Debug/net6.0/staticwebassets.build.json b/WebStarter/obj/Debug/net6.0/staticwebassets.build.json index 572be60..309b0b1 100644 --- a/WebStarter/obj/Debug/net6.0/staticwebassets.build.json +++ b/WebStarter/obj/Debug/net6.0/staticwebassets.build.json @@ -1,19 +1,11 @@ { "Version": 1, - "Hash": "FS59OvTZ9B6lpwaxIjb4jYpPMI2uWVuvwpvRJoWtEFc=", + "Hash": "7euZr+Skxn+CPwHhQ3H6LZuur9IzJqC+CYg6oY75X7A=", "Source": "WebStarter", "BasePath": "_content/WebStarter", "Mode": "Default", "ManifestType": "Build", "ReferencedProjectsConfiguration": [], - "DiscoveryPatterns": [ - { - "Name": "WebStarter\\wwwroot", - "Source": "WebStarter", - "ContentRoot": "D:\\Desktop\\huannengMain\\WebStarter\\wwwroot\\", - "BasePath": "_content/WebStarter", - "Pattern": "**" - } - ], + "DiscoveryPatterns": [], "Assets": [] } \ No newline at end of file