public static PhoneArea GetPhoneAreaInfo(string mobile) { PhoneArea phoneAreaInfo = null; if (!string.IsNullOrEmpty(mobile) && mobile.Length > 7) { try { SystemPhoneAreaWrapper phoneArea = SystemPhoneAreaWrapper.FindByPhonePrefix(mobile.Substring(0, 7)); if (phoneArea == null) { return(null); } phoneAreaInfo = new PhoneArea(); phoneAreaInfo.OperatorType = phoneArea.OperatorType; phoneAreaInfo.Province = phoneArea.Province; phoneAreaInfo.City = phoneArea.City; } catch (Exception ex) { Logger.Error(ex.Message); } } return(phoneAreaInfo); }
private PhoneArea GetProvinceAndCity(string mobile) { PhoneArea phoneAreaInfo = null; //#if DEBUG // phoneAreaInfo = GetPhoneAreaInfo(mobile); //#else if (!string.IsNullOrEmpty(mobile) && mobile.Length > 7) { try { try { phoneAreaInfo = CacheProviderFactory.GetPhoneAreaCache().GetPhoneAreaByPhoneNumber(mobile); } catch (Exception ex) { Logger.Error("NOSQL读取错误。", ex); phoneAreaInfo = GetPhoneAreaInfo(mobile); } } catch (Exception ex) { Logger.Error("手机号段读取失败。", ex); } } //#endif return(phoneAreaInfo); }
protected static Dictionary <string, PhoneArea> GetAllPhoneDictionary() { List <SystemPhoneAreaWrapper> phoneAreaWrappers = SystemPhoneAreaWrapper.FindAll(); Dictionary <string, PhoneArea> allPhoneDictionar = new Dictionary <string, PhoneArea>(); foreach (SystemPhoneAreaWrapper phoneAreaWrapper in phoneAreaWrappers) { PhoneArea phoneArea = new PhoneArea(); phoneArea.City = phoneAreaWrapper.City; phoneArea.Province = phoneAreaWrapper.Province; phoneArea.OperatorType = phoneAreaWrapper.OperatorType; allPhoneDictionar.Add(phoneAreaWrapper.PhonePrefix, phoneArea); } return(allPhoneDictionar); }
private void bgwDataToNoSQL_DoWork(object sender, DoWorkEventArgs doWorkEventArg) { List <SystemPhoneAreaWrapper> phoneAreaWrappers = SystemPhoneAreaWrapper.FindAll(); rowCounts = phoneAreaWrappers.Count; string title = string.Format("正在从数据库导入手机号段信息,共(" + rowCounts.ToString() + "条)."); SetTitle(title, rowCounts); var client = new MongoClient(Program.NoSQL_DBConnString); var server = client.GetServer(); var database = server.GetDatabase(Program.NoSQL_DbName); var collection = database.GetCollection(Program.NoSQL_CollectionName); int i = 0; foreach (SystemPhoneAreaWrapper phoneAreaWrapper in phoneAreaWrappers) { i++; if (bgwDataToNoSQL.CancellationPending) { break; } bgwDataToNoSQL.ReportProgress(i, rowCounts); ////var query = Query<PhoneArea>.EQ(e => e.PhonePrefix, phoneAreaWrapper.PhonePrefix); ////if (collection.FindOne(query) != null) ////{ //// this.Invoke(new Action(delegate() //// { //// this.lblProcessProgress.Text = "号码数据导入中( " + i.ToString() + "/" + rowCounts.ToString() + ")。。。"; //// })); //// continue; ////} var entity = new PhoneArea() { PhonePrefix = phoneAreaWrapper.PhonePrefix, Province = phoneAreaWrapper.Province, City = phoneAreaWrapper.City, OperatorType = phoneAreaWrapper.OperatorType, }; MongoInsertOptions mongoInsert = new MongoInsertOptions() { WriteConcern = WriteConcern.Unacknowledged }; rowSuccessCounts++; this.Invoke(new Action(delegate() { this.lblProcessProgress.Text = "号码数据导入中( " + i.ToString() + "/" + rowCounts.ToString() + ")。。。"; })); collection.Save(entity, mongoInsert); } }
public bool ProcessRequest(IDataAdapter httpRequestLog, bool statusOk, out RequestErrorType requestError, out string errorMessage) { requestError = RequestErrorType.NoError; errorMessage = ""; string linkid = GetLinkID(httpRequestLog); if (string.IsNullOrEmpty(linkid)) { requestError = RequestErrorType.NoLinkID; errorMessage = " 通道 ‘" + Name + "’ 请求失败:没有LinkID ."; return(false); } if (this.CheckLinkIDIsExisted(linkid)) { requestError = RequestErrorType.RepeatLinkID; errorMessage = " 通道 ‘" + Name + "’ 请求失败:重复的LinkID (缓存检查) ."; return(false); } string mo = this.ChannelParams.MoFromRequset(httpRequestLog); if (this.ChannelType == DictionaryConst.Dictionary_ChannelType_IVRChannel_Key) { mo = "ivr"; } string spcode = this.ChannelParams.SPCodeFromRequset(httpRequestLog); string mobile = this.ChannelParams.MobileFromRequset(httpRequestLog); string province = ""; string city = ""; string mobileOperator = ""; PhoneArea phoneArea = this.GetProvinceAndCity(mobile); if (phoneArea != null) { if (!string.IsNullOrEmpty(phoneArea.Province)) { province = phoneArea.Province; } else { province = ""; } if (!string.IsNullOrEmpty(phoneArea.City)) { city = phoneArea.City; } else { city = ""; } if (!string.IsNullOrEmpty(phoneArea.OperatorType)) { mobileOperator = phoneArea.OperatorType; } else { mobileOperator = ""; } } SPCodeWrapper matchCode = null; if (this.ChannelType == DictionaryConst.Dictionary_ChannelType_IVRChannel_Key) { matchCode = this.GetMatchCodeFromIVRRequest(httpRequestLog, spcode, province, city); } else { matchCode = this.GetMatchCodeFromRequest(httpRequestLog, mo, spcode, province, city); } if (matchCode == null) { requestError = RequestErrorType.NoChannelClientSetting; errorMessage = "请求失败:通道‘" + Name + "’请求未能找到匹配的代码设置。"; return(false); } SPClientCodeRelationWrapper clientCodeRelation = matchCode.GetRelateClientCodeRelation(); //如果存在指令,但是不存在对应的分配关系,转到默认匹配 if (clientCodeRelation == null) { clientCodeRelation = this.GetDefaultClientCodeRelation(); //如果是指令没有分配下家如何处理。 //matchCode = clientCodeRelation.CodeID; } SPRecordWrapper record = new SPRecordWrapper(); record.ChannelID = this; record.CodeID = matchCode; record.ClientID = clientCodeRelation.ClientID; record.ClientCodeRelationID = clientCodeRelation; record.Mo = mo; record.Mobile = mobile; record.LinkID = linkid; record.SpNumber = spcode; record.Province = province; record.City = city; record.OperatorType = mobileOperator; record.CreateDate = GetRecordTime(httpRequestLog); record.IsReport = false; record.IsStatOK = statusOk; record.IsIntercept = this.CaculteIsIntercept(matchCode, clientCodeRelation); if (record.IsIntercept) { record.IsSycnToClient = false; record.IsSycnSuccessed = false; record.SycnRetryTimes = 0; } else { if (!clientCodeRelation.SyncData) { record.IsSycnToClient = false; record.IsSycnSuccessed = false; record.SycnRetryTimes = 0; } else { record.IsSycnToClient = true; record.IsSycnSuccessed = false; record.SycnRetryTimes = 0; } } record.Price = clientCodeRelation.Price; record.Count = GetRecordCount(httpRequestLog); SPRecordExtendInfoWrapper spRecordExtendInfo = new SPRecordExtendInfoWrapper(); spRecordExtendInfo.StartTime = this.ChannelParams.StartTimeFromRequset(httpRequestLog); spRecordExtendInfo.EndTime = this.ChannelParams.EndTimeFromRequset(httpRequestLog); spRecordExtendInfo.FeeTime = this.ChannelParams.FeeTimeFromRequset(httpRequestLog); spRecordExtendInfo.State = this.ChannelParams.StateFromRequset(httpRequestLog); spRecordExtendInfo.Ip = httpRequestLog.RequestIp; spRecordExtendInfo.RequestContent = httpRequestLog.RequestData; spRecordExtendInfo.ExtendField1 = this.ChannelParams.ExtendField1FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField2 = this.ChannelParams.ExtendField2FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField3 = this.ChannelParams.ExtendField3FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField4 = this.ChannelParams.ExtendField4FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField5 = this.ChannelParams.ExtendField5FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField6 = this.ChannelParams.ExtendField6FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField7 = this.ChannelParams.ExtendField7FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField8 = this.ChannelParams.ExtendField8FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField9 = this.ChannelParams.ExtendField9FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField10 = this.ChannelParams.ExtendField10FromRequset(httpRequestLog); try { bool result = SPRecordWrapper.InsertPayment(record, spRecordExtendInfo, out requestError, out errorMessage); if (!result && requestError == RequestErrorType.RepeatLinkID) { requestError = RequestErrorType.RepeatLinkID; errorMessage = " 通道 ‘" + Name + "’ 请求失败:重复的LinkID(查询排重 异常排重) ."; return(false); } requestError = RequestErrorType.NoError; errorMessage = ""; try { CacheProviderFactory.GetLinkIDCache().AddLinkIDs(linkid, this.Id); } catch (Exception ex) { Logger.Error(ex.Message); } record.SycnToClient(); return(true); } catch (Exception ex) { requestError = RequestErrorType.DataSaveError; errorMessage = "请求失败:插入数据失败,错误信息:" + ex.Message; return(false); } }