/// <summary> /// 补全数据 /// </summary> /// <param name="avhData"></param> /// <param name="fdData"></param> /// <returns></returns> public AVHData BuQuanAVH(AVHData avhData, FDData fdData) { try { if (avhData.IbeData.Count > 0 && fdData.FdRow.Count > 0) { // TestData test = new TestData(); List <AirplainType> listAirplainType = new List <AirplainType>(); try { //mgHelper.All<AirplainType>().ToList();// listAirplainType = test.GetAirplainType(); } catch (Exception) { listAirplainType = new List <AirplainType>(); } //所有的baseCabin List <BaseCabin> allBaseCabin = test.GetBaseCabin(""); decimal TaxFee = 0m;//机建费 for (int i = 0; i < avhData.IbeData.Count; i++) { //空舱位 if (avhData.IbeData[i].IBESeat == null || avhData.DicYSeatPrice == null) { continue; } //Y舱价格 if (!avhData.DicYSeatPrice.ContainsKey(avhData.IbeData[i].CarrierCode)) { if (fdData.YFdRow.ContainsKey(avhData.IbeData[i].CarrierCode)) { avhData.DicYSeatPrice.Add(avhData.IbeData[i].CarrierCode, fdData.YFdRow[avhData.IbeData[i].CarrierCode].SeatPrice); } } //查找机建费 AirplainType airplainType = listAirplainType.Find(p => p.Code == avhData.IbeData[i].AirModel); if (airplainType != null) { TaxFee = airplainType.TaxFee; } else { try { AirplainType _airplainType = new AirplainType() { Code = avhData.IbeData[i].AirModel, TaxFee = 50m }; //补全机型机建 //mgHelper.Add<AirplainType>(); if (!test.ExistAirplainType(_airplainType.Code)) { test.ExecuteSQL(string.Format("insert into AirplainType(Code,TaxFee) values('{0}',{1})", _airplainType.Code, _airplainType.TaxFee)); } } catch (Exception) { } } for (int j = 0; j < avhData.IbeData[i].IBESeat.Count; j++) { FdRow fdRow = fdData.FdRow.Where(p => p.CarrierCode == avhData.IbeData[i].CarrierCode && p.Seat == avhData.IbeData[i].IBESeat[j].Seat).FirstOrDefault(); if (fdRow != null) { //燃油 avhData.IbeData[i].ADultFuleFee = fdRow.ADultFuleFee; avhData.IbeData[i].ChildFuleFee = fdRow.ADultFuleFee; //机建费 从数据库中读取 暂时假数据 if (TaxFee != 0) { avhData.IbeData[i].TaxFee = TaxFee; } //舱位价 avhData.IbeData[i].IBESeat[j].SeatPrice = fdRow.SeatPrice; //折扣 avhData.IbeData[i].IBESeat[j].Rebate = fdRow.Rebate; } else { try { //从数据库中获取 //BaseCabin baseCabin = mgHelper.Query<BaseCabin>(p => p.CarrierCode == avhData.IbeData[i].CarrierCode && p.Code == avhData.IbeData[i].IBESeat[j].Seat).FirstOrDefault(); //List<BaseCabin> baseCabinList = test.GetBaseCabin(string.Format(" CarrierCode='{0}' and Code='{1}' ", avhData.IbeData[i].CarrierCode, avhData.IbeData[i].IBESeat[j].Seat)); List <BaseCabin> baseCabinList = allBaseCabin.Where(m => m.CarrierCode == avhData.IbeData[i].CarrierCode && m.Code == avhData.IbeData[i].IBESeat[j].Seat).ToList(); BaseCabin baseCabin = null; if (baseCabinList != null && baseCabinList.Count > 0) { baseCabin = baseCabinList[0]; } if (baseCabin != null && avhData.DicYSeatPrice.ContainsKey(avhData.IbeData[i].CarrierCode) && avhData.DicYSeatPrice[avhData.IbeData[i].CarrierCode] != 0m) { //折扣 avhData.IbeData[i].IBESeat[j].Rebate = baseCabin.Rebate; //舱位价 avhData.IbeData[i].IBESeat[j].SeatPrice = dataBill.MinusCeilTen((baseCabin.Rebate / 100) * avhData.DicYSeatPrice[avhData.IbeData[i].CarrierCode]); } fdRow = fdData.FdRow.Where(p => p.ADultFuleFee != 0).FirstOrDefault(); //取这条航线的燃油 但不精确 avhData.IbeData[i].ADultFuleFee = fdRow.ADultFuleFee; avhData.IbeData[i].ChildFuleFee = fdRow.ADultFuleFee; //机建费 从数据库中读取 暂时假数据 avhData.IbeData[i].TaxFee = TaxFee; } catch (Exception) { } } } } } } catch (Exception ex) { //记录日志 log.WriteLog("BuQuanAVH", "异常信息:" + ex.Message + "\r\n"); } return(avhData); }
/// <summary> /// 获取FD数据 包括数据的补全 /// </summary> /// <param name="FromCode"></param> /// <param name="ToCode"></param> /// <param name="FlyDate"></param> /// <returns></returns> public FDData GetFD(string FromCode, string ToCode, DateTime FlyDate, string carrayCode) { FDData fd = new FDData(); List <string> execSQL = new List <string>(); //记录日志 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 { fd.QueryParam = new QueryParam() { FromCode = FromCode, ToCode = ToCode, FlyDate = FlyDate.ToString("yyy-MM-dd"), FlyTime = "00:00:00" }; fd.FdRow = new List <FdRow>(); //所有的baseCabin List <BaseCabin> allBaseCabin = test.GetBaseCabin(""); IBEService.WebService1SoapClient ibe = new IBEService.WebService1SoapClient(); DataSet dsIBE = ibe.getIBEFDData(fd.QueryParam.FromCode, fd.QueryParam.ToCode, fd.QueryParam.FlyDate, fd.QueryParam.FlyTime); #region 数据条数 int FltShopAVJourneyCount = dsIBE.Tables["FltShopAVJourney"].Rows.Count; int FltShopAVOptCount = dsIBE.Tables["FltShopAVOpt"].Rows.Count; int CabinAllCount = dsIBE.Tables["CabinAll"].Rows.Count; int TaxAllCount = dsIBE.Tables["TaxAll"].Rows.Count; int FltShopAVFltCount = dsIBE.Tables["FltShopAVFlt"].Rows.Count; int FltShopPSCount = dsIBE.Tables["FltShopPS"].Rows.Count; int RouteAllCount = dsIBE.Tables["RouteAll"].Rows.Count; int FltShopNFareCount = dsIBE.Tables["FltShopNFare"].Rows.Count; int FltShopPFareCount = dsIBE.Tables["FltShopPFare"].Rows.Count; int FltShopRuleCount = dsIBE.Tables["FltShopRule"].Rows.Count; List <string> AirCodeList = new List <string>(); List <AirCarrier> m_AirCideList = test.GetAirCarrier(""); //..从数据库中读取航空公司 m_AirCideList.ForEach(p => { if (!AirCodeList.Contains(p.Code)) { AirCodeList.Add(p.Code); } }); //从FD中读取航空公司记入列表中 if (FltShopAVFltCount > 0) { for (int i = 0; i < FltShopAVFltCount; i++) { string tempC = dsIBE.Tables["FltShopAVFlt"].Rows[i]["A1"].ToString().ToUpper(); if (!AirCodeList.Contains(tempC)) { AirCodeList.Add(tempC); } } } #endregion //航线 // var result = // mgHelper.All<CabinSeat>().Where(p => p.Airline.FromCode == FromCode && p.Airline.ToCode == ToCode); List <CabinSeat> CabinSeatList = test.GetCabinSeatList(string.Format(" FromCode='{0}' and ToCode='{1}' ", FromCode, ToCode));// result.ToList(); #region 获取燃油 decimal ranyou = 0m; for (int i = 0; i < TaxAllCount; i++) { if (dsIBE.Tables["TaxAll"].Rows[i]["A1"].ToString().ToUpper() == "YQ") { ranyou = decimal.Parse((dsIBE.Tables["TaxAll"].Rows[i]["A2"] == DBNull.Value || dsIBE.Tables["TaxAll"].Rows[i]["A2"].ToString() == "") ? "0" : dsIBE.Tables["TaxAll"].Rows[i]["A2"].ToString()); if (ranyou > 0) { break; } } } #endregion #region 获取舱价格 //获取这条行线里程有没有不为0的 CabinSeat cabinSeat = CabinSeatList.Where(p => p.Airline.Mileage != 0).FirstOrDefault(); Airline airline = cabinSeat != null ? cabinSeat.Airline : null; //各个航空公司的这条航线的Y舱数据 Dictionary <string, FdRow> dicY = new Dictionary <string, FdRow>(); for (int i = 0; i < FltShopPFareCount; i++) { FdRow fdr = new FdRow(); fdr.Seat = dsIBE.Tables["FltShopPFare"].Rows[i]["A2"].ToString().ToUpper(); fdr.CarrierCode = dsIBE.Tables["FltShopPFare"].Rows[i]["A1"].ToString().ToUpper(); //过滤航空公司 if (!string.IsNullOrEmpty(carrayCode)) { if (fdr.CarrierCode != carrayCode.ToUpper()) { continue; } } //过滤完后添加到集合 fd.FdRow.Add(fdr); //获取舱位价格 if (fdr.Seat.Trim().Length == 1 || fdr.Seat.Trim().Length == 2) { decimal _SeatPrice = 0m; if (decimal.TryParse(dsIBE.Tables["FltShopPFare"].Rows[i]["A3"].ToString(), out _SeatPrice)) { fdr.SeatPrice = _SeatPrice; } } fdr.Mileage = (airline == null || airline.Mileage == 0) ? (int)fdr.SeatPrice : airline.Mileage; if (ranyou <= 0) { if (cabinSeat != null) { fdr.ADultFuleFee = cabinSeat.Fuel.AdultFuelFee; fdr.ChildFuleFee = cabinSeat.Fuel.ChildFuelFee; } } else { fdr.ADultFuleFee = ranyou; fdr.ChildFuleFee = ranyou; //List<CabinSeat> FuelList = CabinSeatList.Where(p => p.CarrierCode == fdr.CarrierCode).ToList(); //List<string> idsList = new List<string>(); //for (int j = 0; j < FuelList.Count; j++) //{ // idsList.Add("'" + FuelList[j]._id + "'"); //} //if (idsList.Count > 0) //{ // execSQL.Add(string.Format("update CabinSeat set AdultFuelFee={0},ChildFuelFee={1} where _id in({2}) ", ranyou, ranyou, string.Join(",", idsList.ToArray()))); //} } if (fdr.Seat == "Y") { if (!dicY.ContainsKey(fdr.CarrierCode)) { dicY.Add(fdr.CarrierCode, fdr); } } } fd.YFdRow = dicY; //循环承运人 foreach (string item in AirCodeList) { if (!dicY.ContainsKey(item)) { //没有Y舱数据信息的航空公司 需要补全 CabinSeat lineResult = CabinSeatList.Where(p => p.CarrierCode == item).FirstOrDefault(); FdRow fdr = new FdRow() { ADultFuleFee = ranyou == 0 && lineResult != null ? lineResult.Fuel.AdultFuelFee : ranyou, ChildFuleFee = ranyou == 0 && lineResult != null ? lineResult.Fuel.ChildFuelFee : ranyou, CarrierCode = item, Mileage = lineResult != null ? lineResult.Airline.Mileage : 0, Rebate = 100, SeatPrice = lineResult != null ? lineResult.Airline.SeatPrice : 0, TaxFee = 0m, Seat = "Y" }; dicY.Add(item, fdr); fd.FdRow.Add(fdr); } else { //更新Y舱价格和里程数据 //List<CabinSeat> YMList = CabinSeatList.Where(p => p.CarrierCode == item).ToList(); //List<string> idslIst = new List<string>(); //for (int i = 0; i < YMList.Count; i++) //{ // idslIst.Add("'" + YMList[i]._id + "'"); //} //if (idslIst.Count > 0) //{ // execSQL.Add(string.Format("update CabinSeat set SeatPrice={0},Mileage={1} where _id in({2}) ", dicY[item].SeatPrice, dicY[item].Mileage, string.Join(",", idslIst.ToArray()))); //} } } //检查漏掉的舱位 foreach (string aircode in AirCodeList) { if (dicY.ContainsKey(aircode)) { CabinSeat lineResult = CabinSeatList.Where(p => p.CarrierCode == aircode).FirstOrDefault(); if (lineResult != null) { lineResult.SeatList.ForEach(p => { //不存在就添加 FdRow frw = fd.FdRow.Where(p1 => p1.CarrierCode == lineResult.CarrierCode && p1.Seat == p.Code).FirstOrDefault(); if (frw == null) { fd.FdRow.Add(new FdRow() { ADultFuleFee = lineResult.Fuel.AdultFuelFee, ChildFuleFee = lineResult.Fuel.ChildFuelFee, CarrierCode = aircode, Mileage = lineResult != null ? lineResult.Airline.Mileage : 0, SeatPrice = 0, Seat = p.Code }); } }); } } } //IBE没有获取到价格的 用基本数据计算 //List<FdRow> nfdr = fd.FdRow.Where(p => p.SeatPrice == 0m).ToList(); //for (int i = 0; i < nfdr.Count; i++) //{ // FdRow fdr = nfdr[i]; // if (fdr.SeatPrice == 0 && dicY.ContainsKey(fdr.CarrierCode)) // { // var seatResult = CabinSeatList.Where(p => p.CarrierCode == fdr.CarrierCode).FirstOrDefault(); // Seat seat = seatResult != null ? seatResult.SeatList.Where(p => p.Code == fdr.Seat).FirstOrDefault() : null; // if (seat != null) // { // fdr.Rebate = seat.Rebate; // fdr.SeatPrice = dataBill.CeilTen((seat.Rebate / 100) * dicY[fdr.CarrierCode].SeatPrice); // } // else // { // //去基础表查询 // List<BaseCabin> baseCabinList = allBaseCabin.Where(m => m.CarrierCode == fdr.CarrierCode && m.Code == fdr.Seat).ToList(); // if (baseCabinList != null && baseCabinList.Count > 0) // { // BaseCabin baseCabin = baseCabinList[0]; // fdr.Rebate = baseCabin.Rebate; // fdr.SeatPrice = dataBill.CeilTen((baseCabin.Rebate / 100) * dicY[fdr.CarrierCode].SeatPrice); // } // } // } //} #endregion #region 计算更新折扣 //fd.FdRow没有的舱位就没有办法了 Dictionary <string, List <Seat> > dicSeat = new Dictionary <string, List <Seat> >(); for (int i = 0; i < fd.FdRow.Count; i++) { if (dicY.ContainsKey(fd.FdRow[i].CarrierCode)) { if (dicY[fd.FdRow[i].CarrierCode].SeatPrice != 0) { //计算折扣 fd.FdRow[i].Rebate = GetZk(fd.FdRow[i].SeatPrice, dicY[fd.FdRow[i].CarrierCode].SeatPrice); } if (!dicSeat.ContainsKey(fd.FdRow[i].CarrierCode)) { List <Seat> ffdList = new List <Seat>(); ffdList.Add(new Seat() { Rebate = fd.FdRow[i].Rebate, Code = fd.FdRow[i].Seat }); dicSeat.Add(fd.FdRow[i].CarrierCode, ffdList); } else { dicSeat[fd.FdRow[i].CarrierCode].Add(new Seat() { Rebate = fd.FdRow[i].Rebate, Code = fd.FdRow[i].Seat }); } } } if (dicSeat.Count > 0) { foreach (KeyValuePair <string, List <Seat> > item in dicSeat) { List <CabinSeat> List = CabinSeatList.Where(p => p.CarrierCode == item.Key && (p.SeatList == null || p.SeatList.Count == 0)).ToList(); for (int i = 0; i < List.Count; i++) { //更新舱位 if (item.Value != null && item.Value.Count > 0) { List[i].SeatList = item.Value; } else { List <Seat> sbSeat = new List <Seat>(); List <BaseCabin> baseCabinList = allBaseCabin.Where(m => m.CarrierCode == item.Key).ToList(); foreach (BaseCabin baseItem in baseCabinList) { sbSeat.Add(new Seat() { Code = baseItem.Code, Rebate = baseItem.Rebate }); } List[i].SeatList = sbSeat; } StringBuilder sbSeatData = new StringBuilder(); foreach (Seat seat in List[i].SeatList) { sbSeatData.Append(seat.ToString() + "|"); } //更新舱位 //execSQL.Add(string.Format("update dbo.CabinSeat set SeatList='{0}' where _id='{1}' and (SeatList='' or SeatList is null) ", sbSeatData, List[i]._id)); } } } #endregion //System.Threading.ThreadPool.QueueUserWorkItem(p => //{ // if (execSQL.Count > 0) // { // test.ExecuteSQLList(execSQL); // } //}); } catch (Exception ex) { sbLog.Append("异常信息:" + ex.Message + "\r\n"); //记录日志 log.WriteLog("GetFD", sbLog.ToString()); } return(fd); }