/// <summary>
        /// 添加或更新一个架次信息
        /// 架次是实体,用Common库,Collection也可以直接取
        /// </summary>
        /// <param name="flight"></param>
        /// <returns></returns>
        internal FlightDataEntities.Flight AddOrReplaceFlight(
            FlightDataEntities.Flight flight)
        {
            Flight flightResult = null;
            using (AircraftMongoDbDal dal = new AircraftMongoDbDal())
            {
                MongoServer mongoServer = dal.GetMongoServer();
                //不用判断是否为空,必须不能为空才能继续,否则内部要抛异常
                try
                {
                    MongoDatabase database = dal.GetMongoDatabaseCommon(mongoServer);
                    //这是实体,直接取Common吧
                    //dal.GetMongoDatabaseByAircraftModel(mongoServer, flight.Aircraft.AircraftModel);

                    if (database != null)
                    {
                        MongoCollection<Flight> modelCollection
                            = database.GetCollection<Flight>(AircraftMongoDb.COLLECTION_FLIGHT);

                        flightResult = InsertOrUpdateByFlightID(flight, flightResult, modelCollection);
                    }
                }
                catch (Exception e)
                {
                    LogHelper.Error("AddOrReplaceFlight", e);
                    flightResult = null;
                }
            }

            return flightResult;
        }
        internal int GetEarliestYear(AircraftModel model)
        {
            if (model == null || string.IsNullOrEmpty(model.ModelName))
            {
                LogHelper.Warn("aircraftModel为空或aircraftModel.ModelName为空或FlightID为空(GetEarliestYear)。", null);
                return DateTime.Now.Year;
            }

            using (AircraftMongoDbDal dal = new AircraftMongoDbDal())
            {
                MongoServer mongoServer = dal.GetMongoServer();
                //不用判断是否为空,必须不能为空才能继续,否则内部要抛异常
                try
                {//此方法操作的记录为跟架次密切相关,需要拆分存储的记录,最好在DAL里面去处理表名构建逻辑
                    MongoDatabase database = dal.GetMongoDatabaseCommon(mongoServer);
                    if (database != null)
                    {
                        if (database != null)
                        {
                            MongoCollection<Flight> modelCollection
                                = database.GetCollection<Flight>(AircraftMongoDb.COLLECTION_FLIGHT);

                            var queryable = modelCollection.AsQueryable();
                            var result = from one in queryable
                                         where one.Aircraft != null && one.Aircraft.AircraftModel != null
                                         && one.Aircraft.AircraftModel.ModelName == model.ModelName
                                         select Convert.ToInt32(one.FlightDate.Year);

                            if (result != null && result.Count() > 0)
                            {
                                return result.ToArray().Min();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    LogHelper.Error("GetAllAircrafts", e);
                }
            }
            return DateTime.Now.Year;
        }
        internal Flight[] GetAllFlights(AircraftModel model, AircraftInstance instance)
        {
            if (model == null || string.IsNullOrEmpty(model.ModelName))
            {
                LogHelper.Warn("model为空或ModelName为空(GetAllFlights)。", null);
                return null;
            }

            if (instance == null || string.IsNullOrEmpty(instance.AircraftNumber))
                return GetAllFlights(model);

            using (AircraftMongoDbDal dal = new AircraftMongoDbDal())
            {
                MongoServer mongoServer = dal.GetMongoServer();
                //不用判断是否为空,必须不能为空才能继续,否则内部要抛异常
                try
                {
                    MongoDatabase database = dal.GetMongoDatabaseCommon(mongoServer);
                    //这是实体,直接取Common吧
                    //dal.GetMongoDatabaseByAircraftModel(mongoServer, flight.Aircraft.AircraftModel);

                    if (database != null)
                    {
                        MongoCollection<Flight> modelCollection
                            = database.GetCollection<Flight>(AircraftMongoDb.COLLECTION_FLIGHT);

                        var queryable = modelCollection.AsQueryable();
                        var result = from one in queryable
                                     where one.Aircraft != null && one.Aircraft.AircraftModel != null
                                     && one.Aircraft.AircraftModel.ModelName == model.ModelName
                                     && one.Aircraft.AircraftNumber == instance.AircraftNumber //加上机号判断
                                     select one;

                        return result.ToArray();
                    }
                }
                catch (Exception e)
                {
                    LogHelper.Error("GetAllFlights", e);
                }
            }

            return null;
        }