From afcc3bc11f63206fab69f58e23a5ea85a07121d3 Mon Sep 17 00:00:00 2001 From: CZ Date: Tue, 18 Jun 2024 15:52:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E7=94=B5=E6=9C=BA=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=8C=E6=8E=A5=E6=94=B6=E5=85=85=E7=94=B5=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=B8=A7handler=E6=9B=B4=E6=96=B0sql?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Handler/RemoteStartChargingResHandler.cs | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/Service/Charger/Handler/RemoteStartChargingResHandler.cs b/Service/Charger/Handler/RemoteStartChargingResHandler.cs index 00974f0..35d60eb 100644 --- a/Service/Charger/Handler/RemoteStartChargingResHandler.cs +++ b/Service/Charger/Handler/RemoteStartChargingResHandler.cs @@ -26,35 +26,41 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, RemoteStartChargingRes msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) - { - Log.Info($"receive {msg} from {sn}"); - if (msg.Result == 0) + if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { - 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(); + Log.Info($"receive {msg} from {sn}"); + if (msg.Result == 0) + { + 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); - } + if (chargeOrders.Count > 0) + { + ChargeOrder one = chargeOrders[0]; + ChargeOrderRepository.Update( + i => new ChargeOrder() + { + CmdStatus = 1, + StartTime = client.ChargingStartTime + }, + it => it.Id == one.Id); + } + } + else + { + client.ChargingStatus = (int)ChargingStatus.StartChargingFailed; + client.ChargingStartTime = Convert.ToDateTime("2000-1-1"); + } } else { client.ChargingStatus = (int)ChargingStatus.StartChargingFailed; - client.ChargingStartTime = Convert.ToDateTime("2000-1-1"); } - } - else - { - client.ChargingStatus = (int)ChargingStatus.StartChargingFailed; - } } } -} +} \ No newline at end of file