/// <summary> /// Данные по квотам на перелеты /// </summary> /// <param name="query">Параметры запроса</param> /// <returns></returns> public QuotaPriceResult GetFlightQuotaPrices(QuotaPriceQuery query) { QuotaPriceResult flightQuotaPrices; using (var mtsDc = new MtSearchDbDataContext()) { using (var mtmDc = new MtMainDbDataContext()) { flightQuotaPrices = mtsDc.GetFlightQuotaPrices(mtmDc, query); } } return(flightQuotaPrices); }
/// <summary> /// Данные по квотам на перелеты /// </summary> /// <param name="dc">Контекст БД</param> /// <param name="mainDc">Контекст БД</param> /// <param name="query">Параметры запроса</param> /// <returns></returns> public static QuotaPriceResult GetFlightQuotaPrices(this MtSearchDbDataContext dc, MtMainDbDataContext mainDc, QuotaPriceQuery query) { string hash; return(GetFlightQuotaPrices(dc, mainDc, query, out hash)); }
/// <summary> /// Данные по квотам на перелеты /// </summary> /// <param name="dc">Контекст БД</param> /// <param name="mainDc">Контекст БД</param> /// <param name="query">Параметры запроса</param> /// <param name="hash">Строка кэша</param> /// <returns></returns> public static QuotaPriceResult GetFlightQuotaPrices(this MtSearchDbDataContext dc, MtMainDbDataContext mainDc, QuotaPriceQuery query, out string hash) { QuotaPriceResult result; hash = String.Format("{0}_{1}", MethodBase.GetCurrentMethod().Name, query); if ((result = CacheHelper.GetCacheItem <QuotaPriceResult>(hash)) != null) { return(result); } // определяем агента по логину / паролю пользователя int?agentKey = null; if (!string.IsNullOrEmpty(query.UserName)) { var user = mainDc.GetDupUser(query.UserName, query.UserPassword); if (user != null) { agentKey = user.US_PRKEY; } } var cacheDependencies = new List <string>(); result = new QuotaPriceResult(); foreach (var flightPars in query.FlightParams) { string hashOut; var cost = dc.GetFlightPriceByParams(flightPars.FlightParamKeys.CharterKey, flightPars.FlightParamKeys.CharterClassKey, flightPars.FlightParamKeys.PartnerKey, flightPars.FlightParamKeys.PacketKey, flightPars.DepartTime.Date, flightPars.Duration != null ? flightPars.Duration.Value : 1, out hashOut); if (!cacheDependencies.Contains(hashOut)) { cacheDependencies.Add(hashOut); } if (cost != null && cost.Price != null) { var quotaState = dc.CheckServiceQuotaByDay(ServiceClass.Flight, flightPars.FlightParamKeys.CharterKey, flightPars.FlightParamKeys.CharterClassKey, null, flightPars.FlightParamKeys.PartnerKey, agentKey, flightPars.DepartTime.Date, flightPars.Duration != null ? flightPars.Duration.Value : 1, true, out hashOut); if (!cacheDependencies.Contains(hashOut)) { cacheDependencies.Add(hashOut); } result.FlightData.Add(new QuotaPriceData { QuotaState = quotaState.QuotaState, QuotaPlaces = quotaState.Places, PriceValue = cost }); } } CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout); return(result); }
/// <summary> /// Возвращает сопоставления пар перелетов /// </summary> /// <param name="dc">Контекст поисковой БД</param> /// <param name="mainDc">Контекст основной БД</param> /// <param name="packetType">Тип пакета (туда, обратно, туда/обратно)</param> /// <param name="flightVariants">Список перелетов</param> /// <param name="hash">Хэш кэша</param> /// <returns></returns> private static IEnumerable <DatesMatches> GetFlightMatches(this MtSearchDbDataContext dc, MtMainDbDataContext mainDc, PacketType packetType, IList <FlightVariant> flightVariants, out string hash) { List <DatesMatches> result; var hashBuilder = new StringBuilder(); foreach (var flightVaraint in flightVariants) { hashBuilder.AppendFormat("{0}_", flightVaraint); } hash = String.Format("{0}_{1}_{2}", MethodBase.GetCurrentMethod().Name, packetType, hashBuilder); if ((result = CacheHelper.GetCacheItem <List <DatesMatches> >(hash)) != null) { return(result); } result = new List <DatesMatches>(); string hashOut; var cacheDependencies = new List <string>(); if ((PacketType.TwoWayCharters & packetType) == packetType) { var twoWayTickets = (from flightDateTo in flightVariants join flightDateFrom in flightVariants on flightDateTo.CityKeyTo equals flightDateFrom.CityKeyFrom where flightDateTo.CityKeyFrom == Globals.Settings.HomeCityKey && flightDateTo.CityKeyFrom == flightDateFrom.CityKeyTo && flightDateTo.FlightParamKeys.CharterClassKey == flightDateFrom.FlightParamKeys.CharterClassKey && ((flightDateTo.FlightNumber == flightDateFrom.FlightNumber + 1) || (flightDateTo.FlightNumber == flightDateFrom.FlightNumber - 1) || (flightDateTo.FlightNumber == flightDateFrom.FlightNumber && flightDateTo.FlightParamKeys.CharterKey != flightDateFrom.FlightParamKeys.CharterKey)) && ( ((flightDateTo.ArrivalTime - flightDateTo.ArrivalTime.Date) <= (flightDateFrom.DepartTime - flightDateFrom.DepartTime.Date) && flightDateTo.ArrivalTime.Date.AddDays(flightDateTo.DurationMin - 1) <= flightDateFrom.DepartTime.Date && flightDateTo.ArrivalTime.Date.AddDays(flightDateTo.DurationMax - 1) >= flightDateFrom.DepartTime.Date) || ((flightDateTo.ArrivalTime - flightDateTo.ArrivalTime.Date) > (flightDateFrom.DepartTime - flightDateFrom.DepartTime.Date) && flightDateTo.ArrivalTime.Date.AddDays(flightDateTo.DurationMin - 1) <= flightDateFrom.DepartTime.Date.AddDays(-1) && flightDateTo.ArrivalTime.Date.AddDays(flightDateTo.DurationMax - 1) >= flightDateFrom.DepartTime.Date.AddDays(-1)) ) select new Tuple <FlightVariant, FlightVariant>(new FlightVariant(flightDateTo), new FlightVariant(flightDateFrom))) .Distinct(new FlightParamsByDateTupleComparer()) .ToList(); foreach (var pair in twoWayTickets) { var query = new QuotaPriceQuery(); query.FlightParams.Add(new QuotaPriceParams { DepartTime = pair.Item1.DepartTime, Duration = pair.Item2.DepartTime.Date.Subtract(pair.Item1.DepartTime.Date).Days + 1, FlightParamKeys = new FlightVariantKeys { CharterKey = pair.Item1.FlightParamKeys.CharterKey, CharterClassKey = pair.Item1.FlightParamKeys.CharterClassKey, PacketKey = pair.Item1.FlightParamKeys.PacketKey, PartnerKey = pair.Item1.FlightParamKeys.PartnerKey } }); query.FlightParams.Add(new QuotaPriceParams { DepartTime = pair.Item2.DepartTime, Duration = pair.Item2.DepartTime.Date.Subtract(pair.Item1.DepartTime.Date).Days + 1, FlightParamKeys = new FlightVariantKeys { CharterKey = pair.Item2.FlightParamKeys.CharterKey, CharterClassKey = pair.Item2.FlightParamKeys.CharterClassKey, PacketKey = pair.Item2.FlightParamKeys.PacketKey, PartnerKey = pair.Item2.FlightParamKeys.PartnerKey } }); var quotaPrice = dc.GetFlightQuotaPrices(mainDc, query, out hashOut); if (!cacheDependencies.Contains(hashOut)) { cacheDependencies.Add(hashOut); } if (quotaPrice.FlightData.Count > 1) { pair.Item1.FlightQuotaPriceData = new QuotaPriceData { PriceValue = quotaPrice.FlightData[0].PriceValue, QuotaPlaces = quotaPrice.FlightData[0].QuotaPlaces, QuotaState = quotaPrice.FlightData[0].QuotaState }; pair.Item2.FlightQuotaPriceData = new QuotaPriceData { PriceValue = quotaPrice.FlightData[1].PriceValue, QuotaPlaces = quotaPrice.FlightData[1].QuotaPlaces, QuotaState = quotaPrice.FlightData[1].QuotaState }; result.Add(new DatesMatches { FlightParamsTo = pair.Item1, FlightParamsFrom = pair.Item2 }); } } } else if ((PacketType.DirectCharters & packetType) == packetType) { var directTickets = (from flightDateTo in flightVariants where flightDateTo.CityKeyFrom == Globals.Settings.HomeCityKey select flightDateTo) .Distinct(new FlightParamsByDateComparer()) .ToList(); foreach (var flight in directTickets) { var query = new QuotaPriceQuery(); query.FlightParams.Add(new QuotaPriceParams { DepartTime = flight.DepartTime, FlightParamKeys = new FlightVariantKeys { CharterKey = flight.FlightParamKeys.CharterKey, CharterClassKey = flight.FlightParamKeys.CharterClassKey, PacketKey = flight.FlightParamKeys.PacketKey, PartnerKey = flight.FlightParamKeys.PartnerKey } }); var quotaPrice = dc.GetFlightQuotaPrices(mainDc, query, out hashOut); if (!cacheDependencies.Contains(hashOut)) { cacheDependencies.Add(hashOut); } if (quotaPrice.FlightData.Count > 0) { flight.FlightQuotaPriceData = new QuotaPriceData { PriceValue = quotaPrice.FlightData[0].PriceValue, QuotaPlaces = quotaPrice.FlightData[0].QuotaPlaces, QuotaState = quotaPrice.FlightData[0].QuotaState }; result.Add(new DatesMatches { FlightParamsTo = flight, FlightParamsFrom = null }); } } } else if ((PacketType.BackCharters & packetType) == packetType) { var backTickets = (from flightDateTo in flightVariants where flightDateTo.CityKeyTo == Globals.Settings.HomeCityKey select flightDateTo) .Distinct(new FlightParamsByDateComparer()) .ToList(); foreach (var flight in backTickets) { var query = new QuotaPriceQuery(); query.FlightParams.Add(new QuotaPriceParams { DepartTime = flight.DepartTime, FlightParamKeys = new FlightVariantKeys { CharterKey = flight.FlightParamKeys.CharterKey, CharterClassKey = flight.FlightParamKeys.CharterClassKey, PacketKey = flight.FlightParamKeys.PacketKey, PartnerKey = flight.FlightParamKeys.PartnerKey } }); var quotaPrice = dc.GetFlightQuotaPrices(mainDc, query, out hashOut); if (!cacheDependencies.Contains(hashOut)) { cacheDependencies.Add(hashOut); } if (quotaPrice.FlightData.Count > 0) { flight.FlightQuotaPriceData = new QuotaPriceData { PriceValue = quotaPrice.FlightData[0].PriceValue, QuotaPlaces = quotaPrice.FlightData[0].QuotaPlaces, QuotaState = quotaPrice.FlightData[0].QuotaState }; result.Add(new DatesMatches { FlightParamsTo = null, FlightParamsFrom = flight }); } } } CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout); return(result); }