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.
98 lines
3.7 KiB
98 lines
3.7 KiB
using Entity.Constant;
|
|
using log4net;
|
|
using Repository.Station;
|
|
using Service.Cloud.Client;
|
|
using Service.Cloud.Msg.Cloud.Req;
|
|
using Service.Execute.Api;
|
|
using Service.Execute.Enum;
|
|
using Service.Execute.StaticTools;
|
|
using Service.Execute.SwapException;
|
|
using Service.Init;
|
|
using Swapping.Business.Tech;
|
|
|
|
namespace Service.Execute.Step;
|
|
|
|
/// <summary>
|
|
/// 云平台下发换电
|
|
/// </summary>
|
|
public class SwapCanStartState : IState
|
|
{
|
|
private readonly ILog _log = LogManager.GetLogger(typeof(SwapCanStartState));
|
|
|
|
private SwapOrderRepository SwapOrderRepository { get; set; }
|
|
|
|
public StateResult Handle(SwappingStateMachine machine)
|
|
{
|
|
InvokeStatus swapCanStart = SwapCanStart(machine);
|
|
|
|
if (InvokeStatus.Done != swapCanStart)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(swapCanStart, ExceptionReason.None);
|
|
}
|
|
|
|
return new StateResult()
|
|
{
|
|
SwappingState = SwappingState.CarCtrl
|
|
};
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 等待云平台下发换电
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public InvokeStatus SwapCanStart(SwappingStateMachine machine)
|
|
{
|
|
return Invoker.Invoke("check swapCanStart", 1000, 50, machine.IsCanceled,
|
|
() => machine.CloudCarCanStartFlag, () =>
|
|
{
|
|
//远程模式
|
|
if (StationConstant.StationModel.Remote ==
|
|
BaseEnumExtensions.GetEnumByCode<StationConstant.StationModel>(
|
|
int.Parse(StaticStationInfo.StationModel)))
|
|
{
|
|
CarCanStart carCanStart = CloudApi.CarCanStart();
|
|
if (carCanStart != null)
|
|
{
|
|
//车牌号
|
|
if (carCanStart.cn.Equals(machine.BoxCarInfoModel.CarNo))
|
|
{
|
|
//可以开始换电
|
|
if (carCanStart.cs == 1)
|
|
{
|
|
_log.Info("SwapCanStart ok");
|
|
//更新换电订单
|
|
machine.SwapOrder.CloudSn = carCanStart.on;
|
|
SwapOrderRepository.Update(machine.SwapOrder.CloudSn);
|
|
machine.CloudCarCanStartFlag = true;
|
|
}
|
|
else
|
|
{
|
|
_log.Info("SwapCanStart cancel");
|
|
//语音提示云平台取消换电
|
|
machine.CloudCarCanStartFlag = false;
|
|
machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.CloudSendSwapCancel.GetLed());
|
|
SoundTool.PlayOneSound((int)InfoEnum.SwapInfo.CloudSendSwapError);
|
|
machine.BusinessSwappingForCloudState =
|
|
InfoEnum.BusinessSwappingForCloudState.SwapReady;
|
|
CloudApi.SendStateLog(machine.SwapOrder,
|
|
machine.BusinessSwappingForCloudState);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
machine.CloudCarCanStartFlag = true;
|
|
//直接下发换电
|
|
_log.Info("SwapCanStart ok");
|
|
}
|
|
}, () =>
|
|
{
|
|
machine.ExceptionReason = ExceptionReason.CloudSendSwapError;
|
|
machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.CloudSendSwapError.GetLed());
|
|
SoundTool.PlayOneSound((int)InfoEnum.SwapInfo.CloudSendSwapError);
|
|
}, false, () => { }
|
|
, 10, InvokeStatus.None);
|
|
}
|
|
} |