Ejemplo n.º 1
0
        public JsonResult GetInterData(OdInfoInput oii)
        {
            var    urls         = "http://192.168.1.111:8080/MuB2TPriceQuery/InterRT";
            string data         = ZhiFlightIntertRTRequestData(oii);
            string responsedata = webRequestPost(urls, data, null).ToString().Trim();
            //Logger.WriteLog("直达航班国际RT往返查询接口响应数据:" + System.DateTime.Now + responsedata);
            OdInfoOutput model = JsonConvert.DeserializeObject <OdInfoOutput>(responsedata);

            return(Json(model));
        }
Ejemplo n.º 2
0
        public override void Execute()
        {
            var urls    = "http://192.168.1.111:8088/MuB2TPriceQuery/InterRT";
            var taxUrls = "http://192.168.1.111:8088/MuB2TPriceQuery/TaxClient";

            List <PriceSearchQuery> querys = null;

            using (ToolDbContext dbContext = new ToolDbContext()) {
                querys = dbContext.PriceSearchQuerys.ToList();
            }
            Parallel.ForEach(querys, (itemQuery) =>
            {
                var flightNos  = itemQuery.FlightNo.Split('/');
                var cabinNames = itemQuery.CabinName.Split('/');

                if (itemQuery.BeginDate.Value < DateTime.Now.AddDays(1))
                {
                    itemQuery.BeginDate = DateTime.Now.AddDays(1);
                }
                foreach (var itemCabinName in cabinNames)
                {
                    for (var date = itemQuery.BeginDate.Value; date < itemQuery.EndDate.Value; date = date.AddDays(1))
                    {
                        B2XTaxYQ taxModel = null;
                        #region 税费查询
                        try
                        {
                            B2XTaxYQ bt = new B2XTaxYQ();
                            bt.pfList   = new List <PsgFare>();
                            bt.pfList.Add(new PsgFare()
                            {
                                psgType = "ADT"
                            });
                            bt.salesCountry  = "CN";
                            bt.salesCurrency = "CNY";
                            bt.segList       = new List <Segment>();
                            bt.segList.Add(new Segment()
                            {
                                clazz = itemCabinName, destcd = itemQuery.ArrivePort, orgcd = itemQuery.DepartPort
                            });
                            bt.ticketingDate    = DateTime.Now.ToString("yyyy-MM-dd");
                            string postdata     = JsonConvert.SerializeObject(bt);
                            string responsedata = webRequestPost(taxUrls, postdata, null).ToString().Trim();
                            var taxResults      = new RtFlightTaxQueryLog()
                            {
                                ArrivePort = itemQuery.ArrivePort,
                                CreateDate = DateTime.Now,
                                //DepartCabinName = "N",
                                DepartCabinName = itemCabinName,
                                DepartPort      = itemQuery.DepartPort,
                                ResponseData    = responsedata,
                                RouteType       = "OW",
                                DepartDate      = date,
                                Status          = 0
                            };
                            taxModel = JsonConvert.DeserializeObject <B2XTaxYQ>(responsedata);

                            using (ToolDbContext context = new ToolDbContext())
                            {
                                context.RtFlightTaxQueryLogs.Add(taxResults);
                                context.SaveChanges();
                            }
                        }
                        catch (Exception ex)
                        {
                            //Logger.WriteLog("税费查询接口请求异常日志" + System.DateTime.Now + ex.Message);
                        }
                        #endregion



                        foreach (var itemFlightNo in flightNos)
                        {
                            #region 价格查询
                            try
                            {
                                OdInfoInput oiiOW   = new OdInfoInput();
                                oiiOW.cabinRank     = "ECONOMY";
                                oiiOW.channelNo     = 220;
                                oiiOW.currency      = "CNY";
                                oiiOW.kamNo         = "";
                                oiiOW.language      = "ZH";
                                oiiOW.paxType       = "";
                                oiiOW.promotionCode = "";
                                oiiOW.queryType     = "all";
                                oiiOW.routeList     = new List <RouteInfo>();
                                oiiOW.routeList.Add(new RouteInfo()
                                {
                                    cabinName = itemCabinName,
                                    //cabinName = "N",
                                    flightNo    = itemFlightNo,
                                    routeDirect = "depart",
                                    routeName   = itemQuery.DepartPort + "/" + itemQuery.ArrivePort,
                                    travelDate  = date.ToString("yyyy-MM-dd")
                                });
                                oiiOW.routeType       = "OW";
                                oiiOW.saleDate        = DateTime.Now.ToString("yyyy-MM-dd");
                                oiiOW.specialFareCode = "";
                                oiiOW.taxesFlag       = false;
                                string postdata       = JsonConvert.SerializeObject(oiiOW);
                                string responsedata   = webRequestPost(urls, postdata, null).ToString().Trim();
                                var priceQueryLog     = new RtInterFlightPriceQueryLog()
                                {
                                    ArrivePort      = itemQuery.ArrivePort,
                                    DepartCabinName = itemCabinName,
                                    DepartDate      = date,
                                    DepartPort      = itemQuery.DepartPort,
                                    FlightNo        = itemFlightNo,
                                    ResponseData    = responsedata,
                                    RouteType       = "OW",
                                    CreateDate      = DateTime.Now,
                                    Status          = 0
                                };
                                OdInfoOutput model = JsonConvert.DeserializeObject <OdInfoOutput>(responsedata);


                                var flightPrice = new ETL0RtFlightPrice()
                                {
                                    ArrivePort = itemQuery.ArrivePort,

                                    CreateDate = DateTime.Now,
                                    DepartPort = itemQuery.DepartPort,
                                    DepartDate = date,
                                    FlightNo   = itemFlightNo,
                                    Status     = 0
                                };
                                if (taxModel != null && taxModel.pfList != null && taxModel.pfList.Any() && taxModel.pfList[0].taxList != null)
                                {
                                    flightPrice.Tax = new Decimal(taxModel.pfList[0].taxList.Sum(a => a.taxAmount ?? 0));
                                }
                                Func <string, decimal> sum = (ls) =>
                                {
                                    var s = ls.Split('/');
                                    return(s.Sum(b => decimal.Parse(b)));
                                };
                                flightPrice.Price     = model.routeCombineList[0].odFareInfoList.Where(a => a.passengerType == "ADT").Min(b => sum(b.price));
                                flightPrice.CabinName = model.routeCombineList[0].odFareInfoList.Where(a => a.passengerType == "ADT").Where(b => sum(b.price) == flightPrice.Price).First().cabinName;
                                using (ToolDbContext context = new ToolDbContext())
                                {
                                    context.RtInterFlightPriceQueryLogs.Add(priceQueryLog);
                                    context.ETL0RtFlightPrices.Add(flightPrice);
                                    context.SaveChanges();
                                }

                                Console.WriteLine(itemFlightNo + "  " + itemCabinName + "  " + date.ToString("yyyy-MM-dd"));
                            }
                            catch (Exception ex)
                            {
                                //throw ex;
                            }
                            #endregion
                        }
                    }
                }
            });
            Console.WriteLine("End");
            Console.Read();
        }