public List <CabinSeat> GetCabinSeatList(string sqlWhere) { string sql = "select * from dbo.CabinSeat"; if (!string.IsNullOrEmpty(sqlWhere)) { sql += " where " + sqlWhere; } List <CabinSeat> reList = new List <CabinSeat>(); try { using (SqlConnection conn = new SqlConnection(strConnectionString)) { SqlCommand cmd = new SqlCommand(sql, conn); if (conn.State == ConnectionState.Closed) { conn.Open(); } SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (rdr.Read()) { CabinSeat cabinSeat = new CabinSeat(); cabinSeat._id = rdr["_id"] != null ? rdr["_id"].ToString() : ""; cabinSeat.CarrierCode = rdr["CarrierCode"] != null ? rdr["CarrierCode"].ToString() : ""; cabinSeat.Airline = new Airline() { FromCode = rdr["FromCode"] != null ? rdr["FromCode"].ToString() : "", ToCode = rdr["ToCode"] != null ? rdr["ToCode"].ToString() : "", Mileage = int.Parse(rdr["Mileage"] != null ? rdr["Mileage"].ToString() : "0"), SeatPrice = decimal.Parse(rdr["SeatPrice"] != null ? rdr["SeatPrice"].ToString() : "0") }; cabinSeat.Fuel = new Fuel() { AdultFuelFee = decimal.Parse(rdr["AdultFuelFee"] != null ? rdr["AdultFuelFee"].ToString() : "0"), ChildFuelFee = decimal.Parse(rdr["ChildFuelFee"] != null ? rdr["ChildFuelFee"].ToString() : "0") }; string strSeat = rdr["SeatList"] != null ? rdr["SeatList"].ToString() : ""; string[] strArray = strSeat.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length > 0) { List <Seat> listSpace = new List <Seat>(); foreach (string item in strArray) { if (item.Split('-').Length == 2) { listSpace.Add(new Seat() { Code = item.Split('-')[0], Rebate = decimal.Parse(item.Split('-')[1]) }); } } cabinSeat.SeatList = listSpace; } else { cabinSeat.SeatList = new List <Seat>(); } reList.Add(cabinSeat); } rdr.Close(); } } catch (SqlException ex) { JoveZhao.Framework.Logger.WriteLog(JoveZhao.Framework.LogType.ERROR, "航班数据库查询[GetCabinSeatList]", ex); } catch (Exception e) { JoveZhao.Framework.Logger.WriteLog(JoveZhao.Framework.LogType.ERROR, "航班数据库查询[GetCabinSeatList]", e); } return(reList); }
/// <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); }