using System; using System.Collections.Generic; using GpsModels; using log4net; using MongoDB.Bson; using MongoDB.Driver; namespace Toogps.Mongo.Repository { public class CarGpsRepository { public static ILog Log = LogManager.GetLogger(""); //插入车辆定位数据,一般用作轨迹查询 public static bool InsertCarGpsList(List models, string tbName) { var carList = new List(); foreach (var gpsModel in models) { if (OutOfChina((double)gpsModel.Latitude, (double)gpsModel.Longitude)) continue; var cargps = new CarGpsModel() { VehicleId = gpsModel.VehicleId, CompanyId = gpsModel.CompanyId, SimNo = gpsModel.SimNo, VehiclePlate = gpsModel.VehiclePlate, VehicleCode = gpsModel.VehicleCode, Longitude = gpsModel.Longitude, Latitude = gpsModel.Latitude, Speed = gpsModel.Speed, Direct = gpsModel.Direct, GpsState = gpsModel.GpsState, GpsTime = gpsModel.GpsTime, RecTime = gpsModel.RecTime, Acc = gpsModel.Acc, Work = gpsModel.Work, Address= gpsModel.Address, //GpsMode = gpsModel.GpsMode }; carList.Add(cargps); } if (carList.Count <= 0) { Log.InfoFormat("InsertCarGpsList并没有插入数据:models数量={0}", models.Count); return false; } return InsertCarGpsList(carList, tbName); } public static bool InsertCarGpsList(List models, string tbName) { try { if (models.Count <= 0) return false; return RepositoryContext.Server.InsertMany(models, tbName); } catch (Exception ex) { return false; } } public static bool InsertCarGps(CarGpsModel model, string tbName) { try { bool flag = RepositoryContext.Server.InsertOne(model, tbName); return flag; } catch (Exception ex) { return false; } } public static bool OutOfChina(double lat, double lon) { if (lon < 72.004 || lon > 137.8347) return true; if (lat < 0.8293 || lat > 55.8271) return true; return false; } } }