|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using HybirdFrameworkCore.AutoTask;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
using Service.Init;
|
|
|
|
|
|
|
|
|
|
namespace Service.MyTask;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 换电订单算费用
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Scope]
|
|
|
|
|
public class SwapOrderSettleAnAccountTask : ITask
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(SwapOrderSettleAnAccountTask));
|
|
|
|
|
|
|
|
|
|
private volatile bool _stop;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SwapOrderBatteryRepository SwapOrderBatteryRepository { get; set; }
|
|
|
|
|
|
|
|
|
|
private SwapOrderRepository SwapOrderRepository { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SwapOrderSettleAnAccountTask(SwapOrderBatteryRepository swapOrderBatteryRepository,
|
|
|
|
|
SwapOrderRepository swapOrderRepository)
|
|
|
|
|
{
|
|
|
|
|
SwapOrderBatteryRepository = swapOrderBatteryRepository;
|
|
|
|
|
SwapOrderRepository = swapOrderRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string Name()
|
|
|
|
|
{
|
|
|
|
|
return "SwapOrderSettleAnAccountTask";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Interval()
|
|
|
|
|
{
|
|
|
|
|
return 1000 * 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle()
|
|
|
|
|
{
|
|
|
|
|
Log.Info("Begin SwapOrderSettleAnAccountTask");
|
|
|
|
|
|
|
|
|
|
List<SwapOrderBattery> listSwapOrderBattery = SwapOrderBatteryRepository.QueryListByClause(i =>
|
|
|
|
|
i.DownNominalEnergy >0 &&
|
|
|
|
|
i.UpNominalEnergy >0 &&
|
|
|
|
|
i.UpBatterySoc >0 &&
|
|
|
|
|
i.DownBatterySoc >0 &&
|
|
|
|
|
i.SettleAnAccountFlag == null);
|
|
|
|
|
|
|
|
|
|
if (listSwapOrderBattery.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
List<string?> list = listSwapOrderBattery
|
|
|
|
|
.Where(resp => !string.IsNullOrEmpty(resp.SwapOrderSn))
|
|
|
|
|
.Select(resp => resp.SwapOrderSn)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
List<SwapOrder> swapOrderList = SwapOrderRepository
|
|
|
|
|
.QueryListByClause(swapOrder => list.Contains(swapOrder.Sn));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (swapOrderList.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 电费单价
|
|
|
|
|
decimal electricityTotalFee = StaticStationInfo.ElectricityTotalFee;
|
|
|
|
|
// 换电服务费用
|
|
|
|
|
decimal serviceTotalFee = StaticStationInfo.ServiceTotalFee;
|
|
|
|
|
// 附加费用
|
|
|
|
|
decimal appendTotalFee = StaticStationInfo.AppendTotalFee;
|
|
|
|
|
|
|
|
|
|
List<SwapOrderBattery> updateSwapOrderBatteryList = new List<SwapOrderBattery>();
|
|
|
|
|
List<SwapOrder> updateSwapOrderList = new List<SwapOrder>();
|
|
|
|
|
foreach (var swapOrderBattery in listSwapOrderBattery)
|
|
|
|
|
{
|
|
|
|
|
// 换上的满电包soc*满电包的电池标量
|
|
|
|
|
decimal? upNominalEnergy = swapOrderBattery.UpBatterySoc * swapOrderBattery.UpNominalEnergy;
|
|
|
|
|
// 换下的亏电包soc*亏电包的电池标量
|
|
|
|
|
decimal? downNominalEnergy = swapOrderBattery.DownBatterySoc * swapOrderBattery.DownNominalEnergy;
|
|
|
|
|
|
|
|
|
|
// 电量费用
|
|
|
|
|
decimal? electricCharge = (upNominalEnergy - downNominalEnergy) * electricityTotalFee;
|
|
|
|
|
|
|
|
|
|
if (upNominalEnergy != null && downNominalEnergy != null && electricCharge != null)
|
|
|
|
|
{
|
|
|
|
|
var matchingOrder = swapOrderList.FirstOrDefault(order => order.Sn == swapOrderBattery.SwapOrderSn);
|
|
|
|
|
if (matchingOrder != null)
|
|
|
|
|
{
|
|
|
|
|
matchingOrder.ServiceTotalFee = serviceTotalFee;
|
|
|
|
|
matchingOrder.ElectricityTotalFee = electricCharge;
|
|
|
|
|
matchingOrder.AppendTotalFee = appendTotalFee;
|
|
|
|
|
matchingOrder.TotalFee = matchingOrder.ServiceTotalFee + matchingOrder.ElectricityTotalFee +
|
|
|
|
|
matchingOrder.AppendTotalFee;
|
|
|
|
|
// 标记换电订单已经算了订单价钱
|
|
|
|
|
swapOrderBattery.SettleAnAccountFlag = 1;
|
|
|
|
|
updateSwapOrderBatteryList.Add(swapOrderBattery);
|
|
|
|
|
updateSwapOrderList.Add(matchingOrder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (updateSwapOrderList.Count > 0 && updateSwapOrderBatteryList.Count>0)
|
|
|
|
|
{
|
|
|
|
|
SwapOrderRepository.UpdateIgnoreNullColumns(updateSwapOrderList);
|
|
|
|
|
SwapOrderBatteryRepository.UpdateIgnoreNullColumns(updateSwapOrderBatteryList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Stoped()
|
|
|
|
|
{
|
|
|
|
|
return _stop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
_stop = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetStop()
|
|
|
|
|
{
|
|
|
|
|
_stop = false;
|
|
|
|
|
}
|
|
|
|
|
}
|