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; /// /// 云平台下发换电 /// 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 }; } /// /// 等待云平台下发换电 /// /// public InvokeStatus SwapCanStart(SwappingStateMachine machine) { return Invoker.Invoke("check swapCanStart", 1000, 50, machine.IsCanceled, () => SwappingStateMachine.CloudCarCanStartFlag, () => { //远程模式 if (StationConstant.StationModel.Remote == BaseEnumExtensions.GetEnumByCode( int.Parse(StaticStationInfo.StationModel))) { CarCanStart carCanStart = CloudApi.CarCanStart(); if (carCanStart != null) { //车牌号 if (carCanStart.cn.Equals(machine.TBoxCarInfoModel.CarNo)) { //可以开始换电 if (carCanStart.cs == 1) { _log.Info("SwapCanStart ok"); //更新换电订单 machine.SwapOrder.CloudSn = carCanStart.on; SwapOrderRepository.Update(machine.SwapOrder.CloudSn); SwappingStateMachine.CloudCarCanStartFlag = true; } else { _log.Info("SwapCanStart cancel"); //语音提示云平台取消换电 SwappingStateMachine.CloudCarCanStartFlag = false; machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.CloudSendSwapCancel.GetLed()); SoundTool.PlayOneSound((int)InfoEnum.SwapInfo.CloudSendSwapError); SwappingStateMachine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.SwapReady; CloudApi.SendStateLog(machine.SwapOrder, SwappingStateMachine.BusinessSwappingForCloudState); } } } } else { SwappingStateMachine.CloudCarCanStartFlag = true; //直接下发换电 _log.Info("SwapCanStart ok"); } }, () => { SwappingStateMachine.ExceptionReason = ExceptionReason.CloudSendSwapError; machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.CloudSendSwapError.GetLed()); SoundTool.PlayOneSound((int)InfoEnum.SwapInfo.CloudSendSwapError); }, false, () => { } , 10, InvokeStatus.None); } }