From 1279eaf4ac025e48ec594d6143513115853c5bcd Mon Sep 17 00:00:00 2001 From: CZ Date: Sat, 14 Sep 2024 20:04:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8D=A2=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E7=94=B5=E6=B1=A0=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/MyJob/UpdateDownBatteryInfoTask.cs | 113 +--------------- Service/MyTask/UpdateDownBatteryInfoTask.cs | 141 ++++++++++++++++++++ 2 files changed, 142 insertions(+), 112 deletions(-) create mode 100644 Service/MyTask/UpdateDownBatteryInfoTask.cs diff --git a/Service/MyJob/UpdateDownBatteryInfoTask.cs b/Service/MyJob/UpdateDownBatteryInfoTask.cs index a31ea81..5f28270 100644 --- a/Service/MyJob/UpdateDownBatteryInfoTask.cs +++ b/Service/MyJob/UpdateDownBatteryInfoTask.cs @@ -1,112 +1 @@ -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 == 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 + \ No newline at end of file diff --git a/Service/MyTask/UpdateDownBatteryInfoTask.cs b/Service/MyTask/UpdateDownBatteryInfoTask.cs new file mode 100644 index 0000000..fee7d83 --- /dev/null +++ b/Service/MyTask/UpdateDownBatteryInfoTask.cs @@ -0,0 +1,141 @@ +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; + +/// +/// 更新换下的电池编码和soc +/// +[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() + { + Log.Info("Begin UpdateDownBatteryInfo"); + try + { + var listSwapOrderBattery = + _swapOrderBatteryRepository.QueryListByClause(i => i.DownBatteryNo == "-1" && i.DownBatterySoc == -1); + if (listSwapOrderBattery.Count > 0) + { + Log.Info("listSwapOrderBattery.Count > 0"); + var UpSwapOrderBattery = listSwapOrderBattery[listSwapOrderBattery.Count - 1]; + var lstBinInfo = _BinInfoRepository.QueryByClause(i => i.Exists == 1 + && i.No == UpSwapOrderBattery.DownBatteryBinNo + .ToString() + && i.Soc > 0 + && !string.IsNullOrEmpty(i.BatteryNo) + && i.BatteryNo != "-1"); + if (lstBinInfo != null) + { + _swapOrderBatteryRepository.Update(i => new SwapOrderBattery() + { + DownBatterySoc = lstBinInfo.Soc, + DownBatteryNo = lstBinInfo.BatteryNo + }, + i => i.SwapOrderSn.ToString() == UpSwapOrderBattery.SwapOrderSn + && i.DownBatteryBinNo == UpSwapOrderBattery.DownBatteryBinNo); + Log.Info($"update DownBatteryBinNo SwapOrderSn:{UpSwapOrderBattery.SwapOrderSn} soc:{lstBinInfo.Soc} DownBatteryNo:{lstBinInfo.BatteryNo}"); + } + } + } + catch (Exception e) + { + } + + + /*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; + }#1# + 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