//插入命令历史记录 private void InsertBreakOilHistoryRecord(EGPSCurrentInfo info, string tenantCode, string userCode, EnumOilCommandType commandType) { #region create entity EBreakOilHistoryRecord history = new EBreakOilHistoryRecord(); history.ACC = info.ACCState; history.AntennaState = info.AntennaState; history.CommandType = (int)commandType; history.GPSCode = info.GPSCode; history.IsBreakOil = commandType == EnumOilCommandType.BreakOil ? true : false; history.Latitude = info.Latitude; history.Longitude = info.Longitude; history.OilState = info.OilState; history.RecordID = Guid.NewGuid(); history.SerialNumber = Guid.NewGuid(); history.SetTime = DateTime.Now; history.Speed = info.Speed; history.TenantCode = tenantCode; history.UserCode = userCode; history.VehicleCode = info.VehicleCode; #endregion BreakOilHistoryManager breakOilHistoryMgr = new BreakOilHistoryManager(); breakOilHistoryMgr.Add(history); BreakOilLastRecordManager breakOilLastRecordMgr = new BreakOilLastRecordManager(); EBreakOilLastRecord lastRecord = breakOilLastRecordMgr.Exists(history.VehicleCode); if (lastRecord == null) { lastRecord = new EBreakOilLastRecord(); lastRecord.VehicleCode = history.VehicleCode; lastRecord.BreakOilHistoryRecord = history; breakOilLastRecordMgr.Add(lastRecord); } else { lastRecord.BreakOilHistoryRecord = history; breakOilLastRecordMgr.Update(lastRecord); } breakOilLastRecordMgr.VehicleControl(info.GPSCode, commandType, history.SerialNumber); }
/// <summary> /// 发送断油断电或供油供电指令 /// </summary> /// <param name="vehicleCode">车辆编号</param> /// <param name="commandType">2:断油断电,100:供油供电</param> /// <returns></returns> public AndroidData<object> SendCommand(string vehicleCode, int commandType, string tenantCode, string userCode) { AndroidData<object> data = new AndroidData<object>(); IBreakOilLastRecordManager db = new BreakOilLastRecordManager(); IBreakOilHistoryManager db2 = new MobileQueryBreakOilHistoryManager(); IPositionService gpsTrackManager = new PositionService(); try { //如果是断油断电,则判断车辆是否熄火5分钟以上,如果不是则不能发送指令。 if (commandType == 2) { bool accOff = db.IsAccOff(new Guid(vehicleCode)); if (!accOff) { data.Message = "车辆需要熄火5分钟以上才能发送断油断电"; data.ResultCode = ResultCodeEnum.Fail; return data; } } EBreakOilLastRecord record = db.Exists(new Guid(vehicleCode)); EGPSCurrentInfo info = gpsTrackManager.GetCurrentInfoFromDB(new Guid(vehicleCode)); EBreakOilHistoryRecord history = new EBreakOilHistoryRecord(); TimeSpan timeSpan = DateTime.Now.Subtract(info.ReportTime); if (null == info || timeSpan.TotalMinutes > 10) { data.Message = "车辆没有在线"; data.ResultCode = ResultCodeEnum.Fail; return data; } else { history.ACC = info.ACCState; history.AntennaState = info.AntennaState; history.Area = info.Area; history.CommandType = commandType; history.GPSCode = info.GPSCode; history.IsBreakOil = commandType == 2 ? true : false; history.LandMark = info.LandMark; history.Latitude = Convert.ToDecimal(info.Latitude); history.Longitude = Convert.ToDecimal(info.Longitude); history.Oil = Convert.ToDecimal(info.OilBearing); history.OilState = info.OilState; history.RecordID = Guid.NewGuid(); history.Road = info.Road; history.SerialNumber = Guid.NewGuid(); history.SetTime = DateTime.Now; history.Speed = Convert.ToDecimal(info.Speed); history.StarkMileage = Convert.ToDecimal(info.StarkMileage); history.TenantCode = tenantCode; history.UserCode = userCode; history.VehicleCode = new Guid(vehicleCode); } if (null != record) { db2.Add(history); record.BreakOilHistoryRecord = history; db.Update(record); } else { db2.Add(history); record = new EBreakOilLastRecord(); record.VehicleCode = new Guid(vehicleCode); record.BreakOilHistoryRecord = history; db.Add(record); } //发送指令待完善 db.VehicleControl(vehicleCode, commandType, history.SerialNumber); data.ResultCode = ResultCodeEnum.Success; return data; } catch (Exception ex) { data.Message = ex.Message; data.ResultCode = ResultCodeEnum.Fail; return data; } }