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.
282 lines
11 KiB
282 lines
11 KiB
using Autofac;
|
|
using Entity.Attr;
|
|
using Entity.Constant;
|
|
using HybirdFrameworkCore.Autofac;
|
|
using log4net;
|
|
using Repository.Station;
|
|
using Service.Execute.Api;
|
|
using Service.Execute.Model;
|
|
using Service.Execute.Model.Tbox;
|
|
using Service.Execute.StaticTools;
|
|
using Service.Execute.SwapException;
|
|
using Service.Execute.Utils;
|
|
using Service.Init;
|
|
using Service.MyTask;
|
|
using Service.Station;
|
|
|
|
namespace Service.Execute.Step;
|
|
|
|
public class SwapDoneState : IState
|
|
{
|
|
private readonly CommonMgr _CommonMgr = AppInfo.Container.Resolve<CommonMgr>();
|
|
private readonly ILog _log = LogManager.GetLogger(typeof(SwapDoneState));
|
|
|
|
/// <summary>
|
|
/// 修改换电订单
|
|
/// 查看是否有预约单 更新预约单的状态
|
|
/// </summary>
|
|
/// <param name="machine"></param>
|
|
/// <returns></returns>
|
|
public StateResult Handle(SwappingStateMachine machine)
|
|
{
|
|
//电池安装完成之后
|
|
|
|
//收到放缓存1007或者1008或者9000
|
|
InvokeStatus toInvokeStatus = ToSafePosition(machine);
|
|
if (toInvokeStatus != InvokeStatus.Done)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None);
|
|
}
|
|
|
|
//车辆上锁
|
|
InvokeStatus lockCar = LockCar(machine);
|
|
if (lockCar != InvokeStatus.Done)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(lockCar, ExceptionReason.None);
|
|
}
|
|
|
|
//TBOX收到车辆上电OK信号
|
|
InvokeStatus tBoxEnergyUp = TBoxEnergyUp(machine);
|
|
if (tBoxEnergyUp != InvokeStatus.Done)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(tBoxEnergyUp, ExceptionReason.None);
|
|
}
|
|
|
|
////TBOX收到货箱放下,发换电完成
|
|
//InvokeStatus tBoxDown = TBoxDown(machine);
|
|
//if (tBoxDown != InvokeStatus.Done)
|
|
//{
|
|
// return SwappingStateMachine.ReturnWithInvokeErr(tBoxDown, ExceptionReason.None);
|
|
//}
|
|
|
|
//更新换电订单
|
|
machine.SwapOrder!.SwapResult = machine.SwapStatus;
|
|
machine.SwapOrder.SwapEndTime = DateTime.Now;
|
|
machine.SwapOrder.FailReason = machine.SwapFailReason;
|
|
_CommonMgr.UpdateSwapOrder(machine);
|
|
|
|
|
|
//修改预约单
|
|
if (machine.SwapOrderBatteryInfo!.swapAmtOrder != null)
|
|
{
|
|
machine.SwapOrderBatteryInfo.swapAmtOrder.Status =
|
|
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
? (int)InfoEnum.AmtOrderStatus.SwapFinish
|
|
: (int)InfoEnum.AmtOrderStatus.SwapFail;
|
|
_CommonMgr.UpdateAmtOrder(machine);
|
|
}
|
|
|
|
Task.Run(() =>
|
|
{
|
|
//新增换电成功上报云平台数据
|
|
//_CommonMgr.InsertCloudReportForSwapSuccess(machine);
|
|
//换电成功关于bininfo表的更新
|
|
_CommonMgr.UpdateBinInfoForSwapSuccess(machine);
|
|
|
|
//可人工确认换电成功标识
|
|
machine.PlcSwapFlag = true;
|
|
});
|
|
|
|
|
|
if (machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success)
|
|
{
|
|
//上传云平台换电状态
|
|
machine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.SwapDoneWithVel;
|
|
}
|
|
|
|
//出口雷达监测
|
|
InvokeStatus existRadar = ExistRadar(machine);
|
|
if (existRadar != InvokeStatus.Done)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(existRadar, ExceptionReason.None);
|
|
}
|
|
|
|
|
|
return new StateResult()
|
|
{
|
|
SwappingState = SwappingState.StationReady
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 车辆上锁
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public InvokeStatus LockCar(SwappingStateMachine machine)
|
|
{
|
|
return Invoker.Invoke("LockCar", 500, 10, machine.IsCanceled, machine.IsManualSwapSucc,
|
|
() => machine.VelLockFlag, () =>
|
|
{
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.LockCar);
|
|
Task<bool> result = TBoxApi.LockCarManyTimes(machine.RfidReadModel.VelVin);
|
|
|
|
bool unLock = result.Result;
|
|
//if (unLock)
|
|
{
|
|
//查询车辆锁止状态
|
|
Task<TboxCarInfoModel> carInfo = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin);
|
|
if (carInfo.Result?.HeartBeatMsg?.LockStatus == 2 || machine.ManualConfirmCarLockFlag)
|
|
{
|
|
machine.ManualConfirmCarLockFlag = false;
|
|
machine.BoxCarInfoModel = carInfo.Result;
|
|
machine.VelLockFlag = true;
|
|
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
|
|
machine);
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.LockSuccess);
|
|
}
|
|
}
|
|
}, () =>
|
|
{
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrLockCar);
|
|
}, false, () => { machine.ExceptionReason = ExceptionReason.LockCarError; }
|
|
, 10, InvokeStatus.None);
|
|
}
|
|
|
|
|
|
public InvokeStatus ExistRadar(SwappingStateMachine machine)
|
|
{
|
|
return Invoker.Invoke("wait exist radar", 1000, 5, machine.IsCanceled, machine.IsManualSwapSucc,
|
|
() => machine.RadarOutFlag, () =>
|
|
{
|
|
if (PlcApi.ExitRadar())
|
|
{
|
|
_log.Info("exist radar false");
|
|
}
|
|
else
|
|
{
|
|
machine.ExceptionReason = ExceptionReason.None;
|
|
_log.Info("exist radar true");
|
|
|
|
|
|
if (PlcApi.WriteExistLamp(1020))
|
|
{
|
|
//出口写红灯
|
|
//更新车辆离场时间,上报云平台
|
|
machine.BusinessSwappingForCloudState =
|
|
InfoEnum.BusinessSwappingForCloudState.SwapDoneWithoutVel;
|
|
machine.SwapOrder!.VehicleLeaveTime = DateTime.Now;
|
|
_CommonMgr.UpdateSwapOrder(machine);
|
|
|
|
machine.RadarOutFlag = true;
|
|
TBoxApi.SetHeart("1", 1);
|
|
_CommonMgr.InsertStep(
|
|
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
? InfoEnum.BusinessSwappingStep.RadarOutFlag
|
|
: InfoEnum.BusinessSwappingStep.RadarOutFailFlag,
|
|
machine);
|
|
}
|
|
}
|
|
}, () =>
|
|
{
|
|
SoundApi.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
? (int)InfoEnum.SwapInfo.InfoCarLeave
|
|
: (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
|
|
}, false, () => { }, 10, InvokeStatus.None);
|
|
}
|
|
|
|
///// <summary>
|
|
/////收到货箱放下
|
|
///// </summary>
|
|
///// <returns></returns>
|
|
//public InvokeStatus TBoxDown(SwappingStateMachine machine)
|
|
//{
|
|
// return Invoker.Invoke("TBoxDown", 500, 5, machine.IsCanceled,
|
|
// () => machine.TboxDownFlag, () =>
|
|
// {
|
|
// var carInfo = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin);
|
|
|
|
// var tboxCarInfoModel = carInfo.Result;
|
|
|
|
// //货箱放下
|
|
// if (tboxCarInfoModel?.HeartBeatMsg?.CrateBrimStatus == 1)
|
|
// {
|
|
// TBoxApi.SetHeart(machine.RfidReadModel.VelVin, 4);
|
|
|
|
// machine.TboxDownFlag = true;
|
|
// SoundApi.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
// ? (int)InfoEnum.SwapInfo.InfoCarLeave
|
|
// : (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
|
|
// machine.BoxCarInfoModel = tboxCarInfoModel;
|
|
|
|
// //断连Tbox
|
|
// if (StaticStationInfo.TboxStateDisConnect)
|
|
// {
|
|
// TBoxApi.DisConnect(machine.BoxCarInfoModel.CarNo);
|
|
// }
|
|
// }
|
|
// }, () =>
|
|
// {
|
|
// SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoTboxDown);
|
|
// }, false, () => { }
|
|
// , 10, InvokeStatus.None);
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
///收到上电成功
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public InvokeStatus TBoxEnergyUp(SwappingStateMachine machine)
|
|
{
|
|
return Invoker.Invoke("TBoxEnergyUp", 500, 5, machine.IsCanceled,
|
|
() => machine.TboxEnergyUpFlag, () =>
|
|
{
|
|
var carInfo = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin);
|
|
|
|
var tboxCarInfoModel = carInfo.Result;
|
|
//高压上电改为根据钥匙状态判断
|
|
if (tboxCarInfoModel?.HeartBeatMsg?.KeyStatus == 2)
|
|
{
|
|
//查询车辆锁止状态
|
|
machine.TboxEnergyUpFlag = true;
|
|
// _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.TBoxSwapReadyFlag,
|
|
// machine);
|
|
machine.BoxCarInfoModel = tboxCarInfoModel;
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoTboxDown);
|
|
}
|
|
}, () =>
|
|
{
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoTboxEnergyUp);
|
|
}, false, () => { }
|
|
, 5, InvokeStatus.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 行车回归安全位置
|
|
/// </summary>
|
|
/// <param name="machine"></param>
|
|
/// <returns></returns>
|
|
public InvokeStatus ToSafePosition(SwappingStateMachine machine)
|
|
{
|
|
return Invoker.Invoke("plc ToSavePosition", 500, 5, machine.IsCanceled,
|
|
() => machine.ToSafePositionFlag, () =>
|
|
{
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPackFinish.GetLed());
|
|
|
|
if (PlcApi.ReadPlcTaskStatus() == 1007 || PlcApi.ReadPlcTaskStatus() == 1008|| PlcApi.ReadPlcTaskStatus() == 9000)
|
|
{
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition);
|
|
machine.ToSafePositionFlag = true;
|
|
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
|
|
|
|
machine.SwapStatus = 1;
|
|
|
|
{
|
|
PlcRealTimeTask.CameraTask = false; //结束记录拍照偏移日志
|
|
PlcRealTimeTask.LockStatusTask = false; //结束下发电池包锁状态
|
|
PlcRealTimeTask.VehicleParkingStatusTask = false; //结束下发车辆驻车状态
|
|
}
|
|
}
|
|
}, () => { });
|
|
}
|
|
} |