From 73b0c361faf1fd855fcac6948d780b41b3e902c6 Mon Sep 17 00:00:00 2001 From: CZ Date: Sat, 15 Jun 2024 17:40:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=B5=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?=E5=85=85=E7=94=B5=E6=9C=BA=E5=90=AF=E5=8A=A8=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=B8=A7=E6=9B=B4=E6=96=B0=E5=90=AF=E5=8A=A8=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=92=8C=20=E5=90=AF=E5=8A=A8=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Charger/Common/ChargerConst.cs | 19 ++++++++------ .../Handler/RemoteStartChargingResHandler.cs | 15 +++++++++++ .../Charger/MyTask/EmeterEnergyRecordTask.cs | 26 ++++++++++++++++--- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/Service/Charger/Common/ChargerConst.cs b/Service/Charger/Common/ChargerConst.cs index a59be89..7a0e424 100644 --- a/Service/Charger/Common/ChargerConst.cs +++ b/Service/Charger/Common/ChargerConst.cs @@ -24,12 +24,15 @@ public static class ChargerConst /// public enum ChargingStatus { - UnKnown, - Authed, - AuthFailed, - StartChargingSuccess, - StartChargingFailed, - Charging, - StopChargingSuccess, - StopChargingFailed + UnKnown=0, + StartChargingSuccess=1, + + StopChargingSuccess=4, + Authed=5, + AuthFailed=6, + + StartChargingFailed=7, + // Charging, + + StopChargingFailed=8 } \ No newline at end of file diff --git a/Service/Charger/Handler/RemoteStartChargingResHandler.cs b/Service/Charger/Handler/RemoteStartChargingResHandler.cs index 923f4ce..00974f0 100644 --- a/Service/Charger/Handler/RemoteStartChargingResHandler.cs +++ b/Service/Charger/Handler/RemoteStartChargingResHandler.cs @@ -1,6 +1,8 @@ using DotNetty.Transport.Channels; +using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using log4net; +using Repository.Station; using Service.Charger.Client; using Service.Charger.Common; using Service.Charger.Msg.Charger.Resp; @@ -19,6 +21,9 @@ namespace Service.Charger.Handler public class RemoteStartChargingResHandler : SimpleChannelInboundHandler, IBaseHandler { private static readonly ILog Log = LogManager.GetLogger(typeof(RemoteStartChargingResHandler)); + + public ChargeOrderRepository ChargeOrderRepository { get; set; } + protected override void ChannelRead0(IChannelHandlerContext ctx, RemoteStartChargingRes msg) { if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) @@ -29,6 +34,16 @@ namespace Service.Charger.Handler client.IsStopped = false; client.ChargingStatus = (int)ChargingStatus.StartChargingSuccess; client.ChargingStartTime = DateTime.Now; + //查找最新的充电订单 + List chargeOrders = ChargeOrderRepository.QueryListByClause(i => i.BatteryNo == client.BatteryNo, "created_time desc") + .Take(1).ToList(); + + if (chargeOrders.Count > 0) + { + ChargeOrder one = chargeOrders[0]; + ChargeOrderRepository.Update(i => i.CmdStatus == 1 && i.StartTime == client.ChargingStartTime, + it => it.Id == one.Id); + } } else { diff --git a/Service/Charger/MyTask/EmeterEnergyRecordTask.cs b/Service/Charger/MyTask/EmeterEnergyRecordTask.cs index 0d82708..b1f5b32 100644 --- a/Service/Charger/MyTask/EmeterEnergyRecordTask.cs +++ b/Service/Charger/MyTask/EmeterEnergyRecordTask.cs @@ -34,6 +34,8 @@ public class EmeterEnergyRecordTask : ITask { try { + List list = new List(); + List listEmeterEnergyChanges = new List(); foreach (var keyValuePair in ClientMgr.Dictionary) { var chargerClient = keyValuePair.Value; @@ -41,27 +43,43 @@ public class EmeterEnergyRecordTask : ITask { string id = DateTime.Now.ToString("yyyyMMddHHmmss"); + string code = StaticStationInfo.StationNo + "_" + chargerClient.Sn; + id = id + "_" + chargerClientSn; EmeterEnergy emeterEnergy = new() { Id = id, UploadFlag = 0, Value = chargerClient.UploadTelemetryData.DcMeterCurrentPower, - Code = StaticStationInfo.StationNo + "_" + chargerClient.Sn, + Code =code , UploadTime = DateTime.Now }; - EmeterEnergyRepository.Insert(emeterEnergy); + list.Add(emeterEnergy); + EmeterEnergyChange emeterEnergyChange = new() { Id = id, UploadFlag = 0, Value = chargerClient.UploadTelemetryData.ACMeterCurrentBatteryValue, - Code = StaticStationInfo.StationNo + "_" + chargerClient.Sn, + Code = code, UploadTime = DateTime.Now }; - EmeterEnergyChangeRepository.Insert(emeterEnergyChange); + listEmeterEnergyChanges.Add(emeterEnergyChange); + } } + + if (list.Count > 0) + { + EmeterEnergyRepository.Insert(list); + } + + if (listEmeterEnergyChanges.Count > 0) + { + EmeterEnergyChangeRepository.Insert(listEmeterEnergyChanges); + } + + } catch (Exception e) {