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.
212 lines
7.0 KiB
212 lines
7.0 KiB
6 months ago
|
using Autofac;
|
||
|
using AutoMapper;
|
||
|
using Entity.Constant;
|
||
|
using Entity.DbModel.Station;
|
||
|
using Entity.Dto;
|
||
|
using HybirdFrameworkCore.Autofac;
|
||
|
using HybirdFrameworkCore.Autofac.Attribute;
|
||
|
using Repository.Station;
|
||
|
using Service.Execute.Model;
|
||
|
using Service.Init;
|
||
|
using Service.Station;
|
||
|
|
||
|
namespace Service.Execute.Utils;
|
||
|
|
||
|
[Scope("SingleInstance")]
|
||
|
public class CommonMgr
|
||
|
{
|
||
|
private SwapOrderStepService _swapOrderStepService { get; set; }
|
||
|
private SwapOrderRepository _swapOrderRepository { get; set; }
|
||
|
|
||
|
private BinInfoRepository _binInfoRepository { get; set; }
|
||
|
private SwapAmtOrderRepository _amtOrderRepository { get; set; }
|
||
|
private SwapOrderBatteryRepository _swapOrderBatteryRepository { get; set; }
|
||
|
|
||
|
/// <summary>
|
||
|
/// 新增小步状态
|
||
|
/// </summary>
|
||
|
public void InsertStep(InfoEnum.BusinessSwappingStep step, SwappingStateMachine machine)
|
||
|
{
|
||
|
machine.StepModel.Add(new()
|
||
|
{
|
||
|
StepName = BaseEnumExtensions.GetNameByEnum<InfoEnum.BusinessSwappingStep>(step),
|
||
|
StepNo = (int)step,
|
||
|
StartTime = DateTime.Now
|
||
|
});
|
||
|
_swapOrderStepService.InsertSwapStepForSwapMain(step,
|
||
|
machine.StepSort++, machine.SwapOrder.Sn);
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 新增换电订单
|
||
|
/// </summary>
|
||
|
/// <param name="swapOrder"></param>
|
||
|
/// <returns></returns>
|
||
|
public SwapOrder SaveOrder(SwapOrder swapOrder)
|
||
|
{
|
||
|
_swapOrderRepository.Insert(swapOrder);
|
||
|
return swapOrder;
|
||
|
}
|
||
|
|
||
|
|
||
|
public void SaveSwapBattery(SwappingStateMachine machine)
|
||
|
{
|
||
|
BinInfo UpBin = machine.SwapOrderBatteryInfo.UpBinInfo;
|
||
|
BinInfo InBin = machine.SwapOrderBatteryInfo.InBinInfo;
|
||
|
SwapOrderBattery swapOrderBattery = new SwapOrderBattery()
|
||
|
{
|
||
|
SwapOrderSn = machine.SwapOrder.Sn,
|
||
|
UpBatterySoc = UpBin.Soc,
|
||
|
UpBatteryNo = UpBin.BatteryNo,
|
||
|
UpBatterySoe = UpBin.Soe,
|
||
|
UpBatteryBinNo = int.Parse(UpBin.No),
|
||
|
DownBatteryBinNo = int.Parse(InBin.No),
|
||
|
};
|
||
|
_swapOrderBatteryRepository.Insert(swapOrderBattery);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 1.锁仓
|
||
|
/// 2.更改预约单
|
||
|
/// </summary>
|
||
|
public void LockBinAndUpdateAmt(SwapOrderBatteryInfo orderBatteryInfo)
|
||
|
{
|
||
|
var configBinInfo =
|
||
|
new MapperConfiguration(cfg => cfg.CreateMap<BinInfo, BinInfo>().ReverseMap());
|
||
|
IMapper mapperBinInfo = configBinInfo.CreateMapper();
|
||
|
BinInfo dbBinInfo = mapperBinInfo.Map<BinInfo>(orderBatteryInfo.UpBinInfo);
|
||
|
|
||
|
dbBinInfo.AmtLock = (int)InfoEnum.AmtBatLockStatus.Lock;
|
||
|
_binInfoRepository.Update(dbBinInfo);
|
||
|
if (!orderBatteryInfo.isAmt)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var configAmt =
|
||
|
new MapperConfiguration(cfg => cfg.CreateMap<SwapAmtOrder, SwapAmtOrder>().ReverseMap());
|
||
|
IMapper mapperAmt = configAmt.CreateMapper();
|
||
|
SwapAmtOrder swapAmtOrder = mapperAmt.Map<SwapAmtOrder>(orderBatteryInfo.swapAmtOrder);
|
||
|
swapAmtOrder.Status = (int)InfoEnum.AmtOrderStatus.Swapping;
|
||
|
_amtOrderRepository.Update(swapAmtOrder);
|
||
|
}
|
||
|
|
||
|
/// 1.仓位状态:启动
|
||
|
/// 2.电池在位
|
||
|
/// 3.充电状态:不在充电中
|
||
|
/// 4.未锁定
|
||
|
/// 5.最后一次结束充电时间> ()
|
||
|
/// 6.soc >()
|
||
|
/**
|
||
|
* && i.ChargeStatus == 2
|
||
|
&& i.AmtLock == "0"
|
||
|
&& new TimeSpan(DateTime.Now.Ticks -
|
||
|
i.LastChargeFinishTime.ToDateTime().Ticks)
|
||
|
.TotalMinutes > StaticStationInfo.SwapFinishChargeTime
|
||
|
&& i.Soc > StaticStationInfo.Soc
|
||
|
*/
|
||
|
public SwapOrderBatteryInfo SelectPackNotArm()
|
||
|
{
|
||
|
SwapOrderBatteryInfo orderBatteryInfo = new SwapOrderBatteryInfo();
|
||
|
UpBin(orderBatteryInfo);
|
||
|
if (orderBatteryInfo.CanSwap != InfoEnum.SelectBinStatusInfo.Success)
|
||
|
{
|
||
|
return orderBatteryInfo;
|
||
|
}
|
||
|
|
||
|
InBin(orderBatteryInfo);
|
||
|
|
||
|
return orderBatteryInfo;
|
||
|
}
|
||
|
|
||
|
public SwapOrderBatteryInfo SelectPackArm(SwapAmtOrder swapAmtOrder)
|
||
|
{
|
||
|
SwapOrderBatteryInfo orderBatteryInfo = new SwapOrderBatteryInfo();
|
||
|
orderBatteryInfo.swapAmtOrder = swapAmtOrder;
|
||
|
orderBatteryInfo.isAmt = true;
|
||
|
BinInfo UpBin = _binInfoRepository.QueryByClause(i => i.No.Equals(swapAmtOrder.AmtBinNoList));
|
||
|
bool CanSwap = UpBin.Exists == 1 && UpBin.Status == 1 && UpBin.ChargeStatus == 2
|
||
|
&& UpBin.AmtLock == (int)InfoEnum.AmtBatLockStatus.Lock && new TimeSpan(DateTime.Now.Ticks -
|
||
|
UpBin.LastChargeFinishTime.ToDateTime()
|
||
|
.Ticks)
|
||
|
.TotalMinutes > int.Parse(StaticStationInfo.SwapFinishChargeTime) &&
|
||
|
UpBin.Soc > int.Parse(StaticStationInfo.SwapSoc);
|
||
|
if (!CanSwap)
|
||
|
{
|
||
|
orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.AmtError;
|
||
|
|
||
|
return orderBatteryInfo;
|
||
|
}
|
||
|
|
||
|
orderBatteryInfo.UpBinInfo = UpBin;
|
||
|
InBin(orderBatteryInfo);
|
||
|
return orderBatteryInfo;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 取电池判断
|
||
|
/// </summary>
|
||
|
/// <param name="orderBatteryInfo"></param>
|
||
|
public void UpBin(SwapOrderBatteryInfo orderBatteryInfo)
|
||
|
{
|
||
|
SelectPackDto selectPack =
|
||
|
_binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime);
|
||
|
|
||
|
orderBatteryInfo.UpBinInfo = selectPack.BinInfo;
|
||
|
orderBatteryInfo.CanSwap = selectPack.Info;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 放电池判断:取出来的电池仓位能不能放
|
||
|
/// </summary>
|
||
|
/// <param name="orderBatteryInfo"></param>
|
||
|
public void InBin(SwapOrderBatteryInfo orderBatteryInfo)
|
||
|
{
|
||
|
List<BinInfo> list =
|
||
|
_binInfoRepository.QueryListByClause(i =>
|
||
|
i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock
|
||
|
&& i.Exists == 0);
|
||
|
if (list.Count <= 0)
|
||
|
{
|
||
|
orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOfEmptyBin;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
orderBatteryInfo.InBinInfo = list[0];
|
||
|
orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.Success;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 查询预约单
|
||
|
/// </summary>
|
||
|
/// <param name="machine"></param>
|
||
|
/// <returns></returns>
|
||
|
public SwapAmtOrder? QueryAmtOrder(SwappingStateMachine machine)
|
||
|
{
|
||
|
return
|
||
|
_amtOrderRepository.QueryByClause(i =>
|
||
|
i.Status == (int)InfoEnum.AmtOrderStatus.Success && i.CarNo.Equals(machine.BoxCarInfoModel.CarNo));
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 更新订单
|
||
|
/// </summary>
|
||
|
/// <param name="machine"></param>
|
||
|
public void UpdateSwapOrder(SwappingStateMachine machine)
|
||
|
{
|
||
|
_swapOrderRepository.Update(machine.SwapOrder);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 更新预约订单
|
||
|
/// </summary>
|
||
|
/// <param name="machine"></param>
|
||
|
public void UpdateAmtOrder(SwappingStateMachine machine)
|
||
|
{
|
||
|
_amtOrderRepository.Update(machine.SwapOrderBatteryInfo.swapAmtOrder);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|