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.

131 lines
4.5 KiB

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()
{
1 month ago
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));
1 month ago
if (swapOrderList.Count <= 0)
{
return;
}
// 电费单价
decimal electricityTotalFee = StaticStationInfo.ElectricityTotalFee;
// 换电服务费用
decimal serviceTotalFee = StaticStationInfo.ServiceTotalFee;
// 附加费用
decimal appendTotalFee = StaticStationInfo.AppendTotalFee;
1 month ago
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;
1 month ago
if (upNominalEnergy != null && downNominalEnergy != null && electricCharge != null)
{
1 month ago
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;
1 month ago
updateSwapOrderBatteryList.Add(swapOrderBattery);
updateSwapOrderList.Add(matchingOrder);
1 month ago
}
}
}
1 month ago
if (updateSwapOrderList.Count > 0 && updateSwapOrderBatteryList.Count>0)
1 month ago
{
SwapOrderRepository.UpdateIgnoreNullColumns(updateSwapOrderList);
SwapOrderBatteryRepository.UpdateIgnoreNullColumns(updateSwapOrderBatteryList);
1 month ago
}
}
}
public bool Stoped()
{
return _stop;
}
public void Stop()
{
_stop = true;
}
public void ResetStop()
{
_stop = false;
}
}