From dd92a75fa08757fbe02a402f860e001093186ea8 Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Fri, 24 May 2024 09:24:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E5=B9=B3=E5=8F=B0=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E6=89=93=E6=A0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/DbModel/Station/AmtOrderInfo.cs | 167 ------------------- Entity/DbModel/Station/SwapAmtOrder.cs | 12 +- HybirdFrameworkDriver/Common/MsgCache.cs | 18 +- Repository/Repository.csproj | 4 + Repository/Station/AmtOrderInfoRepository.cs | 13 -- Service/Cloud/Client/CloudClient.cs | 29 +++- Service/Cloud/Handler/AmtBatHandler.cs | 16 +- Service/Cloud/Handler/CarAuthResHandler.cs | 23 +++ Service/Cloud/Handler/CarCanStartHandler.cs | 4 +- 9 files changed, 83 insertions(+), 203 deletions(-) delete mode 100644 Entity/DbModel/Station/AmtOrderInfo.cs delete mode 100644 Repository/Station/AmtOrderInfoRepository.cs create mode 100644 Service/Cloud/Handler/CarAuthResHandler.cs diff --git a/Entity/DbModel/Station/AmtOrderInfo.cs b/Entity/DbModel/Station/AmtOrderInfo.cs deleted file mode 100644 index 7efa3f4..0000000 --- a/Entity/DbModel/Station/AmtOrderInfo.cs +++ /dev/null @@ -1,167 +0,0 @@ -using SqlSugar; - -namespace Entity.DbModel.Station -{ - /// - ///预约订单表 - /// - [SugarTable("amt_order_info")] - public partial class AmtOrderInfo - { - public AmtOrderInfo() - { - } - - /// - /// Desc:主键 - /// Default: - /// Nullable:False - /// - [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] - public long Id { get; set; } - - /// - /// Desc:换电站编码 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "sn")] - public string Sn { get; set; } - - /// - /// Desc:车辆编码 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "car_no")] - public string CarNo { get; set; } - - /// - /// Desc:预约单号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "order_no")] - public string? OrderNo { get; set; } - - /// - /// Desc:车辆vim码 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "vin")] - public string Vin { get; set; } - - /// - /// Desc:预约电池类型编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "battery_type")] - public string BatteryType { get; set; } - - /// - /// Desc:预约电池编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "battery_nos")] - public string BatteryNos { get; set; } - - /// - /// Desc:预约数量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "batnum")] - public int? Batnum { get; set; } - - /// - /// Desc:预约电池锁仓仓号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "bin_nos")] - public string BinNos { get; set; } - - /// - /// Desc:预约时间 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "start_time")] - public DateTime? StartTime { get; set; } - - /// - /// Desc:预约到期时间 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "end_time")] - public DateTime? EndTime { get; set; } - - /// - /// Desc:预约单状态:1:预约成功;2:预约取消;3:预约失败;4:换电完成;5:换电失败;6:换电中;7:预约过期 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "status")] - public byte? Status { get; set; } - - /// - /// Desc:取消时间 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "cancel_time")] - public DateTime? CancelTime { get; set; } - - /// - /// Desc:换电完成时间 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "swap_finish_time")] - public DateTime? SwapFinishTime { get; set; } - - /// - /// Desc:换电订单编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "swap_order_no")] - public string SwapOrderNo { get; set; } - - /// - /// Desc:创建人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "created_by")] - public string CreatedBy { get; set; } - - /// - /// Desc:创建时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName = "created_time")] - public DateTime? CreatedTime { get; set; } - - /// - /// Desc:更新人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName = "updated_by")] - public string UpdatedBy { get; set; } - - /// - /// Desc:更新时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName = "updated_time")] - public DateTime? UpdatedTime { get; set; } - } -} \ No newline at end of file diff --git a/Entity/DbModel/Station/SwapAmtOrder.cs b/Entity/DbModel/Station/SwapAmtOrder.cs index f89c06e..f0115f8 100644 --- a/Entity/DbModel/Station/SwapAmtOrder.cs +++ b/Entity/DbModel/Station/SwapAmtOrder.cs @@ -36,24 +36,24 @@ namespace Entity.DbModel.Station /// Default: /// Nullable:True /// - [SugarColumn(ColumnName="pay_status")] - public int? PayStatus {get;set;} + [SugarColumn(ColumnName="battery_type")] + public string BatteryType {get;set;} /// /// Desc:车辆vin码 /// Default: /// Nullable:True /// - [SugarColumn(ColumnName="vin")] - public string Vin {get;set;} + [SugarColumn(ColumnName="car_no")] + public string CarNo {get;set;} /// /// Desc:车辆mac /// Default: /// Nullable:True /// - [SugarColumn(ColumnName="mac")] - public string Mac {get;set;} + [SugarColumn(ColumnName="battery_no_list")] + public string BatteryNoList {get;set;} /// /// Desc:预约电池数量 diff --git a/HybirdFrameworkDriver/Common/MsgCache.cs b/HybirdFrameworkDriver/Common/MsgCache.cs index 29a1e26..079743c 100644 --- a/HybirdFrameworkDriver/Common/MsgCache.cs +++ b/HybirdFrameworkDriver/Common/MsgCache.cs @@ -2,9 +2,9 @@ namespace HybirdFrameworkDriver.Common; -public class MsgCache +public class MsgCache { - private readonly ConcurrentDictionary _dictionary = new(); + private readonly ConcurrentDictionary> _dictionary = new(); private static readonly string MsgKey = "msg_"; public void Add(string key, dynamic value) @@ -12,7 +12,7 @@ public class MsgCache _dictionary[key] = value; } - public bool TryGet(string key, out dynamic? value) + public bool TryGet(string key, out MsgPair? value) { return _dictionary.TryGetValue(key, out value); } @@ -22,12 +22,12 @@ public class MsgCache _dictionary.Remove(key, out var value); } - public void AddByMsgId(int key, dynamic value) + public void AddByMsgId(int key, MsgPair value) { _dictionary[MsgKey + key] = value; } - public bool TryGetMsgId(int key, out dynamic? value) + public bool TryGetMsgId(int key, out MsgPair? value) { return _dictionary.TryGetValue(MsgKey + key, out value); } @@ -36,4 +36,12 @@ public class MsgCache { _dictionary.Remove(MsgKey + key, out var value); } + + +} + +public class MsgPair +{ + public TReq? Req { get; set; } + public TResp? Resp { get; set; } } \ No newline at end of file diff --git a/Repository/Repository.csproj b/Repository/Repository.csproj index e5483ac..914e75a 100644 --- a/Repository/Repository.csproj +++ b/Repository/Repository.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/Repository/Station/AmtOrderInfoRepository.cs b/Repository/Station/AmtOrderInfoRepository.cs deleted file mode 100644 index 4478473..0000000 --- a/Repository/Station/AmtOrderInfoRepository.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Entity.DbModel.Station; -using HybirdFrameworkCore.Autofac.Attribute; -using SqlSugar; - -namespace Repository.Station; - -[Scope("SingleInstance")] -public class AmtOrderInfoRepository : BaseRepository -{ - public AmtOrderInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) - { - } -} \ No newline at end of file diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index efb7b77..1fb4783 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -3,6 +3,7 @@ using Autofac; using Autofac.Core; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkDriver.Common; using log4net; using MQTTnet; using MQTTnet.Client; @@ -19,6 +20,7 @@ using Newtonsoft.Json.Linq; using Service.Cloud.Handler; using Service.Cloud.Msg; using Service.Cloud.Msg.Cloud.Req; +using Service.Cloud.Msg.Cloud.Resp; using Service.Cloud.Msg.Host.Req; namespace Service.Cloud.Client; @@ -61,15 +63,21 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR #endregion - #region Cmd + #region Cmd msg cache public CarCanStart? CarCanStart { get; set; } + /// + /// + /// + public MsgPair CarAuth { get; set; } = new(); #endregion - private IMqttClient? MqttClient; + #region basic + + private IMqttClient? MqttClient; - private List handlers = new List(); + private List handlers = new (); private static ushort _incrementId; @@ -329,4 +337,19 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR return builder.Build(); } + + #endregion + + + + #region 主动发送CMD + + public void SendVehicleCertification(VehicleCertification vehicleCertification) + { + this.CarAuth.Req = vehicleCertification; + this.CarAuth.Resp = null; + this.Publish(vehicleCertification); + } + + #endregion } \ No newline at end of file diff --git a/Service/Cloud/Handler/AmtBatHandler.cs b/Service/Cloud/Handler/AmtBatHandler.cs index 1aa47dd..e288648 100644 --- a/Service/Cloud/Handler/AmtBatHandler.cs +++ b/Service/Cloud/Handler/AmtBatHandler.cs @@ -14,12 +14,12 @@ namespace Service.Cloud.Handler; public class AmtBatHandler : IBaseHandler { private BinInfoRepository _binInfoRepository; - private AmtOrderInfoRepository _amtOrderInfoRepository; + private SwapAmtOrderRepository _swapAmtOrderRepository; - public AmtBatHandler(BinInfoRepository binInfoRepository, AmtOrderInfoRepository amtOrderInfoRepository) + public AmtBatHandler(BinInfoRepository binInfoRepository, SwapAmtOrderRepository swapAmtOrderRepository) { _binInfoRepository = binInfoRepository; - _amtOrderInfoRepository = amtOrderInfoRepository; + _swapAmtOrderRepository = swapAmtOrderRepository; } public void Handle(string t) @@ -29,7 +29,7 @@ public class AmtBatHandler : IBaseHandler AmtBat? amtBat = JsonConvert.DeserializeObject(t); if (amtBat != null) { - int count = _amtOrderInfoRepository.GetCount(it => + int count = _swapAmtOrderRepository.GetCount(it => it.CarNo == amtBat.cn && it.Status == (byte)InfoEnum.AmtOrderStatus.Success); if (count > 0) @@ -38,14 +38,14 @@ public class AmtBatHandler : IBaseHandler } else { - AmtOrderInfo amtOrderInfo = new AmtOrderInfo() + SwapAmtOrder amtOrderInfo = new SwapAmtOrder() { Sn = StaticStationInfo.StationNo, CarNo = amtBat.cn, - Batnum = amtBat.bm, + BatteryCount = amtBat.bm, BatteryType = amtBat.bn, - StartTime = amtBat.at, - EndTime = amtBat.at.AddMinutes(amtBat.am) + AmtTime = amtBat.at, + ExpireTime = amtBat.at.AddMinutes(amtBat.am) }; } diff --git a/Service/Cloud/Handler/CarAuthResHandler.cs b/Service/Cloud/Handler/CarAuthResHandler.cs new file mode 100644 index 0000000..431c485 --- /dev/null +++ b/Service/Cloud/Handler/CarAuthResHandler.cs @@ -0,0 +1,23 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using Newtonsoft.Json; +using Service.Cloud.Client; +using Service.Cloud.Common; +using Service.Cloud.Msg.Cloud.Resp; + +namespace Service.Cloud.Handler; + +[Scope("InstancePerDependency")] +public class CarAuthResHandler : IBaseHandler + +{ + public bool CanHandle(string cmd) + { + return CloudConst.carAuthRes == cmd; + } + + public void Handle(string t) + { + VehicleCertificationResp? resp = JsonConvert.DeserializeObject(t); + CloudClientMgr.CloudClient.CarAuth.Resp = resp; + } +} \ No newline at end of file diff --git a/Service/Cloud/Handler/CarCanStartHandler.cs b/Service/Cloud/Handler/CarCanStartHandler.cs index d07833d..cdf3d77 100644 --- a/Service/Cloud/Handler/CarCanStartHandler.cs +++ b/Service/Cloud/Handler/CarCanStartHandler.cs @@ -1,10 +1,12 @@ -using Newtonsoft.Json; +using HybirdFrameworkCore.Autofac.Attribute; +using Newtonsoft.Json; using Service.Cloud.Client; using Service.Cloud.Common; using Service.Cloud.Msg.Cloud.Req; namespace Service.Cloud.Handler; +[Scope("InstancePerDependency")] public class CarCanStartHandler : IBaseHandler { public bool CanHandle(string cmd)