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.

104 lines
4.2 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))
{
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;
_swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudCarCanStartFlag,
machine.StepSort++, machine.SwapOrder.Sn);
}
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);
}
}