You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
/// <summary>
/// 更新换下电池包
/// 首先要放下电池执行完成,然后查询在那个仓
/// </summary>
[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;
}
/// <summary>
/// 更新换下电池包及上辅源
/// 逻辑
/// 查最新一条换电订单看里面soc电池编码以及在位状态
/// 如果订单中soc电池编码都为负数并且仓位电池数据都在就可以更新了
/// </summary>
public void Handle()
{
#region 更新换下电池
var listSwapOrderBattery =
_swapOrderBatteryRepository.QueryListByClause(i => i.DownBatteryNo == "-1" && i.DownBatterySoc == -1);
if (listSwapOrderBattery.Count > 0)
{
string SwapOrderSn = listSwapOrderBattery[listSwapOrderBattery.Count - 1].SwapOrderSn;
//查询两个仓位
var SwapOrderBatteryInfo1 = listSwapOrderBattery[listSwapOrderBattery.Count - 1];
var SwapOrderBatteryInfo2 = listSwapOrderBattery[listSwapOrderBattery.Count - 2];
var lstBinInfo = _BinInfoRepository.QueryListByClause(i => i.Exists == 1
&&
(i.No == SwapOrderBatteryInfo1.DownBatteryBinNo
.ToString() ||
i.No == SwapOrderBatteryInfo2.DownBatteryBinNo
.ToString())
&& i.Soc > 0
/*&& !string.IsNullOrEmpty(i.BatteryNo)*/
&&i.BatteryNo!="-1");
if (lstBinInfo.Count >= 2) //有换电电池包编码需要更新
{
var BinInfo0 = lstBinInfo.Where(i => i.No == SwapOrderBatteryInfo1.DownBatteryBinNo.ToString()).ToList()[0];
var BinInfo1 = lstBinInfo.Where(i => i.No == SwapOrderBatteryInfo2.DownBatteryBinNo.ToString()).ToList()[0];
_swapOrderBatteryRepository.Update(i =>new SwapOrderBattery()
{
DownBatterySoc = BinInfo0.Soc,
DownBatteryNo = BinInfo0.BatteryNo
},
i => i.SwapOrderSn.ToString() == SwapOrderBatteryInfo1.SwapOrderSn
&&i.DownBatteryBinNo==SwapOrderBatteryInfo1.DownBatteryBinNo);
_swapOrderBatteryRepository.Update(i => new SwapOrderBattery()
{
DownBatterySoc = BinInfo1.Soc,
DownBatteryNo = BinInfo1.BatteryNo
}, i => i.SwapOrderSn.ToString() == SwapOrderBatteryInfo2.SwapOrderSn&&i.DownBatteryBinNo==SwapOrderBatteryInfo2.DownBatteryBinNo);
}
}
#endregion
/*try
{
List<SwapOrderBattery> batterys =
_swapOrderBatteryRepository.QueryListByClause(
i => (i.DownBatteryNo == null || i.DownBatterySoc < 0) && i.DownBatteryBinNo != null);
if (batterys.Count <= 0)
{
return;
}
List<string> downBatteryBinNos = batterys.Select(i => i.DownBatteryBinNo.ToString()).ToList();
Dictionary<string, BinInfo> binInfosMap = _BinInfoRepository
.QueryListByClause(i => downBatteryBinNos.Contains(i.No)).ToDictionary(i => i.No);
List<SwapOrderBattery> updateDbBattery = new List<SwapOrderBattery>();
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;
}
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;
}
}