From 870de0478291af4f46f2273a0327a163478ae22a Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Thu, 30 May 2024 13:57:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E5=B9=B3=E5=8F=B0=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HybirdFrameworkCore/Utils/ObjUtils.cs | 47 ++++++++ Service/Cloud/Client/CloudClient.cs | 107 +++++++++++++---- .../Client/MyTask/ChargeOrderUploadTask.cs | 12 +- Service/Cloud/Common/CloudConst.cs | 2 + .../Handler/ChargeDevDataInfoResHandler.cs | 32 +++++ .../Handler/ChargeRecordUploadResHandler.cs | 40 +++++++ .../Handler/UploadSwapOrderResHandler.cs | 39 ++++++ .../Msg/Cloud/Resp/ChargeRecordUploadRes.cs | 13 ++ ...ngeOrderResp.cs => UploadSwapOrderResp.cs} | 2 +- Service/Cloud/Msg/Header.cs | 2 +- .../Cloud/Msg/Host/Req/ChargeDevDataInfo.cs | 40 +++++-- .../Cloud/Msg/Host/Req/ChargeRecordUpLoad.cs | 111 ++++++++++++++++++ ...PowerChangeOrder.cs => UploadSwapOrder.cs} | 2 +- Service/Execute/Api/CloudApi.cs | 6 +- Service/Execute/StationSoftMgr.cs | 4 +- Service/Station/ChargeOrderService.cs | 35 +++++- .../Controllers/ChargeOrderController.cs | 11 +- 17 files changed, 445 insertions(+), 60 deletions(-) create mode 100644 HybirdFrameworkCore/Utils/ObjUtils.cs create mode 100644 Service/Cloud/Handler/ChargeDevDataInfoResHandler.cs create mode 100644 Service/Cloud/Handler/ChargeRecordUploadResHandler.cs create mode 100644 Service/Cloud/Handler/UploadSwapOrderResHandler.cs create mode 100644 Service/Cloud/Msg/Cloud/Resp/ChargeRecordUploadRes.cs rename Service/Cloud/Msg/Cloud/Resp/{UploadPowerChangeOrderResp.cs => UploadSwapOrderResp.cs} (93%) create mode 100644 Service/Cloud/Msg/Host/Req/ChargeRecordUpLoad.cs rename Service/Cloud/Msg/Host/Req/{UploadPowerChangeOrder.cs => UploadSwapOrder.cs} (99%) diff --git a/HybirdFrameworkCore/Utils/ObjUtils.cs b/HybirdFrameworkCore/Utils/ObjUtils.cs new file mode 100644 index 0000000..5ccb25c --- /dev/null +++ b/HybirdFrameworkCore/Utils/ObjUtils.cs @@ -0,0 +1,47 @@ +namespace HybirdFrameworkCore.Utils; + +/// +/// +/// +public static class ObjUtils +{ + /// + /// + /// + /// + /// + public static bool IsNull(object? o) + { + return o == null; + } + + /// + /// + /// + /// + /// + public static bool IsNotNull(object? o) + { + return o != null; + } + + /// + /// + /// + /// + /// + public static bool IsNullOrWhiteSpace(string? o) + { + return string.IsNullOrWhiteSpace(o); + } + + /// + /// + /// + /// + /// + public static bool IsNotNullOrWhiteSpace(string? o) + { + return !string.IsNullOrWhiteSpace(o); + } +} \ No newline at end of file diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index 3b3b92e..9b20e57 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -2,6 +2,7 @@ using Autofac; using Autofac.Core; using Common.Util; +using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkDriver.Common; @@ -11,18 +12,17 @@ using MQTTnet.Client; using MQTTnet.Client.Connecting; using MQTTnet.Client.Disconnecting; using MQTTnet.Client.Options; -using MQTTnet.Client.Publishing; using MQTTnet.Client.Receiving; using MQTTnet.Formatter; using MQTTnet.Protocol; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Repository.Station; 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; -using Service.Init; namespace Service.Cloud.Client; @@ -31,6 +31,8 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR IMqttClientDisconnectedHandler { private static readonly ILog Log = LogManager.GetLogger(typeof(CloudClient)); + + public SwapOrderRepository SwapOrderRepository { get; set;} #region tcp param @@ -82,8 +84,10 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR public MsgPair Sign { get; set; } = new(); public MsgPair StartLog { get; set; } = new(); public MsgPair TemperatureHumidity { get; set; } = new(); - public MsgPair UploadPowerChange { get; set; } = new(); + public MsgPair UploadPowerChange { get; set; } = new(); public MsgPair VehicleData { get; set; } = new(); + public MsgPair ChargeRecordUpLoad { get; set; } = new(); + public MsgPair ChargeDevDataInfo { get; set; } = new(); #endregion @@ -193,14 +197,23 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR { await DoSubTopic(SubTopic); - SendSignIn(new SignIn() + SendVehicleCertification(new VehicleCertification() { - sn = StaticStationInfo.StationNo, - st = "01", - ss = StaticStationInfo.StationStatus, + dt = DateTime.Now, en = 1, - cn = 7 + mode =1, + rfid= "LZ5NB6D33RB000438", + ty= 2, + vi ="LZ5NB6D33RB000438" }); + // SendSignIn(new SignIn() + // { + // sn = StaticStationInfo.StationNo, + // st = "01", + // ss = StaticStationInfo.StationStatus, + // en = 1, + // cn = 7 + // }); } private async Task DoSubTopic(string topic) @@ -229,7 +242,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR Header = new Header() { cmd = data.GetCmd(), - chipherFlag = Encrypt, + cipherFlag = Encrypt, id = GetIncrementId(), sid = StationNo, timeStamp = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000 @@ -237,7 +250,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR body = data }; - model.dataSign = SignData(model); + model.dataSign = "";//SignData(model); var settings = new JsonSerializerSettings() { @@ -245,6 +258,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR DateFormatString = "yyyy-MM-dd HH:mm:ss", NullValueHandling = NullValueHandling.Ignore }; + Log.Info(JsonConvert.SerializeObject(model, settings)); var appMsg = new MqttApplicationMessage { Topic = PubTopic, @@ -253,12 +267,8 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR Retain = false }; - Task task = MqttClient.PublishAsync(appMsg); - var result = task.Result; - if (result.ReasonCode == MqttClientPublishReasonCode.Success) - { - Log.Info($"send {JsonConvert.SerializeObject(model, settings)} success"); - } + MqttClient.PublishAsync(appMsg); + MqttClient.PublishAsync(appMsg); } private string SignData(Model model) where T : ICmd @@ -460,14 +470,13 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR /// /// 上传换电订单 /// - /// + /// /// /// - public UploadPowerChangeOrderResp? SendUploadPowerChangeOrder(UploadPowerChangeOrder uploadPowerChangeOrder, - TimeSpan timeSpan) + public UploadSwapOrderResp? SendUploadPowerChangeOrder(UploadSwapOrder uploadSwapOrder, TimeSpan? timeSpan = null) { - this.UploadPowerChange.Req = uploadPowerChangeOrder; - this.Publish(uploadPowerChangeOrder); + this.UploadPowerChange.Req = uploadSwapOrder; + this.Publish(uploadSwapOrder); return UploadPowerChange.GetResp(timeSpan); } public VehicleDataReportingResp? SendVehicleDataReporting(VehicleDataReporting vehicleDataReporting, @@ -477,5 +486,61 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR this.Publish(vehicleDataReporting); return VehicleData.GetResp(timeSpan); } + + public ChargeRecordUploadRes? SendChargeRecordUpLoad(ChargeRecordUpLoad req, TimeSpan? timeSpan = null) + { + this.ChargeRecordUpLoad.Req = req; + this.Publish(req); + return ChargeRecordUpLoad.GetResp(timeSpan); + } + + public ChargeDevDataInfoRes? SendChargeDevDataInfo(ChargeDevDataInfo req, TimeSpan? timeSpan = null) + { + this.ChargeDevDataInfo.Req = req; + this.Publish(req); + return ChargeDevDataInfo.GetResp(timeSpan); + } + #endregion + + #region business func + + /// + /// + /// + /// + /// 1: 自动; 2: 人工手动 + /// 超时等待 + /// + public bool PublishChargeOrder(ChargeOrder chargeOrder, int op, TimeSpan? timeSpan = null) + { + string swapOrderSn = chargeOrder.SwapOrderSn; + SwapOrder? swapOrder = SwapOrderRepository.QueryByClause(it => it.Sn == swapOrderSn); + ChargeRecordUpLoad req = new ChargeRecordUpLoad() + { + chrsn = chargeOrder.Sn, + son = swapOrderSn, + bid = chargeOrder.BatteryNo, + st = chargeOrder.StartTime ?? DateTime.Now, + et = chargeOrder.EndTime ?? DateTime.Now, + ssoc = chargeOrder.StartSoc ?? 0, + esoc = chargeOrder.StopSoc ?? 0, + //ssoe = chargeOrder.soe + //esoe + dcce = Convert.ToSingle(chargeOrder.StopDcElec ?? 0 - chargeOrder.StartDcElec ?? 0), + acce = Convert.ToSingle(chargeOrder.StopAcElec ?? 0 - chargeOrder.StartAcElec ?? 0), + tp = Convert.ToSingle(chargeOrder.SharpElecCount), + pp = Convert.ToSingle(chargeOrder.PeakElecCount), + fp = Convert.ToSingle(chargeOrder.FlatElecCount), + vp = Convert.ToSingle(chargeOrder.ValleyElecCount), + ct = ((chargeOrder.EndTime ?? DateTime.Now).Subtract(chargeOrder.StartTime ?? DateTime.Now)).Minutes, + cn = 1, + sfs = op, + vin = swapOrder?.VehicleVin, + sfoc = op, + }; + this.SendChargeRecordUpLoad(req); + return true; + } + #endregion } \ No newline at end of file diff --git a/Service/Cloud/Client/MyTask/ChargeOrderUploadTask.cs b/Service/Cloud/Client/MyTask/ChargeOrderUploadTask.cs index 0d55097..80e05fc 100644 --- a/Service/Cloud/Client/MyTask/ChargeOrderUploadTask.cs +++ b/Service/Cloud/Client/MyTask/ChargeOrderUploadTask.cs @@ -11,12 +11,7 @@ public class ChargeOrderUploadTask : AbstractTaskHandler { private static readonly ILog Log = LogManager.GetLogger(typeof(ChargeOrderUploadTask)); - private readonly ChargeOrderRepository _chargeOrderRepository; - - public ChargeOrderUploadTask(ChargeOrderRepository chargeOrderRepository) - { - _chargeOrderRepository = chargeOrderRepository; - } + public ChargeOrderRepository _chargeOrderRepository { get; set; } protected override int Interval() { @@ -25,15 +20,14 @@ public class ChargeOrderUploadTask : AbstractTaskHandler protected override void Handle() { - List? chargeOrders = _chargeOrderRepository.QueryListByClause(it => it.CloudReportStatus != 1); + List? chargeOrders = _chargeOrderRepository.QueryListByClause(it => it.CloudReportStatus ==0); Log.Info($"there are {chargeOrders?.Count ?? 0} to upload"); if (chargeOrders is { Count: > 0 }) { foreach (ChargeOrder chargeOrder in chargeOrders) { - //TODO - //CloudClientMgr.CloudClient?.Publish(); + CloudClientMgr.CloudClient?.PublishChargeOrder(chargeOrder, 1); } } } diff --git a/Service/Cloud/Common/CloudConst.cs b/Service/Cloud/Common/CloudConst.cs index 25eee20..c4e741d 100644 --- a/Service/Cloud/Common/CloudConst.cs +++ b/Service/Cloud/Common/CloudConst.cs @@ -41,6 +41,8 @@ public class CloudConst public static readonly string amtBatRes = "amtBatRes"; public static readonly string ChargeRecordReport = "ChargeRecordReport"; public static readonly string ChargeRecordReportsRes = "ChargeRecordReportsRes"; + public static readonly string ChargeRecordUpLoad = "ChargeRecordUpLoad"; + public static readonly string ChargeRecordUpLoadRes = "ChargeRecordUpLoadRes"; public static readonly string stationRunStatus = "stationRunStatus"; public static readonly string stationRunStatusRes = "stationRunStatusRes"; public static readonly string stationChnRunStatus = "stationChnRunStatus"; diff --git a/Service/Cloud/Handler/ChargeDevDataInfoResHandler.cs b/Service/Cloud/Handler/ChargeDevDataInfoResHandler.cs new file mode 100644 index 0000000..973fec2 --- /dev/null +++ b/Service/Cloud/Handler/ChargeDevDataInfoResHandler.cs @@ -0,0 +1,32 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +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 ChargeDevDataInfoResHandler : IBaseHandler +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(ChargeDevDataInfoResHandler)); + + public void Handle(string t) + { + ChargeDevDataInfoRes? resp = JsonConvert.DeserializeObject(t); + if (resp != null) + { + if (CloudClientMgr.CloudClient != null) + { + CloudClientMgr.CloudClient.ChargeDevDataInfo.SetResp(resp); + Log.Info($"receive ChargeDevDataInfoRes {JsonConvert.SerializeObject(resp)}"); + } + } + } + + public bool CanHandle(string cmd) + { + return CloudConst.chargeDevDataInfoRes == cmd; + } +} \ No newline at end of file diff --git a/Service/Cloud/Handler/ChargeRecordUploadResHandler.cs b/Service/Cloud/Handler/ChargeRecordUploadResHandler.cs new file mode 100644 index 0000000..b977a13 --- /dev/null +++ b/Service/Cloud/Handler/ChargeRecordUploadResHandler.cs @@ -0,0 +1,40 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Newtonsoft.Json; +using Repository.Station; +using Service.Cloud.Client; +using Service.Cloud.Common; +using Service.Cloud.Msg.Cloud.Resp; + +namespace Service.Cloud.Handler; + +[Scope("InstancePerDependency")] +public class ChargeRecordUploadResHandler : IBaseHandler +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(ChargeRecordUploadResHandler)); + + public ChargeOrderRepository ChargeOrderRepository { get; set; } + + public void Handle(string t) + { + ChargeRecordUploadRes? res = JsonConvert.DeserializeObject(t); + if (res != null) + { + if (CloudClientMgr.CloudClient != null) + { + CloudClientMgr.CloudClient.ChargeRecordUpLoad.SetResp(res); + string? reqChrsn = CloudClientMgr.CloudClient.ChargeRecordUpLoad.Req?.chrsn; + Log.Info($"receive ChargeRecordUploadRes chargeOrderNo={reqChrsn} {JsonConvert.SerializeObject(res)}"); + if (!string.IsNullOrWhiteSpace(reqChrsn) && res.re == 0) + { + ChargeOrderRepository.Update(it => it.CloudReportStatus == 1, it => it.Sn == reqChrsn); + } + } + } + } + + public bool CanHandle(string cmd) + { + return CloudConst.ChargeRecordUpLoadRes == cmd; + } +} \ No newline at end of file diff --git a/Service/Cloud/Handler/UploadSwapOrderResHandler.cs b/Service/Cloud/Handler/UploadSwapOrderResHandler.cs new file mode 100644 index 0000000..f32b209 --- /dev/null +++ b/Service/Cloud/Handler/UploadSwapOrderResHandler.cs @@ -0,0 +1,39 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Newtonsoft.Json; +using Repository.Station; +using Service.Cloud.Client; +using Service.Cloud.Common; +using Service.Cloud.Msg.Cloud.Resp; + +namespace Service.Cloud.Handler; + +[Scope("InstancePerDependency")] +public class UploadSwapOrderResHandler : IBaseHandler +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(UploadSwapOrderResHandler)); + + public SwapOrderRepository SwapOrderRepository { get; set; } + public void Handle(string t) + { + UploadSwapOrderResp? resp = JsonConvert.DeserializeObject(t); + if (resp != null) + { + if (CloudClientMgr.CloudClient != null) + { + CloudClientMgr.CloudClient.UploadPowerChange.SetResp(resp); + string? reqSon = CloudClientMgr.CloudClient.UploadPowerChange.Req?.son; + Log.Info($"receive UploadSwapOrderRes swapOrderNo={reqSon} {JsonConvert.SerializeObject(resp)}"); + if (!string.IsNullOrWhiteSpace(reqSon) && resp.re == 0) + { + SwapOrderRepository.Update(it => it.CloudReportStatus == 1, it => it.Sn == reqSon); + } + } + } + } + + public bool CanHandle(string cmd) + { + return CloudConst.staSwapRecordRes == cmd; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Resp/ChargeRecordUploadRes.cs b/Service/Cloud/Msg/Cloud/Resp/ChargeRecordUploadRes.cs new file mode 100644 index 0000000..31095ab --- /dev/null +++ b/Service/Cloud/Msg/Cloud/Resp/ChargeRecordUploadRes.cs @@ -0,0 +1,13 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Cloud.Resp; + +public class ChargeRecordUploadRes : ICmd +{ + public int re { get; set; } + + public string GetCmd() + { + return CloudConst.ChargeRecordUpLoadRes; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Resp/UploadPowerChangeOrderResp.cs b/Service/Cloud/Msg/Cloud/Resp/UploadSwapOrderResp.cs similarity index 93% rename from Service/Cloud/Msg/Cloud/Resp/UploadPowerChangeOrderResp.cs rename to Service/Cloud/Msg/Cloud/Resp/UploadSwapOrderResp.cs index be52d6c..748dc6e 100644 --- a/Service/Cloud/Msg/Cloud/Resp/UploadPowerChangeOrderResp.cs +++ b/Service/Cloud/Msg/Cloud/Resp/UploadSwapOrderResp.cs @@ -10,7 +10,7 @@ namespace Service.Cloud.Msg.Cloud.Resp /// /// 4.2.1.2 后台服务器应答换电站上报的订单信息 /// - public class UploadPowerChangeOrderResp : ICmd + public class UploadSwapOrderResp : ICmd { /// /// 应答结果 diff --git a/Service/Cloud/Msg/Header.cs b/Service/Cloud/Msg/Header.cs index 8ffd0f8..fcd91fb 100644 --- a/Service/Cloud/Msg/Header.cs +++ b/Service/Cloud/Msg/Header.cs @@ -17,7 +17,7 @@ public class Header /// /// /// - public int chipherFlag { get; set; } + public int cipherFlag { get; set; } /// /// /// diff --git a/Service/Cloud/Msg/Host/Req/ChargeDevDataInfo.cs b/Service/Cloud/Msg/Host/Req/ChargeDevDataInfo.cs index db6f7db..ddaa624 100644 --- a/Service/Cloud/Msg/Host/Req/ChargeDevDataInfo.cs +++ b/Service/Cloud/Msg/Host/Req/ChargeDevDataInfo.cs @@ -1,139 +1,163 @@ using Service.Cloud.Common; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Service.Cloud.Msg.Host.Req { /// /// 4.2.10.1 换电站充电机数据上报 /// - public class ChargeDevDataInfo + public class ChargeDevDataInfo : ICmd { - /// /// 场站编码 换电站唯一码 /// public string sn { get; set; } + /// /// 设备编号 设备编号 /// public string en { get; set; } + /// /// 充电架 ID 按电池架的编号 A1,A2… /// public string sd { get; set; } + /// /// 充电机最大允许 输出功率 单位 0.1kw /// public float mtp { get; set; } + /// /// 充电机最大允 许充电速率 单位 0.1C /// public float mcr { get; set; } + /// /// 电池架上是否有 电池 0:未知 1:有电池 2:无电池 /// public int hb { get; set; } + /// /// 电接头连接状态 0:未知 1:已经连接 2:未连接 /// public int el { get; set; } + /// /// 充电机序号 从 1 开始递增 /// public int cno { get; set; } + /// /// 充电机的工作状态 00H:待机 01H:工作02H:工作完成03H:充电暂停 /// public int cs { get; set; } + /// /// 故障状态 00H:无故障 01H:有故障 /// public int fs { get; set; } + ///告警状态 00H:无告警.01H:有告警 public int @as { get; set; } + /// /// 故障码 参考充电机的故障码定义 /// public int fc { get; set; } + /// /// 充电开始时间 没有进行充电填空 /// public DateTime st { get; set; } + /// /// 已经充电时间 单位 分钟 /// public int ct { get; set; } + /// /// 充电开始 SOC 0-100 单位 0.1 ,没有充电填 0 /// public int ssoc { get; set; } + /// /// 当前 SOC 单位 0.1 /// public int csoc { get; set; } + /// /// 充电开始 SOE 单位 0.1kwh,没有充电填 0 /// public float ssoe { get; set; } + /// /// 当前 SOE 单位 0.1kwh /// public float csoe { get; set; } + /// /// 当前充电电压 单位 0.1V,没有充电填 0 /// public float cvot { get; set; } + /// /// 当前充电电流 单位 0.1A,没有充电填 0 /// public float ccur { get; set; } + /// /// BMS 需求电压 单位 0.1V,没有充电填 0 /// public float nvot { get; set; } + /// /// BMS 需求电流 单位 0.1A,没有充电填 0 /// public float ncur { get; set; } + /// /// 最低单体电压 单位 0.01V /// public float lsv { get; set; } + /// /// 最高单体电压 单位 0.01V /// public float hsv { get; set; } + /// /// 最低单体温度 单位 0.1℃ /// public float lst { get; set; } + /// /// 最高单体温度 单位 0.1℃ /// public float hst { get; set; } + /// /// 水冷状态 0:未知 1:开启 2:关闭 0xFF: 无水冷设备 /// public byte ws { get; set; } + /// /// 进水口温度 单位 0.1℃ , 没有水冷设备填 0xFF /// public float it { get; set; } + /// /// 出水口温度 单位 0.1℃ , 没有水冷设备填 0xFF /// public float ot { get; set; } + /// /// 更新时间 格式 ”yyyy-MM-dd HH:mm:ss ” /// public DateTime bt { get; set; } + public string GetCmd() { return CloudConst.chargeDevDataInfo; } } -} +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Req/ChargeRecordUpLoad.cs b/Service/Cloud/Msg/Host/Req/ChargeRecordUpLoad.cs new file mode 100644 index 0000000..2032b06 --- /dev/null +++ b/Service/Cloud/Msg/Host/Req/ChargeRecordUpLoad.cs @@ -0,0 +1,111 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Host.Req; + +public class ChargeRecordUpLoad : ICmd +{ + /// + /// 充电序列号 + /// + public string chrsn { get; set; } + + /// + /// 换电序列号 + /// + public string son { get; set; } + + /// + /// 电池序列号 + /// + public string bid { get; set; } + + /// + /// 开始时间 + /// + public DateTime st { get; set; } + + /// + /// 结束时间 + /// + public DateTime et { get; set; } + + /// + /// 开始 SOC + /// + public int ssoc { get; set; } + + /// + /// 结束 SOC + /// + public int esoc { get; set; } + + /// + /// 开始 SOE + /// + public float ssoe { get; set; } + + /// + /// 结束 SOE + /// + public float esoe { get; set; } + + /// + /// 直流电表充电 电量 + /// + public float dcce { get; set; } + + /// + /// 交流电表充电 电量 + /// + public float acce { get; set; } + + /// + /// 尖时段电量 + /// + public float tp { get; set; } + + /// + /// 峰时段电量 + /// + public float pp { get; set; } + + /// + /// 平时段电量 + /// + public float fp { get; set; } + + /// + /// 谷时段电量 + /// + public float vp { get; set; } + + /// + /// 充电时长 分钟 + /// + public int ct { get; set; } + + /// + /// 充电次数 + /// + public int cn { get; set; } + + /// + /// 1: 自动; 2: 人工手动 + /// + public int sfs { get; set; } + + /// + /// 车辆vin码 + /// + public string? vin { get; set; } + + /// + /// 0:站内充电 1: 站外充电 + /// + public int sfoc { get; set; } + + public string GetCmd() + { + return CloudConst.ChargeRecordUpLoad; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Req/UploadPowerChangeOrder.cs b/Service/Cloud/Msg/Host/Req/UploadSwapOrder.cs similarity index 99% rename from Service/Cloud/Msg/Host/Req/UploadPowerChangeOrder.cs rename to Service/Cloud/Msg/Host/Req/UploadSwapOrder.cs index 1ac6065..776f6e5 100644 --- a/Service/Cloud/Msg/Host/Req/UploadPowerChangeOrder.cs +++ b/Service/Cloud/Msg/Host/Req/UploadSwapOrder.cs @@ -10,7 +10,7 @@ namespace Service.Cloud.Msg.Host.Req /// /// 4.2.1.1 换电上传换电订单 /// - public class UploadPowerChangeOrder : ICmd + public class UploadSwapOrder : ICmd { /// /// 换电站编码 diff --git a/Service/Execute/Api/CloudApi.cs b/Service/Execute/Api/CloudApi.cs index e29c2e5..d23a94d 100644 --- a/Service/Execute/Api/CloudApi.cs +++ b/Service/Execute/Api/CloudApi.cs @@ -53,7 +53,7 @@ public abstract class CloudApi public static int UploadSwapOrder(SwapOrder swapOrder, int seq, SwapOrderBattery swapOrderBattery, int uploadType) { - UploadPowerChangeOrder uploadPowerChangeOrder = new() + UploadSwapOrder uploadSwapOrder = new() { son = swapOrder.CloudSn, cn = swapOrder.VehicleNo, @@ -78,8 +78,8 @@ public abstract class CloudApi wt = new TimeSpan((swapOrder.SwapEndTime.ToDateTime().Ticks - swapOrder.SwapBeginTime.ToDateTime().Ticks)) .TotalSeconds.ToInt(), }; - UploadPowerChangeOrderResp? sendUploadPowerChangeOrder = CloudClientMgr.CloudClient?.SendUploadPowerChangeOrder( - uploadPowerChangeOrder, + UploadSwapOrderResp? sendUploadPowerChangeOrder = CloudClientMgr.CloudClient?.SendUploadPowerChangeOrder( + uploadSwapOrder, global::System.TimeSpan.FromSeconds(TimeSpan)); if (sendUploadPowerChangeOrder == null) { diff --git a/Service/Execute/StationSoftMgr.cs b/Service/Execute/StationSoftMgr.cs index 892bc34..acf84fe 100644 --- a/Service/Execute/StationSoftMgr.cs +++ b/Service/Execute/StationSoftMgr.cs @@ -1,6 +1,6 @@ using Service.BusinessTask; using Service.BusinessTask.MyTask; -using Service.Execute.StaticTools; +using Service.Cloud.Client.MyTask; namespace Service.Execute { @@ -14,6 +14,7 @@ namespace Service.Execute private static readonly AbstractTaskHandler SwapOrderReportCloudTask = new SwapOrderReportCloudTask(); private static readonly AbstractTaskHandler BatteryMoveTask = new BatteryMoveTask(); + private static readonly AbstractTaskHandler ChargeOrderUploadTask = new ChargeOrderUploadTask(); #region Task @@ -25,6 +26,7 @@ namespace Service.Execute { SwapOrderReportCloudTask.Start(); BatteryMoveTask.Start(); + ChargeOrderUploadTask.Start(); } /// diff --git a/Service/Station/ChargeOrderService.cs b/Service/Station/ChargeOrderService.cs index cbe0217..1a8c5c1 100644 --- a/Service/Station/ChargeOrderService.cs +++ b/Service/Station/ChargeOrderService.cs @@ -6,10 +6,12 @@ using HybirdFrameworkCore.Entity; using Repository.Station; using SqlSugar; using System.Linq.Expressions; +using HybirdFrameworkCore.Utils; +using Service.Cloud.Client; namespace Service.Station; /// -/// 綩 +/// 充电订单 /// [Scope("SingleInstance")] public class ChargeOrderService : BaseServices @@ -23,19 +25,19 @@ public class ChargeOrderService : BaseServices /// - /// ѯҳ + /// 根据条件查询分页数据 /// /// /// public PageResult QueryChargeOrder(QueryChargeOrderReq chargeOrder) { - //һյıʽ + //创建一个空的表达式树 Expression> where = null; - //// ʽ + //// 定义参数表达式 ParameterExpression parameter = Expression.Parameter(typeof(ChargeOrder), "u"); - #region ̬ѯ + #region 构建动态查询树 if (chargeOrder.Id != 0) { Expression> condition1Expr = u => u.Id == chargeOrder.Id; @@ -118,9 +120,30 @@ public class ChargeOrderService : BaseServices } #endregion - //ѯ + //查询 return PageResult.ConvertPage(chargeOrderRepository.QueryIPageByCause(chargeOrder, where)); + } + + /// + /// + /// + /// + /// + public async Task> Upload2Cloud(int id) + { + ChargeOrder? order = await BaseDal.QueryByIdAsync(id); + if (ObjUtils.IsNull(order)) + { + return Result.Fail("数据不存在"); + } + + if (order.CloudReportStatus == 1) + { + return Result.Success("已经上传到云平台"); + } + CloudClientMgr.CloudClient?.PublishChargeOrder(order, 2); + return Result.Success(); } } \ No newline at end of file diff --git a/WebStarter/Controllers/ChargeOrderController.cs b/WebStarter/Controllers/ChargeOrderController.cs index 2d46f17..f511b71 100644 --- a/WebStarter/Controllers/ChargeOrderController.cs +++ b/WebStarter/Controllers/ChargeOrderController.cs @@ -56,20 +56,13 @@ public class ChargeOrderController : ControllerBase } - - - /// /// 充电订单上报云端 /// /// [HttpGet("UploadCloud/{id}")] - public async Task> UploadCloud(long id) + public async Task> UploadCloud(int id) { - - return Result.Success(null); + return await chargeOrderService.Upload2Cloud(id); } - - - } \ No newline at end of file