|
|
|
|
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.StaticTools;
|
|
|
|
|
using Service.Execute.SwapException;
|
|
|
|
|
using Service.Execute.Utils;
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
//更新换电订单
|
|
|
|
|
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;
|
|
|
|
|
// CloudApi.SendStateLog(machine.SwapOrder, machine.BusinessSwappingForCloudState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//云平台没有匹配的失败状态
|
|
|
|
|
//车辆上锁 ,提示请驶离
|
|
|
|
|
InvokeStatus lockCar = LockCar(machine);
|
|
|
|
|
|
|
|
|
|
if (lockCar != InvokeStatus.Done)
|
|
|
|
|
{
|
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(lockCar, ExceptionReason.None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//出口雷达监测
|
|
|
|
|
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, 100, machine.IsCanceled, machine.IsManualSwapSucc,
|
|
|
|
|
() => machine.VelLockFlag, () =>
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
//设置出口的是绿灯
|
|
|
|
|
if (PlcApi.WriteExistLamp(1000))
|
|
|
|
|
{
|
|
|
|
|
/*machine.LedTool?.WriteProgramContent(
|
|
|
|
|
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
|
|
|
? InfoEnum.SwapInfo.InfoCarLeave.GetLed()
|
|
|
|
|
: InfoEnum.SwapInfo.ErrInfoCarLeave.GetLed());*/
|
|
|
|
|
SoundTool.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
|
|
|
? (int)InfoEnum.SwapInfo.InfoCarLeave
|
|
|
|
|
: (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
|
|
|
|
|
machine.VelLockFlag = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
|
|
|
|
|
machine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, () =>
|
|
|
|
|
{
|
|
|
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrLockCar.GetLed());
|
|
|
|
|
SoundTool.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;
|
|
|
|
|
|
|
|
|
|
_CommonMgr.InsertStep(
|
|
|
|
|
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
|
|
|
? InfoEnum.BusinessSwappingStep.RadarOutFlag
|
|
|
|
|
: InfoEnum.BusinessSwappingStep.RadarOutFailFlag,
|
|
|
|
|
machine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, () =>
|
|
|
|
|
{
|
|
|
|
|
SoundTool.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
|
|
|
? (int)InfoEnum.SwapInfo.InfoCarLeave
|
|
|
|
|
: (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
|
|
|
|
|
}, false, () => { }, 10, InvokeStatus.None);
|
|
|
|
|
}
|
|
|
|
|
}
|