|
|
|
|
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 * 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle()
|
|
|
|
|
{
|
|
|
|
|
Log.Info("Begin SwapOrderSettleAnAccountTask");
|
|
|
|
|
|
|
|
|
|
List<SwapOrderBattery> listSwapOrderBattery = SwapOrderBatteryRepository.QueryListByClause(i =>
|
|
|
|
|
i.DownNominalEnergy >0 && i.UpNominalEnergy >0 && i.SettleAnAccountFlag == 0);
|
|
|
|
|
|
|
|
|
|
if (listSwapOrderBattery.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
List<string?> list = listSwapOrderBattery.Select(resp => resp.SwapOrderSn).ToList();
|
|
|
|
|
|
|
|
|
|
List<SwapOrder> swapOrderList = SwapOrderRepository
|
|
|
|
|
.Queryable()
|
|
|
|
|
.In(swapOrder => swapOrder.Sn, list)
|
|
|
|
|
.ToList();
|
|
|
|
|
// 电费单价
|
|
|
|
|
decimal electricityTotalFee = StaticStationInfo.ElectricityTotalFee;
|
|
|
|
|
// 换电服务费用
|
|
|
|
|
decimal serviceTotalFee = StaticStationInfo.ServiceTotalFee;
|
|
|
|
|
// 附加费用
|
|
|
|
|
decimal appendTotalFee = StaticStationInfo.AppendTotalFee;
|
|
|
|
|
foreach (var swapOrderBattery in listSwapOrderBattery)
|
|
|
|
|
{
|
|
|
|
|
// 换上的满电包soc*满电包的电池标量
|
|
|
|
|
decimal? upNominalEnergy = swapOrderBattery.UpBatterySoc * swapOrderBattery.UpNominalEnergy;
|
|
|
|
|
// 换下的亏电包soc*亏电包的电池标量
|
|
|
|
|
decimal? downNominalEnergy = swapOrderBattery.DownBatterySoc * swapOrderBattery.DownNominalEnergy;
|
|
|
|
|
|
|
|
|
|
// 电量费用
|
|
|
|
|
decimal? electricCharge = (upNominalEnergy - downNominalEnergy) * electricityTotalFee;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SwapOrderRepository.Update(swapOrderList);
|
|
|
|
|
SwapOrderBatteryRepository.Update(listSwapOrderBattery);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Stoped()
|
|
|
|
|
{
|
|
|
|
|
return _stop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
_stop = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetStop()
|
|
|
|
|
{
|
|
|
|
|
_stop = false;
|
|
|
|
|
}
|
|
|
|
|
}
|