From 194c122ee4a60c160b6121d1e81b5d4e6ef0dfc6 Mon Sep 17 00:00:00 2001 From: zby <24947@USER> Date: Fri, 13 Sep 2024 17:31:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B0=8F=E5=B8=83=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/MyJob/UpdateDownBatteryInfoTask.cs | 200 +++++++++--------- .../Controllers/SwapMonitorController.cs | 9 +- 2 files changed, 105 insertions(+), 104 deletions(-) diff --git a/Service/MyJob/UpdateDownBatteryInfoTask.cs b/Service/MyJob/UpdateDownBatteryInfoTask.cs index cd25213..a31ea81 100644 --- a/Service/MyJob/UpdateDownBatteryInfoTask.cs +++ b/Service/MyJob/UpdateDownBatteryInfoTask.cs @@ -8,101 +8,105 @@ 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 +/// +/// 充电结束上报云平台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 == null) { + continue; + + } + 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 diff --git a/WebStarter/Controllers/SwapMonitorController.cs b/WebStarter/Controllers/SwapMonitorController.cs index 9e83290..e21dbf3 100644 --- a/WebStarter/Controllers/SwapMonitorController.cs +++ b/WebStarter/Controllers/SwapMonitorController.cs @@ -26,9 +26,9 @@ public class SwapMonitorController : ControllerBase private readonly BinInfoService _binInfoService; private readonly IStringLocalizer _localizer; - public SwapMonitorController(IStringLocalizer localizer,MonitorService swapMonitorService, BinInfoService binInfoService) + public SwapMonitorController(MonitorService swapMonitorService, BinInfoService binInfoService) { - _localizer = localizer; + _swapMonitorService = swapMonitorService; _binInfoService = binInfoService; } @@ -54,10 +54,7 @@ public class SwapMonitorController : ControllerBase var respList = _swapMonitorService.GetSwapMonitorData(); - foreach (var item in respList.Data?.StateInfo) - { - item.StepName = _localizer[item.StepNo.ToString()]; - } + return respList; }