/// <summary> /// 默认政策数据 /// </summary> /// <param name="seat"></param> /// <returns></returns> public IbeSeat SetDefaultData(IbeSeat seat) { try { seat.PolicyId = Guid.NewGuid().ToString(); seat.Policy = DefaultPolicy; seat.ReturnMoney = DefaultReturnMoney; seat.PlatformCode = "默认"; seat.PolicyRMK = string.Empty; } catch (Exception ex) { //记录日志 log.WriteLog("SetDefaultData", "异常信息:" + ex.Message + "\r\n"); } return(seat); }
/// <summary> /// 获取航班数据 /// </summary> /// <param name="avhList"></param> /// <param name="PolicyList"></param> /// <returns></returns> public List <AVHData> MatchPolicy(string code, List <AVHData> avhList, TravelType travelType, List <PolicyCache> PolicyList) { DataBill dataBill = new DataBill(); try { //PolicyList = PolicyList.Where(p => p.PlatformCode == "系统").ToList(); if (avhList != null && PolicyList != null && avhList.Count > 0 && PolicyList.Count > 0) { //周六至周日 DayOfWeek[] WeekendTimes = new DayOfWeek[] { DayOfWeek.Saturday, DayOfWeek.Sunday }; //调整缓存政策 PolicyList = PolicyCacheSetting(PolicyList); PolicyList = DeductionSetting(code, avhList, PolicyList); List <string> codeList = ObjectFactory.GetAllInstances <IPlatform>().Select(p => p.Code).ToList(); for (int i = 0; i < avhList.Count; i++) { AVHData avhData = avhList[i]; DateTime flyDate = DateTime.Parse(avhData.QueryParam.FlyDate); //循环IBE数据 for (int j = 0; j < avhData.IbeData.Count; j++) { //排除没有舱位的 if (avhData.IbeData[j].IBESeat == null || avhData.IbeData[j].IBESeat.Count() == 0) { continue; } //循环舱位 每个舱位可能对应多条政策 取最优的一条 List <IbeSeat> addRowList = new List <IbeSeat>(); for (int k = 0; k < avhData.IbeData[j].IBESeat.Count; k++) { avhData.IbeData[j].IBESeat[k].IbeSeatPrice = avhData.IbeData[j].IBESeat[k].SeatPrice; if (avhData.DicYSeatPrice != null && avhData.DicYSeatPrice.ContainsKey(avhData.IbeData[j].CarrierCode) ) { if (avhData.IbeData[j].IBESeat[k].SeatPrice > 0) { avhData.IbeData[j].IBESeat[k].Commission = dataBill.GetCommission(avhData.IbeData[j].IBESeat[k].Policy, avhData.IbeData[j].IBESeat[k].SeatPrice, avhData.IbeData[j].IBESeat[k].ReturnMoney); } } else { //没有Y舱直接过滤 continue; } //每个舱位可能对应多条政策 政策过滤 var result = PolicyList.Where(p => Filter(p, codeList, avhList, avhData, travelType, flyDate, WeekendTimes, j, k)).ToList(); #region 特价舱位匹配政策 //if (avhList.Count == 1)//暂时只适用单程 if (true) { //特价舱位 不通的特价类型的多条政策 List <PolicyCache> spPolicyList = result.Where(p => p.PolicySpecialType != EnumPolicySpecialType.Normal).OrderByDescending(p => p.Point).ToList();//.FirstOrDefault(); if (spPolicyList != null && spPolicyList.Count > 0) { //获取4种类型政策最优的特价 List <PolicyCache> spList = new List <PolicyCache>(); PolicyCache spDynamicSpecial = spPolicyList.Where(p => p.PolicySpecialType == EnumPolicySpecialType.DynamicSpecial).OrderByDescending(p => p.Point).FirstOrDefault(); if (spDynamicSpecial != null) { spList.Add(spDynamicSpecial); } PolicyCache spFixedSpecial = spPolicyList.Where(p => p.PolicySpecialType == EnumPolicySpecialType.FixedSpecial).OrderByDescending(p => p.Point).FirstOrDefault(); if (spFixedSpecial != null) { spList.Add(spFixedSpecial); } PolicyCache spDownSpecial = spPolicyList.Where(p => p.PolicySpecialType == EnumPolicySpecialType.DownSpecial).OrderByDescending(p => p.Point).FirstOrDefault(); if (spDownSpecial != null) { spList.Add(spDownSpecial); } PolicyCache spDiscountOnDiscount = spPolicyList.Where(p => p.PolicySpecialType == EnumPolicySpecialType.DiscountOnDiscount).OrderByDescending(p => p.Point).FirstOrDefault(); if (spDiscountOnDiscount != null) { spList.Add(spDiscountOnDiscount); } //循环克隆一份舱位 spList.ForEach(spPolicy => { IbeSeat ibeSeat = avhData.IbeData[j].IBESeat[k].Clone() as IbeSeat; if (ibeSeat != null) { ibeSeat.Policy = spPolicy.Point; ibeSeat.PolicySpecialType = spPolicy.PolicySpecialType; ibeSeat.SpecialPriceOrDiscount = spPolicy.SpecialPriceOrDiscount; ibeSeat.PolicyRMK = spPolicy.Remark; ibeSeat.PolicyId = spPolicy.PolicyId; ibeSeat.PlatformCode = spPolicy.PlatformCode; //处理特价 if (spPolicy.PolicySpecialType == EnumPolicySpecialType.FixedSpecial) { //固定特价不为0时 更改舱位价为固定特价 if (ibeSeat.SpecialPriceOrDiscount != 0) { ibeSeat.SeatPrice = ibeSeat.SpecialPriceOrDiscount; } } else if (spPolicy.PolicySpecialType == EnumPolicySpecialType.DownSpecial) { //直降 直降不为0时 舱位价中减除直降的价格 if (ibeSeat.SpecialPriceOrDiscount != 0) { ibeSeat.SeatPrice -= ibeSeat.SpecialPriceOrDiscount; } } else if (spPolicy.PolicySpecialType == EnumPolicySpecialType.DiscountOnDiscount) { //折上折 折扣不为0 在现有的舱位价上根据折扣再次计算 if (ibeSeat.SpecialPriceOrDiscount != 0) { decimal zk = ibeSeat.SpecialPriceOrDiscount / 100; ibeSeat.SeatPrice *= zk; //进到十位 ibeSeat.SeatPrice = dataBill.CeilAddTen((int)ibeSeat.SeatPrice); } } //舱位价小于0时为0处理 if (ibeSeat.SeatPrice <= 0) { ibeSeat.SeatPrice = 0; } ibeSeat.Commission = dataBill.GetCommission(spPolicy.Point, ibeSeat.SeatPrice, ibeSeat.ReturnMoney); //屏蔽非单程的非动态特价 //if (avhList.Count > 1 && ibeSeat.PolicySpecialType != EnumPolicySpecialType.DynamicSpecial) // return; //添加到集合 addRowList.Add(ibeSeat); } }); } } #endregion //普通舱位 PolicyCache policy = result.Where(p => p.PolicySpecialType == EnumPolicySpecialType.Normal).OrderByDescending(p => p.Point).FirstOrDefault(); if (policy != null) { //排除异地政策为0的显示 if (policy.PolicySourceType == EnumPolicySourceType.Share && policy.OldPoint == 0) { continue; } avhData.IbeData[j].IBESeat[k].Policy = policy.Point; avhData.IbeData[j].IBESeat[k].PolicySpecialType = policy.PolicySpecialType; avhData.IbeData[j].IBESeat[k].SpecialPriceOrDiscount = policy.SpecialPriceOrDiscount; avhData.IbeData[j].IBESeat[k].PolicyRMK = policy.Remark; avhData.IbeData[j].IBESeat[k].PolicyId = policy.PolicyId; avhData.IbeData[j].IBESeat[k].PlatformCode = policy.PlatformCode; avhData.IbeData[j].IBESeat[k].Commission = dataBill.GetCommission(policy.Point, avhData.IbeData[j].IBESeat[k].SeatPrice, avhData.IbeData[j].IBESeat[k].ReturnMoney); } } if (addRowList.Count > 0) { avhData.IbeData[j].IBESeat.AddRange(addRowList.ToArray()); } } } } } catch (Exception ex) { //记录日志 log.WriteLog("MatchPolicy", "异常信息:" + ex.Message + "\r\n"); } return(avhList); }
/// <summary> /// 获取IBE数据 /// </summary> /// <param name="FromCode"></param> /// <param name="ToCode"></param> /// <param name="FlyDate"></param> /// <returns></returns> public AVHData GetAvh(string FromCode, string ToCode, DateTime FlyDate, string carrayCode) { AVHData ibeData = new AVHData(); //记录日志 StringBuilder sbLog = new StringBuilder(); sbLog.Append("参数:\r\nFromCode=" + FromCode + "\r\n ToCode=" + ToCode + "\r\n FlyDate=" + FlyDate.ToString("yyyy-MM-dd HH:mm:ss") + (carrayCode != null ? carrayCode : "")); try { ibeData.IbeData = new List <IBERow>(); ibeData.QueryParam = new QueryParam() { FromCode = FromCode, ToCode = ToCode, FlyDate = FlyDate.ToString("yyy-MM-dd"), FlyTime = "00:00:00" }; string strData = string.Empty; if (useProxyQuery == 0) { IBEService.WebService1SoapClient ibe = new IBEService.WebService1SoapClient(); strData = ibe.getIBEAVData(ibeData.QueryParam.FromCode, ibeData.QueryParam.ToCode, ibeData.QueryParam.FlyDate, ibeData.QueryParam.FlyTime); } else if (useProxyQuery == 1) { FlightService flightService = ObjectFactory.GetInstance <FlightService>(); strData = flightService.GetAV(this.QueryParam.Code, ibeData.QueryParam.FromCode, ibeData.QueryParam.ToCode, carrayCode, ibeData.QueryParam.FlyDate, "0000"); } ibeData.AVHString = strData; if (!strData.Contains("NoRoutingException")) { string[] IbeArray = strData.Split(new string[] { "^" }, StringSplitOptions.RemoveEmptyEntries); if (IbeArray != null && IbeArray.Length > 0) { string[] strRow = null; foreach (string row in IbeArray) { strRow = row.ToUpper().Split(','); if (strRow.Length >= 15) { IBERow ibeRow = new IBERow(); try { //检测日期格式是否正确 DateTime.Parse(strRow[0]); } catch { strRow[0] = ibeData.QueryParam.FlyDate; } ibeRow.FlyDate = strRow[0]; ibeRow.StartTime = strRow[1]; ibeRow.EndTime = strRow[2]; ibeRow.CarrierCode = strRow[3].Trim(new char[] { '*' }); //过滤航空公司 if (!string.IsNullOrEmpty(carrayCode)) { if (ibeRow.CarrierCode != carrayCode.ToUpper()) { continue; } } ibeRow.FlightNo = strRow[4].Trim(new char[] { '*' }); if (!string.IsNullOrEmpty(strRow[5]) && strRow[5].Split('*')[0].Trim() != "") { string strSeat = strRow[5].Split('*')[0].Trim(); string pattern = "((?<Seat>[0-9A-Z])(?<SeatSymbol>[0-9A-Z]))"; MatchCollection mchs = Regex.Matches(strSeat, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); ibeRow.IBESeat = new List <IbeSeat>(); foreach (Match item in mchs) { if (item.Success) { IbeSeat ibeseat = new IbeSeat(); ibeseat.Seat = item.Groups["Seat"].Value.Trim(); ibeseat.SeatSymbol = item.Groups["SeatSymbol"].Value.Trim(); if (ibeseat.SeatSymbol == "A") { ibeseat.SeatCount = ">9"; } else if (char.IsNumber(ibeseat.SeatSymbol[0])) { ibeseat.SeatCount = ibeseat.SeatSymbol; } else { ibeseat.SeatCount = "0"; } //过滤没有位置的舱位 int mSeatCount = 0; int.TryParse(ibeseat.SeatCount.Replace(">", ""), out mSeatCount); if (mSeatCount > 0) { ibeseat = SetDefaultData(ibeseat); //去重 if (!ibeRow.IBESeat.Exists(p => p.Seat == ibeseat.Seat)) { ibeRow.IBESeat.Add(ibeseat); } } } } } ibeRow.FromCode = strRow[6]; ibeRow.ToCode = strRow[7]; ibeRow.AirModel = strRow[8]; ibeRow.IsStop = strRow[9].Trim() == "1" ? true : false; ibeRow.IsMeals = strRow[10].Trim() == "1" ? true : false; ibeRow.IsElectronicTicket = strRow[11].Trim() == "1" ? true : false; ibeRow.IsShareFlight = (strRow[12].Trim().ToLower() == "1" || strRow[12].Trim().ToLower() == "true") ? true : false; //处理子舱位 ibeRow.ChildSeat = strRow[13].Trim(); if (!string.IsNullOrEmpty(ibeRow.ChildSeat)) { string pattern = "((?<Seat>[0-9A-Z]1)(?<SeatSymbol>[0-9A-Z]))"; MatchCollection mchs = Regex.Matches(ibeRow.ChildSeat, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); if (ibeRow.IBESeat == null) { ibeRow.IBESeat = new List <IbeSeat>(); } foreach (Match item in mchs) { if (item.Success) { IbeSeat ibeseat = new IbeSeat(); ibeseat.Seat = item.Groups["Seat"].Value.Trim(); ibeseat.SeatSymbol = item.Groups["SeatSymbol"].Value.Trim(); if (ibeseat.SeatSymbol == "A") { ibeseat.SeatCount = ">9"; } else if (char.IsNumber(ibeseat.SeatSymbol[0])) { ibeseat.SeatCount = ibeseat.SeatSymbol; } else { ibeseat.SeatCount = "0"; } //过滤没有位置的舱位 int mSeatCount = 0; int.TryParse(ibeseat.SeatCount.Replace(">", ""), out mSeatCount); if (mSeatCount > 0) { ibeseat = SetDefaultData(ibeseat); //去重 if (!ibeRow.IBESeat.Exists(p => p.Seat == ibeseat.Seat)) { ibeRow.IBESeat.Add(ibeseat); } } } } } string strFromCityT1 = strRow[14].Trim(); if (strFromCityT1.Length == 2) { strFromCityT1 = strFromCityT1.Substring(0, 1); } else if (strFromCityT1.Length == 3) { if (strFromCityT1.StartsWith("D")) { strFromCityT1 = strFromCityT1.Substring(0, 1); } else { strFromCityT1 = strFromCityT1.Substring(0, 2); } } else { if ((strFromCityT1.Length >= 2)) { strFromCityT1 = strFromCityT1.Substring(0, 2); } } ibeRow.FromCityT1 = getHZL(ibeRow.FromCode, ibeRow.CarrierCode, strFromCityT1); string strToCityT1 = strRow[14].Trim(); if (strToCityT1.Length == 2) { strToCityT1 = strToCityT1.Substring(1, 1); } else if (strToCityT1.Length == 3) { if (strToCityT1.StartsWith("D")) { strToCityT1 = strToCityT1.Substring(1, 2); } else { strToCityT1 = strToCityT1.Substring(2, 1); } } else { if ((strToCityT1.Length >= 4)) { strToCityT1 = strToCityT1.Substring(2, 2); } } ibeRow.ToCityT1 = getHZL(ibeRow.ToCode, ibeRow.CarrierCode, strToCityT1); if (ibeRow.IsShareFlight) { if (IsOpenShareflght)//过滤共享航班 { //过去完后添加集合 ibeData.IbeData.Add(ibeRow); } } else { //添加集合 ibeData.IbeData.Add(ibeRow); } } } } } else { sbLog.Append("IBE异常信息:" + strData + "\r\n"); } } catch (Exception ex) { sbLog.Append("异常信息:" + ex.Message + "\r\n"); //记录日志 log.WriteLog("GetAvh", sbLog.ToString()); } return(ibeData); }