public CommandResultViewModel VehicleOilControl(Guid vehicleCode, string tenantCode, string userCode, EnumOilCommandType commandType) { CommandResultViewModel vm = new CommandResultViewModel(); try { IList<EGPSCurrentInfo> ltCurrent = DACFacade.Gps.GPSCurrentDAC.GetCurrentInfoList(new Guid[] { vehicleCode }.ToList()); if (!CheckCommandCondition(ltCurrent, vm, commandType)) return vm; InsertBreakOilHistoryRecord(ltCurrent[0], tenantCode, userCode, commandType); vm.CommandResult = EnumCommandResult.Success; } catch (Exception ex) { Logger.Error(ex.Message, ex); vm.CommandResult = EnumCommandResult.Failed; vm.Msg = ex.Message; } return vm; }
private bool CheckCommandCondition(IList<EGPSCurrentInfo> ltCurrent, CommandResultViewModel vm, EnumOilCommandType commandType) { if (ltCurrent.IsEmpty()) { vm.Msg = "车辆已经离线,无法操作"; vm.CommandResult = EnumCommandResult.MisMatchCondition; return false; } TimeSpan timeSpan = DateTime.Now.Subtract(ltCurrent[0].ReportTime); if (timeSpan.TotalMinutes > Param_OffLineTime) { vm.Msg = "车辆已经离线,无法操作"; vm.CommandResult = EnumCommandResult.MisMatchCondition; return false; } if (commandType == EnumOilCommandType.BreakOil) { if (ltCurrent[0].OilState != 1) //1 表示油电路正常 { vm.Msg = "车辆油电路已经断开"; vm.CommandResult = EnumCommandResult.MisMatchCondition; return false; } if (ltCurrent[0].Speed >= 30) { vm.Msg = "此操作在速度30公里/时才能操作"; vm.CommandResult = EnumCommandResult.MisMatchCondition; return false; } } else if (commandType == EnumOilCommandType.Support) { if (ltCurrent[0].OilState == 1) //1 表示油电路正常 { vm.Msg = "车辆油电路已正常"; vm.CommandResult = EnumCommandResult.MisMatchCondition; return false; } } return true; }