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) {