From 396590656615aaceb8f0d41a0e7009529c45a552 Mon Sep 17 00:00:00 2001 From: rszn <645583145@qq.com> Date: Tue, 11 Jun 2024 16:40:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=91=E5=B9=B3=E5=8F=B0mq?= =?UTF-8?q?tt=E7=89=88=E6=9C=AC=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/Constant/StationParamConst.cs | 13 +++++++------ Service/Cloud/Client/CloudClient.cs | 26 +++++++++++++------------- Service/Cloud/Client/CloudClientMgr.cs | 7 ++----- Service/Init/StaticStationInfo.cs | 19 +++++++++---------- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/Entity/Constant/StationParamConst.cs b/Entity/Constant/StationParamConst.cs index bdd1f9b..342f75f 100644 --- a/Entity/Constant/StationParamConst.cs +++ b/Entity/Constant/StationParamConst.cs @@ -64,7 +64,7 @@ public class StationParamConst /// public static readonly string Sevstatus = "Station.Sevstatus"; - + /// /// 投放时间 @@ -183,11 +183,11 @@ public class StationParamConst public static readonly string SetLightDayStartTime = "Station.LightDayStartTime"; public static readonly string SetLightDayEndTime = "Station.LightDayEndTime"; - - - + + + #endregion 系统管理-基础设置 - + //选包策略中最后结束充电时间需要>此值 public static readonly string SwapFinishChargeTime = "Station.SwapFinishChargeTime"; @@ -210,6 +210,7 @@ public class StationParamConst #region cloud param + public static readonly string CloudServerMqttVersion = "Cloud.CloudServerMqttVersion"; public static readonly string CloudServerIp = "Cloud.CloudServerIp"; public static readonly string CloudServerPort = "Cloud.CloudServerPort"; public static readonly string CloudClientId = "Cloud.CloudClientId"; @@ -219,4 +220,4 @@ public class StationParamConst public static readonly string CloudPubTopic = "Cloud.CloudPubTopic"; #endregion -} \ No newline at end of file +} diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index d805b61..f9bc1eb 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -31,7 +31,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR IMqttClientDisconnectedHandler { private static readonly ILog Log = LogManager.GetLogger(typeof(CloudClient)); - + public SwapOrderRepository SwapOrderRepository { get; set;} #region tcp param @@ -43,7 +43,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR public string? Password { get; set; } public int KeepalivePeriod { get; set; } = 3000; public int Timeout { get; set; } = 60; - public string Version { get; set; } = "5.0.16"; + public string MqttVersion { get; set; } = "4.0.0"; public bool IsCleanSession { get; set; } = false; #endregion @@ -71,7 +71,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR public CarCanStart? CarCanStart { get; set; } /// - /// + /// /// public MsgPair CarAuth { get; set; } = new(); public MsgPair ChannelStatus { get; set; } = new(); @@ -225,7 +225,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR MqttTopicFilter topicFilter = new MqttTopicFilter { Topic = str, - QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce + QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce }; list.Add(topicFilter); } @@ -272,7 +272,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR MqttClient.PublishAsync(appMsg); MqttClient.PublishAsync(appMsg); } - + } private string SignData(Model model) where T : ICmd @@ -366,7 +366,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR builder.WithKeepAlivePeriod(TimeSpan.FromSeconds(KeepalivePeriod)) .WithCommunicationTimeout(TimeSpan.FromSeconds(Timeout)); - switch (Version) + switch (MqttVersion) { case "3.1.0": builder.WithProtocolVersion(MqttProtocolVersion.V310); @@ -397,7 +397,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR this.Publish(vehicleCertification); return CarAuth.GetResp(timeSpan); } - + /// /// 换电站通道状态上报 /// @@ -499,8 +499,8 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR this.ChargeRecordUpLoad.Req = req; this.Publish(req); return ChargeRecordUpLoad.GetResp(timeSpan); - } - + } + public ChargeDevDataInfoRes? SendChargeDevDataInfo(ChargeDevDataInfo req, TimeSpan? timeSpan = null) { this.ChargeDevDataInfo.Req = req; @@ -512,7 +512,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR #region business func /// - /// + /// /// /// /// 1: 自动; 2: 人工手动 @@ -534,7 +534,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR ssoc = chargeOrder.StartSoc ?? 0, esoc = lastChargeOrder.StopSoc ?? 0, //ssoe = chargeOrder.soe - //esoe + //esoe dcce =0, acce =0, tp = 0, @@ -557,10 +557,10 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR req.vp += Convert.ToSingle(order.ValleyElecCount); req.ct += ((order.EndTime ?? DateTime.Now).Subtract(order.StartTime ?? DateTime.Now)).Minutes; } - + this.SendChargeRecordUpLoad(req); return true; } #endregion -} \ No newline at end of file +} diff --git a/Service/Cloud/Client/CloudClientMgr.cs b/Service/Cloud/Client/CloudClientMgr.cs index 56c6e61..f162388 100644 --- a/Service/Cloud/Client/CloudClientMgr.cs +++ b/Service/Cloud/Client/CloudClientMgr.cs @@ -1,13 +1,9 @@ using Autofac; -using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Redis; using log4net; -using Newtonsoft.Json; using Repository.Station; -using Service.Cloud.Msg; -using Service.Cloud.Msg.Host.Req; using Service.Init; namespace Service.Cloud.Client; @@ -22,6 +18,7 @@ public class CloudClientMgr { CloudClient = AppInfo.Container.Resolve(); + CloudClient.MqttVersion = StaticStationInfo.CloudServerMqttVersion; CloudClient.ServerIp = StaticStationInfo.CloudServerIp; CloudClient.ServerPort = StaticStationInfo.CloudServerPort; CloudClient.ClientId = StaticStationInfo.CloudClientId; @@ -93,4 +90,4 @@ public class CloudClientMgr } });*/ } -} \ No newline at end of file +} diff --git a/Service/Init/StaticStationInfo.cs b/Service/Init/StaticStationInfo.cs index e8adfbb..3642b80 100644 --- a/Service/Init/StaticStationInfo.cs +++ b/Service/Init/StaticStationInfo.cs @@ -1,7 +1,6 @@ using Autofac; using Entity.Constant; using HybirdFrameworkCore.Autofac; -using Service.Station; using Service.System; namespace Service.Init; @@ -135,17 +134,17 @@ public class StaticStationInfo { get { - string port = Resolve(StationParamConst.CloudServerPort); - if (string.IsNullOrWhiteSpace(port)) - { - return 33000; - } - + string port = Resolve(StationParamConst.CloudServerPort, "33000"); return int.Parse(port); } set => Set(StationParamConst.CloudServerPort, value); } + public static string CloudServerMqttVersion + { + get => Resolve(StationParamConst.CloudServerMqttVersion, "4.0.0"); + set => Set(StationParamConst.CloudServerMqttVersion, value); + } public static string CloudClientId { get => Resolve(StationParamConst.CloudClientId); @@ -182,7 +181,7 @@ public class StaticStationInfo private static SysConfigService _sysConfigService; - private static string Resolve(string key) + private static string Resolve(string key, string? value = default) { if (_sysConfigService == null) { @@ -195,7 +194,7 @@ public class StaticStationInfo return s; } - return ""; + return value; } private static void Set(string key, object value) @@ -209,4 +208,4 @@ public class StaticStationInfo } #endregion -} \ No newline at end of file +}