Exemplo n.º 1
0
    private AirMerchandise SearchAir(Terms.Sales.Business.AirSearchCondition searchCondition)
    {
        searchCondition.UserInfo = UserInfo;
        //bool isOpenCommNetFareTicket = false;
        bool isOpenAllFareTypeAir = false;
        bool isOnlyShowPubFareTicket = true;
        bool hasMajorAirlinesForAvailable = false;
        bool hasMajorAirlinesForSelect = false;
        bool isAvailableOnly = false;

        if (ConfigurationManager.AppSettings.Get("IsOpenAllFareTypeAir") != null)
            isOpenAllFareTypeAir = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("IsOpenAllFareTypeAir").ToString());

        if (ConfigurationManager.AppSettings.Get("IsOnlyShowPubFareTicket") != null)
            isOnlyShowPubFareTicket = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("IsOnlyShowPubFareTicket").ToString());

        if (ConfigurationManager.AppSettings.Get("HasMajorAirlinesForAvailable") != null)
            hasMajorAirlinesForAvailable = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("HasMajorAirlinesForAvailable").ToString());

        if (ConfigurationManager.AppSettings.Get("HasMajorAirlinesForSelect") != null)
            hasMajorAirlinesForSelect = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("HasMajorAirlinesForSelect").ToString());

        if (ConfigurationManager.AppSettings.Get("IsAvailableOnly") != null)
            isAvailableOnly = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("IsAvailableOnly").ToString());

        //by cjc, ��ʱ��ʾ���еĻ�Ʊ

        searchCondition.IsLogin = Utility.IsLogin;

        //��Cache�в��ҽ��
        AirMerchandise airMerchandise = (AirMerchandise)MVMerchandisePool.Find(searchCondition);

        if (airMerchandise == null)
        {
            DateTime SearchingBeginningTime = DateTime.Now;

            AirProductSearcher searcher = new AirProductSearcher();

            DateTime depDate = searchCondition.GetAddTripCondition()[0].DepartureDate;
            DateTime rtnDate = new DateTime();
            string fromAirportCode = searchCondition.GetAddTripCondition()[0].Departure.Code;
            string toAirportCode = searchCondition.GetAddTripCondition()[0].Destination.Code;
            string rtnFromAirportCode = string.Empty;
            string rtnToAirportCode = string.Empty;
            int adultNumber = searchCondition.GetPassengerNumber(TERMS.Common.PassengerType.Adult);
            int childNumber = searchCondition.GetPassengerNumber(TERMS.Common.PassengerType.Child);
            IList<AirProduct> airs = new List<AirProduct>();
            DateTime dtBeginTime = new DateTime();

            //log begin 20090312 Leon
            try
            {
                dtBeginTime = System.DateTime.Now;
                log.Info(m_LogRandomID + " >Search  From Terms Product Begin Start time : " + dtBeginTime);

                if (searchCondition.FlightType.ToLower().Equals("oneway"))
                    log.Info(m_LogRandomID + " >===================== OneWay =====================");
                else if (searchCondition.FlightType.ToLower().Equals("roundtrip"))
                    log.Info(m_LogRandomID + " >===================== Roundtrip =====================");
                else
                    log.Info(m_LogRandomID + " >===================== OpenJW =====================");
            }
            catch
            { }

            //ת����ѯ����
            TERMS.Common.Search.AirSearchCondition termsSearchCondition;

            if (searchCondition.FlightType.ToLower().Equals("oneway"))
            {
                termsSearchCondition = new TERMS.Common.Search.AirSearchCondition(fromAirportCode, true, toAirportCode, true, depDate, true, adultNumber, childNumber, 0);
            }
            else if (searchCondition.FlightType.ToLower().Equals("roundtrip"))
            {
                rtnDate = searchCondition.GetAddTripCondition()[1].DepartureDate;
                termsSearchCondition = new TERMS.Common.Search.AirSearchCondition(fromAirportCode, true, toAirportCode, true, depDate, true, rtnDate, true, adultNumber, childNumber, 0);
            }
            else  //Open Jaw
            {
                rtnDate = searchCondition.GetAddTripCondition()[1].DepartureDate;
                rtnFromAirportCode = searchCondition.GetAddTripCondition()[1].Departure.Code;
                rtnToAirportCode = searchCondition.GetAddTripCondition()[1].Destination.Code;
                termsSearchCondition = new TERMS.Common.Search.AirSearchCondition(fromAirportCode, true, toAirportCode, true, depDate, true, rtnFromAirportCode, true, rtnToAirportCode, true, rtnDate, true, adultNumber, childNumber, 0);
            }

            //ָ�����չ�˾
            if (searchCondition.Airlines != null && searchCondition.Airlines.Length > 0)
                termsSearchCondition.AddAirlines(searchCondition.Airlines);

            //�ƶ��յ�
            for (int i = 0; i < termsSearchCondition.Trips.Count; i++)
                termsSearchCondition.Trips[i].Cabin = searchCondition.AirTripCondition[i].Cabin;

            //��������ָ����ѯ��ʾ����
            if (!isOpenAllFareTypeAir)
            {
                //if isOpenAllFareTypeAir is false ,  un-login condition come into effect.
                if (!Utility.IsLogin)
                {
                    termsSearchCondition.HasMajorAirlinesForAvailable = hasMajorAirlinesForAvailable;
                    termsSearchCondition.HasMajorAirlinesForSelect = hasMajorAirlinesForSelect;
                    termsSearchCondition.IsAvailableOnly = isAvailableOnly;

                    //if un-login and only show PUB fare
                    if (isOnlyShowPubFareTicket)
                    {
                        termsSearchCondition.HasMajorAirlinesForAvailable = true;
                        termsSearchCondition.HasMajorAirlinesForSelect = true;
                        termsSearchCondition.FareType = TERMS.Common.AirFareType.Published;
                        termsSearchCondition.IsAvailableOnly = true;
                    }
                    else
                    {
                        termsSearchCondition.FareType = TERMS.Common.AirFareType.All;
                    }
                }
                else
                {
                    //��¼����ʾ���л�Ʊ����
                    termsSearchCondition.HasMajorAirlinesForAvailable = true;
                    termsSearchCondition.HasMajorAirlinesForSelect = true;
                    termsSearchCondition.FareType = TERMS.Common.AirFareType.All;
                    termsSearchCondition.IsAvailableOnly = false;
                }
            }
            else
            {
                //��ʾ���л�Ʊ����
                termsSearchCondition.HasMajorAirlinesForAvailable = true;
                termsSearchCondition.HasMajorAirlinesForSelect = true;
                termsSearchCondition.FareType = TERMS.Common.AirFareType.All;
                termsSearchCondition.IsAvailableOnly = false;
            }

            //ִ�в�ѯ
            airs = searcher.Search(termsSearchCondition, UserInfo.Entity);

            log.Info(m_LogRandomID + " >Search From Terms Product End time : " + ((TimeSpan)System.DateTime.Now.Subtract(dtBeginTime)).ToString());
            dtBeginTime = System.DateTime.Now;

            if (airs.Count == 0 || airs[0].Items == null) return null;
            TERMS.Business.Centers.ProductCenter.Profiles.AirProfile oldProfile = (TERMS.Business.Centers.ProductCenter.Profiles.AirProfile)airs[0].Profile;
            oldProfile.SetParam("ADULT_NUMBER", adultNumber);
            oldProfile.SetParam("CHILD_NUMBER", childNumber);
            oldProfile.SetParam("IS_LOGIN", Utility.IsLogin);

            //log begin 20090312 Leon
            try
            {
                log.Info(m_LogRandomID + " >Become Merchandise Begin Begin Start time : " + dtBeginTime);

                if (airMerchandise != null && airMerchandise.Items != null)
                    log.Info(m_LogRandomID + " > " + airs[0].ItemGetter.Log.Text);
                else
                    log.Info(m_LogRandomID + " >No Result");

                log.Info(m_LogRandomID + " >Become Merchandise Begin End time : " + ((TimeSpan)System.DateTime.Now.Subtract(dtBeginTime)).ToString());
            }
            catch
            { }

            airMerchandise = new AirMerchandise(oldProfile, airs[0]);
            MVMerchandisePool.Cache(searchCondition.Clone(), airMerchandise); //Cache

            //��¼Searchʱ��
            DateTime SearchingEndingTime = DateTime.Now;
            SearchingLogger searchingLogger = new SearchingLogger();
            searchingLogger.Log(SearchingBeginningTime, SearchingEndingTime, searchCondition);
        }

        return airMerchandise;
    }