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.
107 lines
3.9 KiB
107 lines
3.9 KiB
using Autofac;
|
|
using Entity.Attr;
|
|
using Entity.Constant;
|
|
using HybirdFrameworkCore.Autofac;
|
|
using log4net;
|
|
using Repository.Station;
|
|
using Service.Cloud.Client;
|
|
using Service.Cloud.Msg.Cloud.Req;
|
|
using Service.Execute.Api;
|
|
using Service.Execute.StaticTools;
|
|
using Service.Execute.SwapException;
|
|
using Service.Init;
|
|
using Service.Station;
|
|
|
|
namespace Service.Execute.Step;
|
|
|
|
/// <summary>
|
|
/// 云平台下发换电
|
|
/// </summary>
|
|
public class SwapCanStartState : IState
|
|
{
|
|
private readonly ILog _log = LogManager.GetLogger(typeof(SwapCanStartState));
|
|
|
|
private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve<SwapOrderStepService>();
|
|
private readonly SwapOrderRepository _swapOrderRepository = AppInfo.Container.Resolve<SwapOrderRepository>();
|
|
|
|
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>(
|
|
StaticStationInfo.StationModel))
|
|
{
|
|
// CloudApi.UploadCloudReady(machine.plateNumber);
|
|
if (machine.swapStart != null)
|
|
{
|
|
if (machine.swapStart.command == "start")
|
|
{
|
|
_log.Info("SwapCanStart start");
|
|
//更新换电订单
|
|
machine.SwapOrder.CloudSn = machine.swapStart.orderId;
|
|
//machine.SwapOrder.CloudSn = "1764482218541527041";
|
|
machine.CloudCarCanStartFlag = true;
|
|
}
|
|
// 其他非启动换电状态处理
|
|
else if (machine.swapStart.command == "stop"|| machine.swapStart.command == "reset")
|
|
{
|
|
_log.Info("SwapCanStart stop");
|
|
//语音提示云平台取消换电
|
|
StationSoftMgr.SwappingStateMachineCancel();
|
|
machine.CloudCarCanStartFlag = false;
|
|
|
|
}
|
|
else if (machine.swapStart.command == "suspend")
|
|
{
|
|
_log.Info("SwapCanStart suspend");
|
|
machine.CloudCarCanStartFlag = false;
|
|
//语音提示云平台暂停换电
|
|
}
|
|
else if (machine.swapStart.command == "continue")
|
|
{
|
|
_log.Info("SwapCanStart continue");
|
|
machine.CloudCarCanStartFlag = true;
|
|
//语音提示云平台继续换电
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
machine.CloudCarCanStartFlag = true;
|
|
//直接下发换电
|
|
_log.Info("SwapCanStart ok");
|
|
}
|
|
}, () =>
|
|
{
|
|
machine.ExceptionReason = ExceptionReason.CloudSendSwapError;
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.CloudSendSwapError);
|
|
}, false, () => { }
|
|
, 10, InvokeStatus.None);
|
|
}
|
|
} |