예제 #1
0
        private MatchedPolicy QueryPolicies(PolicyType policyType, string flights, string passengers, DataTransferObject.Order.OrderView orderView)
        {
            PassengerType passengerType         = PassengerType.Adult;
            var           policyFilterCondition = new PolicyFilterConditions
            {
                PolicyType = policyType,
                Purchaser  = Company.CompanyId
            };
            IEnumerable <VoyageFilterInfo> voyages = getVoyageFilterInfos(flights, passengers);

            // 特殊票时,只取航班查询处选择的价格
            if (policyType == PolicyType.Special)
            {
                PolicyView policyView   = null;
                var        flightFlight = voyages.FirstOrDefault();
                if (flightFlight != null && flightFlight.Bunk == null)
                {
                    policyFilterCondition.PatPrice = orderView.PATPrice != null ? orderView.PATPrice.Fare : (decimal?)null;
                }
                else if (policyView != null && flightFlight != null && flightFlight.Bunk == null)
                {
                    policyFilterCondition.PublishFare = policyView.PublishFare;
                }
            }
            else
            {
                policyFilterCondition.PatPrice = orderView.PATPrice != null ? orderView.PATPrice.Fare : (decimal?)null;
            }
            policyFilterCondition.Voyages.AddRange(voyages);
            policyFilterCondition.VoyageType      = VoyageType.OneWay;
            policyFilterCondition.SuitReduce      = hasReduce(voyages, orderView.PATPrice != null ? orderView.PATPrice.Fare : (decimal?)null);
            policyFilterCondition.NeedSubsidize   = true;
            policyFilterCondition.IsUsePatPrice   = false;
            policyFilterCondition.AllowTicketType = FilterByTime(voyages.Min(f => f.Flight.TakeOffTime));
            policyFilterCondition.MaxdRebate      = 0;

            IEnumerable <MatchedPolicy> matchedPolicies = PolicyMatchServcie.MatchBunk(policyFilterCondition, false, passengerType, 1).ToList();

            if (!matchedPolicies.Any() || matchedPolicies.FirstOrDefault() == null)
            {
                InterfaceInvokeException.ThrowNotFindPolicyException();
            }
            return(matchedPolicies.FirstOrDefault());
        }
예제 #2
0
파일: PNRImport.cs 프로젝트: 842549829/Pool
        protected override string ExecuteCore()
        {
            var pnrContext = Context.GetParameterValue("pnrContent");
            var patContext = Context.GetParameterValue("patContent");

            ValidateBusinessParameters(HttpUtility.UrlDecode(pnrContext), HttpUtility.UrlDecode(patContext));

            var policyFilterCondition = GetPolicyFilter(_flights);
            //匹配政策
            List <MatchedPolicy> matchedPolicies        = Service.PolicyMatch.PolicyMatchServcie.MatchBunk(policyFilterCondition, false, _pnr.Passengers.First().Type, 10).ToList();
            List <MatchedPolicy> matchedSpeciafPolicies = null;

            if ((_policyType & PolicyType.Special) != PolicyType.Special && (_policyType & PolicyType.Team) != PolicyType.Team)
            {
                policyFilterCondition  = GetPolicyFilter(_flights, PolicyType.Special);
                matchedSpeciafPolicies = Service.PolicyMatch.PolicyMatchServcie.MatchBunk(policyFilterCondition, false, _pnr.Passengers.First().Type, 10).ToList();
                if (!matchedPolicies.Any() && !matchedSpeciafPolicies.Any())
                {
                    InterfaceInvokeException.ThrowNotFindPolicyException();
                }
            }
            if (!matchedPolicies.Any())
            {
                InterfaceInvokeException.ThrowNotFindPolicyException();
            }
            StringBuilder str = new StringBuilder();

            str.Append("<policies>");
            ReturnStringUtility.GetPolicy(matchedPolicies, matchedSpeciafPolicies, str, _policyType, _flights, InterfaceSetting);
            str.Append("</policies>");
            //将匹配出来的政策存入缓存中
            CustomContext context = CustomContext.NewContext();

            context[_pnr.PnrPair.BPNR + _pnr.PnrPair.PNR] = matchedPolicies;
            ContextCenter.Instance.Save(context);
            str.AppendFormat("<batchNo>{0}</batchNo>", context.Id + "0");

            return(str.ToString());
        }
예제 #3
0
        protected void ValidateBusinessParameters(string pnrContent, string patContent)
        {
            if (string.IsNullOrWhiteSpace(pnrContent))
            {
                InterfaceInvokeException.ThrowParameterErrorException("编码");
            }
            if (string.IsNullOrWhiteSpace(patContent))
            {
                InterfaceInvokeException.ThrowParameterErrorException("PAT内容");
            }
            if (string.IsNullOrWhiteSpace(_policyId))
            {
                InterfaceInvokeException.ThrowParameterErrorException("政策编号");
            }
            if (!Guid.TryParse(_policyId, out _Id))
            {
                InterfaceInvokeException.ThrowParameterErrorException("政策编号");
            }
            if (string.IsNullOrWhiteSpace(_orgbatchNo))
            {
                InterfaceInvokeException.ThrowParameterErrorException("导入批次号");
            }
            _batchNo   = _orgbatchNo.Substring(0, _orgbatchNo.Length - 1);
            _isNeedPat = _orgbatchNo.Substring(_orgbatchNo.Length - 1, 1);
            if (_contact.Trim() != "")
            {
                if (_contact.Split('|').Count() < 3)
                {
                    InterfaceInvokeException.ThrowParameterErrorException("联系信息不完整");
                }
                if (_contact.Split('|')[0].Trim() == "")
                {
                    InterfaceInvokeException.ThrowParameterMissException("联系信息中姓名");
                }
                if (_contact.Split('|')[1].Trim() == "")
                {
                    InterfaceInvokeException.ThrowParameterMissException("联系信息中手机");
                }
            }
            if (_associatePNR != "")
            {
                if (!Regex.IsMatch(_associatePNR, "(\\w)+"))
                {
                    InterfaceInvokeException.ThrowParameterErrorException("关联编码");
                }
                if (_associatePNR.Split('|').Any() && _associatePNR.Split('|')[0] != "" && _associatePNR.Split('|')[0].Length != 6)
                {
                    InterfaceInvokeException.ThrowParameterErrorException("关联编码");
                }
                if (_associatePNR.Split('|').Count() == 2 && _associatePNR.Split('|')[1] != "" && _associatePNR.Split('|')[1].Length != 6)
                {
                    InterfaceInvokeException.ThrowParameterErrorException("关联编码");
                }
            }
            try
            {
                var result = CommandService.GetReservedPnr(pnrContent);
                if (result.Success)
                {
                    _pnr = result.Result;
                }
            }
            catch (Exception)
            {
                InterfaceInvokeException.ThrowParameterErrorException("编码内容");
            }
            if (_pnr == null)
            {
                InterfaceInvokeException.ThrowParameterErrorException("编码内容");
            }
            //如果遇到证件号不全体提编码
            if (_pnr.Passengers.Any(p => string.IsNullOrEmpty(p.CertificateNumber)) && !PNRPair.IsNullOrEmpty(_pnr.PnrPair))
            {
                var rtResult = CommandService.GetReservedPnr(_pnr.PnrPair, Guid.Empty);
                if (rtResult.Success && !rtResult.Result.HasCanceled)
                {
                    _pnr = rtResult.Result;
                }
            }
            _flights = ReserveViewConstuctor.GetQueryFlightView(_pnr.Voyage.Segments, _pnr.Voyage.Type, _pnr.Passengers.First().Type, _pnr.IsTeam).ToList();
            if (!_flights.Any())
            {
                InterfaceInvokeException.ThrowCustomMsgException("编码中缺少航班信息");
            }
            var flight = _flights.FirstOrDefault();

            if (flight.BunkType != null && flight.BunkType.Value == BunkType.Free)
            {
                _patPrices = new List <DataTransferObject.Command.PNR.PriceView> {
                    new DataTransferObject.Command.PNR.PriceView {
                        AirportTax = flight.AirportFee, BunkerAdjustmentFactor = flight.BAF, Fare = 0, Total = flight.AirportFee + flight.BAF
                    }
                };
            }
            else
            {
                _patPrices = Service.Command.Domain.Utility.Parser.GetPatPrices(patContent);
                if (_patPrices == null)
                {
                    InterfaceInvokeException.ThrowCustomMsgException("缺少PAT内容");
                }
                if (_patPrices.Count == 0)
                {
                    InterfaceInvokeException.ThrowCustomMsgException("缺少PAT内容");
                }
            }
            if (DataTransferObject.Common.PNRPair.IsNullOrEmpty(_pnr.PnrPair))
            {
                InterfaceInvokeException.ThrowCustomMsgException("内容中缺少编码");
            }
            if (string.IsNullOrWhiteSpace(_pnr.PnrPair.PNR) && string.IsNullOrWhiteSpace(_pnr.PnrPair.BPNR))
            {
                InterfaceInvokeException.ThrowCustomMsgException("编码信息不全");
            }

            //上次导入内容是没有传入pat信息,需要重新匹配政策
            if (_isNeedPat == "1")
            {
                PNRHelper.SaveImportInfo(_pnr, _pnr.PnrPair, _patPrices.MinOrDefaultElement(item => item.Fare), _pnr.Passengers.First().Type, _patPrices.MaxOrDefaultElement(item => item.Fare), out fdSuccess);
                var policyFilterCondition = GetPolicyFilter(_flights);
                //匹配政策
                List <MatchedPolicy> matchedPolicies        = Service.PolicyMatch.PolicyMatchServcie.MatchBunk(policyFilterCondition, false, _pnr.Passengers.First().Type, 10).ToList();
                List <MatchedPolicy> matchedSpeciafPolicies = null;
                if ((_policyType & PolicyType.Special) != PolicyType.Special && (_policyType & PolicyType.Team) != PolicyType.Team)
                {
                    policyFilterCondition  = GetPolicyFilter(_flights, PolicyType.Special);
                    matchedSpeciafPolicies = Service.PolicyMatch.PolicyMatchServcie.MatchBunk(policyFilterCondition, false, _pnr.Passengers.First().Type, 10).ToList();
                    if (!matchedPolicies.Any() && !matchedSpeciafPolicies.Any())
                    {
                        InterfaceInvokeException.ThrowNotFindPolicyException();
                    }
                }
                if (!matchedPolicies.Any())
                {
                    InterfaceInvokeException.ThrowNotFindPolicyException();
                }
                _matchedPolicy = matchedPolicies.FirstOrDefault(item => item.Id == _Id);
                if (_matchedPolicy == null)
                {
                    _matchedPolicy = matchedSpeciafPolicies.FirstOrDefault(item => item.Id == _Id);
                }
                if (_matchedPolicy == null && policyFilterCondition.SuitReduce)
                {
                    InterfaceInvokeException.ThrowCustomMsgException("您选择的政策不支持低打。请重新选择");
                }
                if (_matchedPolicy == null)
                {
                    InterfaceInvokeException.ThrowNotFindPolicyException();
                }
            }
            else
            {
                //从缓存中取出政策
                _customContext = ContextCenter.Instance[_batchNo];
                if (_customContext == null)
                {
                    InterfaceInvokeException.ThrowCustomMsgException("政策选择超时,请重新导入pnr内容");
                }
                var matchedPolicies = _customContext[_pnr.PnrPair.BPNR + _pnr.PnrPair.PNR] as List <MatchedPolicy>;
                if (matchedPolicies == null)
                {
                    InterfaceInvokeException.ThrowCustomMsgException("政策选择超时,请重新导入pnr内容");
                }
                _matchedPolicy = matchedPolicies.FirstOrDefault(item => item.Id == _Id);
                if (_matchedPolicy == null)
                {
                    InterfaceInvokeException.ThrowNotFindPolicyException();
                }
            }
        }