|
|
|
|
using Autofac;
|
|
|
|
|
using Entity.Attr;
|
|
|
|
|
using Entity.Constant;
|
|
|
|
|
using HybirdFrameworkCore.Autofac;
|
|
|
|
|
using HybirdFrameworkCore.Configuration;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Service.Execute.Api;
|
|
|
|
|
using Service.Execute.Model.Tbox;
|
|
|
|
|
using Service.Execute.SwapException;
|
|
|
|
|
using Service.Execute.Utils;
|
|
|
|
|
using Service.Init;
|
|
|
|
|
using Service.Led;
|
|
|
|
|
using Service.Padar.Client;
|
|
|
|
|
using Service.Sound.SoundClient;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
//查询是否有手动操作数据
|
|
|
|
|
if (_CommonMgr.QueryHasManual(machine.SwapOrder.Sn))
|
|
|
|
|
{
|
|
|
|
|
//半自动
|
|
|
|
|
machine.SwapOrder.SwapWay = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
_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;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
////云平台没有匹配的失败状态
|
|
|
|
|
////车辆上锁 ,提示请驶离
|
|
|
|
|
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>
|
|
|
|
|
/// <param name="machine"></param>
|
|
|
|
|
/// <param name="flag"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public InvokeStatus ControlRadar(SwappingStateMachine machine, byte flag)
|
|
|
|
|
{
|
|
|
|
|
return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, () => PadarMgr._PadarClient?.CarState > 0,
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
PadarMgr._PadarClient?.PadarControl(flag);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InvokeStatus AdjustCarByRadar(SwappingStateMachine machine)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled,
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
//更新车辆离场时间
|
|
|
|
|
machine.BusinessSwappingForCloudState =
|
|
|
|
|
InfoEnum.BusinessSwappingForCloudState.SwapDoneWithoutVel;
|
|
|
|
|
machine.SwapOrder!.VehicleLeaveTime = DateTime.Now;
|
|
|
|
|
_CommonMgr.UpdateSwapOrder(machine);
|
|
|
|
|
|
|
|
|
|
//新增小步
|
|
|
|
|
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarOutFlag,
|
|
|
|
|
machine);
|
|
|
|
|
var carState = PadarMgr._PadarClient?.CarState;
|
|
|
|
|
return carState.HasValue && (carState.Value == 1 || carState.Value == 2 || carState.Value == 3 || carState.Value == 4 || carState.Value == 5);
|
|
|
|
|
},
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
switch (PadarMgr._PadarClient?.CarState)
|
|
|
|
|
{
|
|
|
|
|
case 6:
|
|
|
|
|
_log.Info("车辆未驶离");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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?.CarStatus?.LockStatus == 2)
|
|
|
|
|
// {
|
|
|
|
|
// machine.BoxCarInfoModel = carInfo.Result;
|
|
|
|
|
// SoundApi.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
|
|
|
// ? (int)InfoEnum.SwapInfo.InfoCarLeave
|
|
|
|
|
// : (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
|
|
|
|
|
|
|
|
|
|
// LedClient.SendMsgByKey(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
|
|
|
// ? InfoEnum.SwapInfo.InfoCarLeave.GetLed()
|
|
|
|
|
// : InfoEnum.SwapInfo.ErrInfoCarLeave.GetLed());
|
|
|
|
|
// machine.VelLockFlag = true;
|
|
|
|
|
// //断连Tbox
|
|
|
|
|
// if (StaticStationInfo.TboxStateDisConnect)
|
|
|
|
|
// {
|
|
|
|
|
// TBoxApi.DisConnect(machine.BoxCarInfoModel.CarNo);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
|
|
|
|
|
// machine);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }, () =>
|
|
|
|
|
// {
|
|
|
|
|
// // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrLockCar.GetLed());
|
|
|
|
|
// // SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrLockCar);
|
|
|
|
|
// var SoundClient = AppInfo.Container.Resolve<SoundClient>();
|
|
|
|
|
// //SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address19"));
|
|
|
|
|
// SoundClient.SoundPlay(SoundEnum.music59);
|
|
|
|
|
// LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrLockCar.GetLed());
|
|
|
|
|
// }, false, () => { machine.ExceptionReason = ExceptionReason.LockCarError; }
|
|
|
|
|
// , 10, InvokeStatus.None);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 车辆上锁
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public InvokeStatus LockCar(SwappingStateMachine machine)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return Invoker.Invoke("LockCar", 1000, 10, machine.IsCanceled, machine.IsManualSwapSucc,
|
|
|
|
|
() => machine.VelLockFlag, () =>
|
|
|
|
|
{
|
|
|
|
|
Task<bool> result = TBoxApi.LockCarManyTimes(machine.RfidReadModel.VelVin);
|
|
|
|
|
|
|
|
|
|
bool unLock = result.Result;
|
|
|
|
|
if (unLock|| machine.ManualConfirmCarLockFlag)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//查询车辆锁止状态
|
|
|
|
|
Task<TboxCarInfoModel> carInfo = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin);
|
|
|
|
|
if (carInfo.Result?.CarStatus?.LockStatus == 2 || machine.ManualConfirmCarLockFlag)
|
|
|
|
|
{
|
|
|
|
|
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
|
|
|
|
|
machine,param: $"lock: {unLock} ; heartMsg: {JsonConvert.SerializeObject(carInfo.Result)}",type:
|
|
|
|
|
machine.ManualConfirmCarLockFlag? (int)SwapConstant.StepType.MANUAL :
|
|
|
|
|
(int)SwapConstant.StepType.AUTO);
|
|
|
|
|
machine.ManualConfirmCarLockFlag = false;
|
|
|
|
|
//_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
|
|
|
|
|
// machine);
|
|
|
|
|
var SoundClient = AppInfo.Container.Resolve<SoundClient>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoCarLeaveflushed.GetLed());
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
SoundClient.SoundPlay(SoundEnum.music76);
|
|
|
|
|
Thread.Sleep(7000);
|
|
|
|
|
SoundClient.SoundPlay(SoundEnum.music77);
|
|
|
|
|
// SoundClient.SoundPlay(SoundEnum.music77);
|
|
|
|
|
|
|
|
|
|
machine.BoxCarInfoModel = carInfo.Result;
|
|
|
|
|
// SoundApi.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
|
|
|
// ? (int)InfoEnum.SwapInfo.InfoCarLeave
|
|
|
|
|
// : (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
|
|
|
|
|
|
|
|
|
|
//LedClient.SendMsgByKey(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
|
|
|
// ? InfoEnum.SwapInfo.PleaseAway.GetLed()
|
|
|
|
|
// : InfoEnum.SwapInfo.PleaseAway.GetLed());
|
|
|
|
|
machine.VelLockFlag = true;
|
|
|
|
|
|
|
|
|
|
//断连Tbox
|
|
|
|
|
if (StaticStationInfo.TboxStateDisConnect)
|
|
|
|
|
{
|
|
|
|
|
TBoxApi.DisConnect(machine.BoxCarInfoModel?.CarNo);
|
|
|
|
|
}
|
|
|
|
|
//新增小步
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}, () =>
|
|
|
|
|
{
|
|
|
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrLockCar.GetLed());
|
|
|
|
|
// SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrLockCar);
|
|
|
|
|
|
|
|
|
|
//TODO::加锁失败是否需要播报
|
|
|
|
|
// LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrLockCar.GetLed());
|
|
|
|
|
}, false, () => { machine.ExceptionReason = ExceptionReason.LockCarError; }
|
|
|
|
|
, 5, InvokeStatus.None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//public InvokeStatus AdjustCarByRadar(SwappingStateMachine machine)
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
// return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled,
|
|
|
|
|
// () =>
|
|
|
|
|
// {
|
|
|
|
|
// //新增小步
|
|
|
|
|
// _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarOutFlag,
|
|
|
|
|
// machine);
|
|
|
|
|
// var carState = PadarMgr._PadarClient?.CarState;
|
|
|
|
|
// return carState.HasValue && (carState.Value == 1 || carState.Value == 2 || carState.Value == 3 || carState.Value == 4 || carState.Value == 5);
|
|
|
|
|
// },
|
|
|
|
|
// () =>
|
|
|
|
|
// {
|
|
|
|
|
// switch (PadarMgr._PadarClient?.CarState)
|
|
|
|
|
// {
|
|
|
|
|
// case 6:
|
|
|
|
|
// _log.Info("车辆未驶离");
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
public InvokeStatus ExistRadar(SwappingStateMachine machine)
|
|
|
|
|
{
|
|
|
|
|
return Invoker.Invoke("wait exist radar", 1000, 5, machine.IsCanceled, machine.IsManualSwapSucc,
|
|
|
|
|
() => machine.RadarOutFlag, () =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (machine.ManualSkipRadar)
|
|
|
|
|
{
|
|
|
|
|
machine.RadarOutFlag = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (PadarMgr._PadarClient!.CarState == 1)
|
|
|
|
|
{
|
|
|
|
|
machine.RadarOutFlag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( machine.RadarOutFlag)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
machine.ExceptionReason = ExceptionReason.None;
|
|
|
|
|
_log.Info("exist radar true");
|
|
|
|
|
// for (int a = 0; a < 8; a++)
|
|
|
|
|
// {
|
|
|
|
|
LedClient.SendMsgByKey(InfoEnum.SwapInfo.PleaseAwayyin.GetLed());
|
|
|
|
|
// }
|
|
|
|
|
PlcApi.Traffic(1);
|
|
|
|
|
//出口写红灯
|
|
|
|
|
//更新车辆离场时间,上报云平台
|
|
|
|
|
//machine.BusinessSwappingForCloudState =
|
|
|
|
|
// InfoEnum.BusinessSwappingForCloudState.SwapDoneWithoutVel;
|
|
|
|
|
machine.SwapOrder!.VehicleLeaveTime = DateTime.Now;
|
|
|
|
|
_CommonMgr.UpdateSwapOrder(machine);
|
|
|
|
|
|
|
|
|
|
_CommonMgr.InsertStep(
|
|
|
|
|
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
|
|
|
? InfoEnum.BusinessSwappingStep.RadarOutFlag
|
|
|
|
|
: InfoEnum.BusinessSwappingStep.RadarOutFlag,
|
|
|
|
|
machine,type: machine.ManualSkipRadar? (int)SwapConstant.StepType.MANUAL :(int)SwapConstant.StepType.AUTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, () =>
|
|
|
|
|
{
|
|
|
|
|
// LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoCarLeave.GetLed());
|
|
|
|
|
|
|
|
|
|
}, false, () => { }, 10, InvokeStatus.None);
|
|
|
|
|
}
|
|
|
|
|
}
|