From b0f84fcc6ba8343939092b34a0e5bfd4b7d51fe1 Mon Sep 17 00:00:00 2001 From: CZ Date: Wed, 11 Sep 2024 23:33:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8D=A2=E4=B8=8B=E7=94=B5?= =?UTF-8?q?=E6=B1=A0=E7=9A=84soc=E5=92=8C=E8=BD=A6=E8=BE=86=E7=A6=BB?= =?UTF-8?q?=E5=9C=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Execute/Step/SwapDoneState.cs | 6 ++ Service/MyJob/UpdateDownBatteryInfoTask.cs | 107 +++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 Service/MyJob/UpdateDownBatteryInfoTask.cs diff --git a/Service/Execute/Step/SwapDoneState.cs b/Service/Execute/Step/SwapDoneState.cs index af0826c..5fc778a 100644 --- a/Service/Execute/Step/SwapDoneState.cs +++ b/Service/Execute/Step/SwapDoneState.cs @@ -134,6 +134,12 @@ public class SwapDoneState : IState return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, () => { + //更新车辆离场时间 + machine.BusinessSwappingForCloudState = + InfoEnum.BusinessSwappingForCloudState.SwapDoneWithoutVel; + machine.SwapOrder!.VehicleLeaveTime = DateTime.Now; + _CommonMgr.UpdateSwapOrder(machine); + //新增小步 _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarOutFlag, machine); diff --git a/Service/MyJob/UpdateDownBatteryInfoTask.cs b/Service/MyJob/UpdateDownBatteryInfoTask.cs new file mode 100644 index 0000000..f721634 --- /dev/null +++ b/Service/MyJob/UpdateDownBatteryInfoTask.cs @@ -0,0 +1,107 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.AutoTask; +using log4net; +using Newtonsoft.Json; +using Repository.Station; +using Service.Mgr; + +namespace Service.MyTask; + +/// +/// 充电结束上报云平台task +/// +[Scope] +public class UpdateDownBatteryInfoTask : ITask +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(UpdateDownBatteryInfoTask)); + + private volatile bool _stop; + + + public SwapOrderBatteryRepository _swapOrderBatteryRepository { get; set; } + + public BinInfoRepository _BinInfoRepository { get; set; } + + public string Name() + { + return "UpdateDownBatteryInfoTask"; + } + + public int Interval() + { + return 1000 * 2; + } + + public void Handle() + { + try + { + List batterys = + _swapOrderBatteryRepository.QueryListByClause( + i => (i.DownBatteryNo == null || i.DownBatterySoc<0) && i.DownBatteryBinNo != null); + + + if (batterys.Count <= 0) + { + return; + } + + + List downBatteryBinNos = batterys.Select(i => i.DownBatteryBinNo.ToString()).ToList(); + Dictionary binInfosMap = _BinInfoRepository + .QueryListByClause(i => downBatteryBinNos.Contains(i.No) && i.Exists==1).ToDictionary(i => i.No); + + List updateDbBattery = new List(); + + foreach (var battery in batterys) + { + //更新换下电池包 + binInfosMap.TryGetValue(battery.DownBatteryBinNo.ToString(), out BinInfo info); + if (info.BatteryNo == null || info.BatteryNo == "" || info.BatteryNo == "-1") + { + continue; + } + if (info.Soc == null || info.Soc <=0) + { + continue; + } + + /*if (!info.BatteryNo.Equals(battery.DownBatteryNo)) + { + continue; + }*/ + battery.DownBatteryNo = info.BatteryNo; + battery.DownBatterySoc = info.Soc; + battery.DownBatterySoe = info.Soe; + updateDbBattery.Add(battery); + } + + if (updateDbBattery.Count > 0) + { + Log.Info( + $" UpdateDownBatteryInfoTask update DowmBatteryInfo db={JsonConvert.SerializeObject(updateDbBattery)}"); + _swapOrderBatteryRepository.Update(updateDbBattery); + } + } + catch (Exception e) + { + Log.Error($" UpdateDownBatteryInfoTask err e={e}"); + } + } + + public bool Stoped() + { + return _stop; + } + + public void Stop() + { + _stop = true; + } + + public void ResetStop() + { + _stop = false; + } +} \ No newline at end of file