예제 #1
0
        public void ReAutoMatch()
        {
            SPCodeWrapper matchCode = null;

            if (this.ChannelID.ChannelType == DictionaryConst.Dictionary_ChannelType_IVRChannel_Key)
            {
                matchCode = this.ChannelID.GetMatchCodeFromIVRRequest(this.ExtendInfo.GetHttpRequestLog(), this.SpNumber, this.Province, this.City);
            }
            else
            {
                matchCode = this.ChannelID.GetMatchCodeFromRequest(this.ExtendInfo.GetHttpRequestLog(), this.Mo, this.SpNumber, this.Province, this.City);
            }

            if (matchCode == null)
            {
                return;
            }

            SPClientCodeRelationWrapper clientCodeRelation = matchCode.GetRelateClientCodeRelation();


            //如果存在指令,但是不存在对应的分配关系,转到默认匹配
            if (clientCodeRelation == null)
            {
                clientCodeRelation = this.ChannelID.GetDefaultClientCodeRelation();

                //matchCode = clientCodeRelation.CodeID;
            }

            this.CodeID               = matchCode;
            this.ClientID             = clientCodeRelation.ClientID;
            this.ClientCodeRelationID = clientCodeRelation;

            Update(this);
        }
        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);
            }
        }