From ba60504e1069372202be948e054bb19c21dea5ca Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Thu, 30 May 2024 18:45:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E7=94=B5=E8=AE=A2=E5=8D=95=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/DbModel/Station/ChargeOrder.cs | 68 +++++++++++-------- HybirdFrameworkCore/Utils/ObjUtils.cs | 24 +++++++ Service/Cloud/Client/CloudClient.cs | 41 +++++++---- .../Client/MyTask/ChargeOrderUploadTask.cs | 9 ++- .../Handler/ChargeRecordUploadResHandler.cs | 2 +- Service/Station/ChargeOrderService.cs | 15 ++-- 6 files changed, 105 insertions(+), 54 deletions(-) diff --git a/Entity/DbModel/Station/ChargeOrder.cs b/Entity/DbModel/Station/ChargeOrder.cs index d516fcc..339c531 100644 --- a/Entity/DbModel/Station/ChargeOrder.cs +++ b/Entity/DbModel/Station/ChargeOrder.cs @@ -1,7 +1,4 @@ -using System; -using System.Linq; -using System.Text; -using SqlSugar; +using SqlSugar; namespace Entity.DbModel.Station { @@ -13,9 +10,8 @@ namespace Entity.DbModel.Station { public ChargeOrder() { - - } + /// /// Desc:id /// Default: @@ -63,12 +59,14 @@ namespace Entity.DbModel.Station /// [SugarColumn(ColumnName = "charger_gun_no")] public string ChargerGunNo { get; set; } + /// /// 0:站内充电 1:站外充电 /// [SugarColumn(ColumnName = "charge_mode")] public int ChargeMode { get; set; } + /// /// 1:站控启动 2:本地启动 /// @@ -108,13 +106,13 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName = "stop_soc")] public int? StopSoc { get; set; } - /// - /// Desc:充电时长 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="charge_time_count")] - public int? ChargeTimeCount {get;set;} + /// + /// Desc:充电时长 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "charge_time_count")] + public int? ChargeTimeCount { get; set; } /// /// Desc:充电电量 @@ -124,21 +122,21 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName = "elec_count")] public decimal? ElecCount { get; set; } - /// - /// Desc:交流电表量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="ac_elec_count")] - public decimal? AcElecCount {get;set;} + /// + /// Desc:交流电表量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_elec_count")] + public decimal? AcElecCount { get; set; } - /// - /// Desc:充电开始交流表电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="start_ac_elec")] - public decimal? StartAcElec {get;set;} + /// + /// Desc:充电开始交流表电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_ac_elec")] + public decimal? StartAcElec { get; set; } /// /// Desc:充电结束交流表电量 @@ -298,6 +296,20 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName = "cloud_sn")] public string? CloudSn { get; set; } + /// + /// Desc:云平台订单编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "cloud_charge_order")] + public string CloudChargeOrder { get; set; } + /// + /// Desc:是否可以上传云平台 0-不可用;1-可以 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "can_upload")] + public int? CanUpload { get; set; } } -} +} \ No newline at end of file diff --git a/HybirdFrameworkCore/Utils/ObjUtils.cs b/HybirdFrameworkCore/Utils/ObjUtils.cs index 5ccb25c..fb39f97 100644 --- a/HybirdFrameworkCore/Utils/ObjUtils.cs +++ b/HybirdFrameworkCore/Utils/ObjUtils.cs @@ -25,6 +25,28 @@ public static class ObjUtils return o != null; } + /// + /// + /// + /// + /// + /// + public static bool IsEmpty(List? list) + { + return list == null || list.Count == 0; + } + + /// + /// + /// + /// + /// + /// + public static bool IsNotEmpty(List? list) + { + return list is { Count: >= 0 }; + } + /// /// /// @@ -44,4 +66,6 @@ public static class ObjUtils { return !string.IsNullOrWhiteSpace(o); } + + public static readonly List EmptyList = new List(0); } \ No newline at end of file diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index 9b20e57..2d499b2 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -511,33 +511,46 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR /// 1: 自动; 2: 人工手动 /// 超时等待 /// - public bool PublishChargeOrder(ChargeOrder chargeOrder, int op, TimeSpan? timeSpan = null) + public bool PublishChargeOrder(List orders, int op, TimeSpan? timeSpan = null) { + ChargeOrder chargeOrder = orders[0]; + ChargeOrder lastChargeOrder = orders[^1]; string swapOrderSn = chargeOrder.SwapOrderSn; SwapOrder? swapOrder = SwapOrderRepository.QueryByClause(it => it.Sn == swapOrderSn); ChargeRecordUpLoad req = new ChargeRecordUpLoad() { - chrsn = chargeOrder.Sn, + chrsn = chargeOrder.CloudChargeOrder, son = swapOrderSn, bid = chargeOrder.BatteryNo, st = chargeOrder.StartTime ?? DateTime.Now, - et = chargeOrder.EndTime ?? DateTime.Now, + et = lastChargeOrder.EndTime ?? DateTime.Now, ssoc = chargeOrder.StartSoc ?? 0, - esoc = chargeOrder.StopSoc ?? 0, + esoc = lastChargeOrder.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, + dcce =0, + acce =0, + tp = 0, + pp = 0, + fp = 0, + vp = 0, + ct = 0, + cn = orders.Count, sfs = op, - vin = swapOrder?.VehicleVin, - sfoc = op, + vin = swapOrder.VehicleVin, + sfoc = 0, }; + foreach (ChargeOrder order in orders) + { + req.dcce += Convert.ToSingle(order.StopDcElec ?? 0 - order.StartDcElec ?? 0); + req.acce += Convert.ToSingle(order.StopAcElec ?? 0 - order.StartAcElec ?? 0); + req.tp += Convert.ToSingle(order.SharpElecCount); + req.pp += Convert.ToSingle(order.PeakElecCount); + req.fp += Convert.ToSingle(order.FlatElecCount); + req.vp += Convert.ToSingle(order.ValleyElecCount); + req.ct += ((order.EndTime ?? DateTime.Now).Subtract(order.StartTime ?? DateTime.Now)).Minutes; + } + this.SendChargeRecordUpLoad(req); return true; } diff --git a/Service/Cloud/Client/MyTask/ChargeOrderUploadTask.cs b/Service/Cloud/Client/MyTask/ChargeOrderUploadTask.cs index 80e05fc..70bbf56 100644 --- a/Service/Cloud/Client/MyTask/ChargeOrderUploadTask.cs +++ b/Service/Cloud/Client/MyTask/ChargeOrderUploadTask.cs @@ -20,14 +20,17 @@ public class ChargeOrderUploadTask : AbstractTaskHandler protected override void Handle() { - List? chargeOrders = _chargeOrderRepository.QueryListByClause(it => it.CloudReportStatus ==0); + List? chargeOrders = _chargeOrderRepository.QueryListByClause(it => it.CloudReportStatus ==0 && it.CanUpload == 1); Log.Info($"there are {chargeOrders?.Count ?? 0} to upload"); if (chargeOrders is { Count: > 0 }) { - foreach (ChargeOrder chargeOrder in chargeOrders) + + var group = chargeOrders.GroupBy(it => it.CloudChargeOrder); + foreach (IGrouping grouping in group) { - CloudClientMgr.CloudClient?.PublishChargeOrder(chargeOrder, 1); + List orders = grouping.ToList(); + CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 1); } } } diff --git a/Service/Cloud/Handler/ChargeRecordUploadResHandler.cs b/Service/Cloud/Handler/ChargeRecordUploadResHandler.cs index b977a13..790982d 100644 --- a/Service/Cloud/Handler/ChargeRecordUploadResHandler.cs +++ b/Service/Cloud/Handler/ChargeRecordUploadResHandler.cs @@ -27,7 +27,7 @@ public class ChargeRecordUploadResHandler : IBaseHandler 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); + ChargeOrderRepository.Update(it => it.CloudReportStatus == 1, it => it.CloudChargeOrder == reqChrsn); } } } diff --git a/Service/Station/ChargeOrderService.cs b/Service/Station/ChargeOrderService.cs index 1a8c5c1..88b45f3 100644 --- a/Service/Station/ChargeOrderService.cs +++ b/Service/Station/ChargeOrderService.cs @@ -1,12 +1,11 @@ +using System.Linq.Expressions; using Entity.Api.Req; using Entity.Api.Resp; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; -using Repository.Station; -using SqlSugar; -using System.Linq.Expressions; using HybirdFrameworkCore.Utils; +using Repository.Station; using Service.Cloud.Client; namespace Service.Station; @@ -130,20 +129,20 @@ public class ChargeOrderService : BaseServices /// /// /// - public async Task> Upload2Cloud(int id) + public Result Upload2Cloud(string cloudChargerOrder) { - ChargeOrder? order = await BaseDal.QueryByIdAsync(id); - if (ObjUtils.IsNull(order)) + List orders = BaseDal.QueryListByClause(it => it.CloudChargeOrder == cloudChargerOrder); + if (ObjUtils.IsEmpty(orders)) { return Result.Fail("数据不存在"); } - if (order.CloudReportStatus == 1) + if ( orders[0].CloudReportStatus == 1) { return Result.Success("已经上传到云平台"); } - CloudClientMgr.CloudClient?.PublishChargeOrder(order, 2); + CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2); return Result.Success(); } } \ No newline at end of file