public override void Invoke(IHandlerContext context)
        {
            try
            {
                #region   全量政策
                QunarUploadPolicyRequest qunarRequest = CoreHelper.ChangeToChild <UpLoadPolicyRequest, QunarUploadPolicyRequest>(context.Request);
                Policies     policy        = qunarRequest.PolicyDataOrgin.LastOrDefault();
                PolicyRecord LastPolicyRec = new PolicyRecord {
                    LastPolicyId = 0, LastUpdateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"))
                };
                context.UploadResponse.PolicyRec[UploadType.FullUpload] = LastPolicyRec;
                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "收到全量政策" + qunarRequest.PolicyDataOrgin.Count + "条,开始分批上传"
                });
                context.SetRequest(qunarRequest);
                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "当前全量政策为" + qunarRequest.PolicyDataOrgin.Count + "条,不用分批上传"
                });
                qunarRequest.PolicyData.Add(UploadTypeDetail.FullUpload, qunarRequest.PolicyDataOrgin);
                Next.Invoke(context);

                #endregion
            }
            catch (Exception ex)
            {
                OnMiddlewareWorking(new EventMsg()
                {
                    Status = Enums.RunStatus.Exception, Msg = "QunarFullDispatcherMiddleware:" + ex.Message, Exception = ex, PurchaserType = Enums.PurchaserType.Qunar
                });
                context.UploadResponse = new UploadPolicyResponse()
                {
                    ErrCode = Enums.ResultType.Failed, ErrMsg = ex.Message, Excption = ex
                };
                return;
            }
        }
        public override void Invoke(IHandlerContext context)
        {
            try
            {
                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "开始获取去哪儿增量更新包..."
                });
                QunarUploadPolicyRequest qunarIncrementRequest = CoreHelper.ChangeToChild <UpLoadPolicyRequest, QunarUploadPolicyRequest>(context.Request);


                #region 查询增量政策
                SearchPolicyRequest request = new SearchPolicyRequest()
                {
                    CommisionMoney     = qunarIncrementRequest.CommisionMoney,
                    CommsionPoint      = qunarIncrementRequest.CommsionPoint,
                    IsUpload           = true,
                    OperName           = qunarIncrementRequest.OperName,
                    PageSize           = qunarIncrementRequest.PageSize,
                    PolicyType         = qunarIncrementRequest.PolicyType,
                    pType              = PurchaserType.Qunar,
                    SqlWhere           = qunarIncrementRequest.SqlWhere,
                    UType              = qunarIncrementRequest.UploadType,
                    IsSearchTotalCount = false,
                };
                #region 如果是实时上传则根据上传过的去哪儿记录过滤要上传的记录
                //if (qunarIncrementRequest.IsRealTimeUpload)
                //{
                //   // OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "开始获取实时更新时间..." });
                //    request.IsRealTimeUpload = true;//是否实时更新


                //    //SearchRealTimeUploadResponse realTimeRep = JsonConvert.DeserializeObject<SearchRealTimeUploadResponse>(CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["SearchRealTimeUploadUrl"].ToString(), request));//获取实时上传的记录
                //    //if(realTimeRep.ErrCode == ResultType.Failed)
                //    //{
                //    //    return;
                //    //}
                //    //request.RealTimePolicyRec = realTimeRep.PolicyRec;
                //    //OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "获取到实时更新时间:" + realTimeRep.PolicyRec.LastUpdateTime.ToString("yyyy-MM-dd HH:mm:ss.fff") });
                //}
                #endregion
                string searchContent           = CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["SearchPolicyUrl"].ToString(), request);
                string selectSql               = "";
                int    totalCount              = 0;
                SearchPolicyResponse rep       = JsonConvert.DeserializeObject <SearchPolicyResponse>(searchContent);//先查询一遍,获取要上传的政策
                PolicyRecord         policyRec = rep.LastPolicyRecord;
                context.UploadResponse.BeforePolicyRecord = policyRec;
                if (rep.lstPolicies.Count <= 0)
                {
                    OnMiddlewareWorking(new EventMsg {
                        Status = RunStatus.Normal, Msg = "暂时没有收到增量更新包"
                    });
                    return;
                }
                #endregion

                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "收到增量更新包:" + rep.lstPolicies.Count + "条,开始过滤..."
                });
                List <Policies> lstPoliciesOrgin = rep.lstPolicies;
                #region 如果是实时上传则根据上传过的去哪儿记录过滤要上传的记录
                //if (qunarIncrementRequest.IsRealTimeUpload)
                //{
                //    OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "获取上次更新时间:" + rep.LastPolicyRecord.LastUpdateTime.ToString("yyyy-MM-dd HH:mm:ss.fff") });
                //    //更新到的政策里面去筛选出已经上传的政策Id
                //  CompleteUploadPolicyResponse completePolicyRep = JsonConvert.DeserializeObject<CompleteUploadPolicyResponse>(CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["SearchCompleteUploadUrl"].ToString(), request));
                //    //把没有上传的政策删除掉
                //  if (completePolicyRep.ErrCode == ResultType.Failed || completePolicyRep.CompleteUploadPolicyCollection.Count <= 0)
                //  {
                //      OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "该更新包不在上传去哪儿的上传列表中,不用更新" });
                //      return;
                //  }
                //  lstPoliciesOrgin = CoreHelper.ReserveHaveUploadPolicy(lstPoliciesOrgin, completePolicyRep.CompleteUploadPolicyCollection);
                //    if(lstPoliciesOrgin.Count <= 0)
                //    {
                //        OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "该更新包不在上传去哪儿的上传列表中,不用更新" });
                //        return;
                //    }
                //}
                #endregion
                selectSql = context.Request.IsPrintSql ? "\r\n去哪儿获取增量数据sql:" + selectSql + "\r\n" : "";

                if (lstPoliciesOrgin.Count <= 0)
                {
                    OnMiddlewareWorking(new EventMsg {
                        Status = RunStatus.Normal, Msg = selectSql + "暂时没有增量政策更新包!"
                    });
                    return;
                }
                qunarIncrementRequest.PolicyDataOrgin     = lstPoliciesOrgin;
                context.UploadResponse.BeforePolicyRecord = rep.LastPolicyRecord;
                context.SetRequest(qunarIncrementRequest);
                Next.Invoke(context);
                #region 旧代码
                //#region 过滤政策
                //bool isHaveAll = false;
                //List<Policies> lstFiltedPolicy = CoreHelper.FilterPolicy(qunarIncrementRequest.LstQunarCodes, lstPoliciesOrgin, ref isHaveAll);
                //if (lstFiltedPolicy.Count <= 0)
                //{
                //    OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "经过去哪儿三子码过滤后未筛选到要上传的政策" });
                //    return;
                //}
                //#endregion

                //OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "过滤完成,政策数量:" + lstFiltedPolicy.Count + "条,开始拆分..." });

                //#region 拆分政策
                //List<Policies> lstIncrementalPolicies = CoreHelper.SplitPolicy(request.pType, lstFiltedPolicy, qunarIncrementRequest.LstQunarCodes);
                //qunarIncrementRequest.UploadCount = lstIncrementalPolicies.Count;

                //selectSql = context.Request.IsPrintSql ? "\r\n去哪儿获取增量数据sql:" + selectSql + "\r\n" : "";

                //if (lstIncrementalPolicies.Count <= 0)
                //{
                //    OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = selectSql + "暂时没有增量政策更新包!" });
                //    return;
                //}
                //#endregion



                //OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = selectSql + "收到拆分政策" + lstIncrementalPolicies.Count.ToString() + "条增量政策更新包!开始上传..." });
                //Policies policy = lstIncrementalPolicies.LastOrDefault();
                //PolicyRecord lastPolicyRec = new PolicyRecord() { LastPolicyId = 0, LastUpdateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")) };
                //context.UploadResponse.PolicyRec[UploadType.Incremental] = lastPolicyRec;//保存上次更新记录

                //#region 判断是否分批并交由下个中间件处理
                //int upLoadCount = System.Configuration.ConfigurationManager.AppSettings["MaxUploadCount"] == null ? 1000 : int.Parse(System.Configuration.ConfigurationManager.AppSettings["MaxUploadCount"].ToString());
                //if (lstIncrementalPolicies.Count < upLoadCount)//小于10000,自动上传
                //{
                //    OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "当前增量政策为" + lstIncrementalPolicies.Count + "条,小于最高限制条数:" + upLoadCount + "条,不用分批上传" });
                //    List<Policies> lstAddPolicies = lstIncrementalPolicies.Where(x => x.DelDegree == 1).ToList();
                //    List<Policies> lstDelPolicies = lstIncrementalPolicies.Where(x => x.DelDegree == 0).ToList();
                //    qunarIncrementRequest.PolicyData.Add(UploadTypeDetail.IncrementalAdd, lstAddPolicies);
                //    qunarIncrementRequest.PolicyData.Add(UploadTypeDetail.IncrementalDelete, lstDelPolicies);
                //    context.SetRequest(qunarIncrementRequest);
                //    Next.Invoke(context);

                //}
                //else
                //{
                //    OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "当前增量政策为" + lstIncrementalPolicies.Count + "条,大于最高限制条数:" + upLoadCount + "条,开始分批上传.." });
                //    int index = 1;
                //    while (lstIncrementalPolicies.Count > 0)
                //    {
                //        List<Policies> lstPolicies = new List<Policies>();
                //        lstPolicies = lstIncrementalPolicies.Take(upLoadCount).ToList();//取一万条先上传
                //        qunarIncrementRequest.UploadCount = lstPolicies.Count;
                //        if (lstPolicies.Count > 0)
                //        {
                //            lstIncrementalPolicies.RemoveRange(0, lstPolicies.Count);
                //        }
                //        OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "收到增量政策数量:" + lstPolicies.Count + "条,开始第" + index + "次分批上传" });
                //        List<Policies> lstAddPolicies = lstIncrementalPolicies.Where(x => x.DelDegree == 1).ToList();
                //        List<Policies> lstDelPolicies = lstIncrementalPolicies.Where(x => x.DelDegree == 0).ToList();
                //        PolicyRecord rec = new PolicyRecord() { LastPolicyId = lstPolicies.LastOrDefault().Id, LastUpdateTime = lstPolicies.LastOrDefault().UpdateTime };
                //        context.UploadResponse.BeforePolicyRecord = rec;//每次都保留上回更新的记录
                //        qunarIncrementRequest.PolicyData.Remove(UploadTypeDetail.IncrementalAdd);//先移除后添加,防止key冲突
                //        qunarIncrementRequest.PolicyData.Remove(UploadTypeDetail.IncrementalDelete);
                //        qunarIncrementRequest.PolicyData.Add(UploadTypeDetail.IncrementalAdd, lstAddPolicies);
                //        qunarIncrementRequest.PolicyData.Add(UploadTypeDetail.IncrementalDelete, lstDelPolicies);
                //        context.SetRequest(qunarIncrementRequest);
                //        Next.Invoke(context);
                //        index++;
                //    }
                //}
                //#endregion
                #endregion
            }
            catch (Exception ex)
            {
                OnMiddlewareWorking(new EventMsg()
                {
                    Status = ND.PolicyService.Enums.RunStatus.Exception, Msg = "QunarLoadIncrementalPolicyMiddleware:" + ex.Message, Exception = ex, PurchaserType = ND.PolicyService.Enums.PurchaserType.Qunar
                });
                context.UploadResponse = new UploadPolicyResponse()
                {
                    ErrCode = ND.PolicyService.Enums.ResultType.Failed, ErrMsg = ex.Message, Excption = ex
                };
                return;
            }
        }
Esempio n. 3
0
        public override void Invoke(IHandlerContext context)
        {
            try
            {
                #region 过滤政策
                QunarUploadPolicyRequest qunarIncrementRequest = CoreHelper.ChangeToChild <UpLoadPolicyRequest, QunarUploadPolicyRequest>(context.Request);

                bool            isHaveAll       = false;
                List <Policies> lstFiltedPolicy = CoreHelper.FilterPolicy(qunarIncrementRequest.LstQunarCodes, qunarIncrementRequest.PolicyDataOrgin, ref isHaveAll);
                if (lstFiltedPolicy.Count <= 0)
                {
                    OnMiddlewareWorking(new EventMsg {
                        Status = RunStatus.Normal, Msg = "经过去哪儿三子码过滤后未筛选到要上传的政策"
                    });
                    context.UploadResponse = new UploadPolicyResponse()
                    {
                        ErrCode = Enums.ResultType.Sucess
                    };
                    return;
                }
                #endregion

                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "过滤完成,政策数量:" + lstFiltedPolicy.Count + "条,开始拆分..."
                });

                #region 拆分政策
                PoliciesType    policyType             = (PoliciesType)Enum.Parse(typeof(PoliciesType), qunarIncrementRequest.PolicyType.ToString());
                List <Policies> lstIncrementalPolicies = new List <Policies>();
                List <Policies> lstValidPolicies       = lstFiltedPolicy.Where(x => x.DelDegree == 1).ToList();
                List <Policies> lstNoValidPolicies     = lstFiltedPolicy.Where(x => x.DelDegree == 0).ToList();
                lstIncrementalPolicies.AddRange(lstNoValidPolicies);
                if (lstValidPolicies.Count > 0)
                {
                    lstValidPolicies = CoreHelper.SplitPolicy(PurchaserType.Qunar, lstValidPolicies, qunarIncrementRequest.LstQunarCodes, policyType);
                    lstIncrementalPolicies.AddRange(lstValidPolicies);
                }
                qunarIncrementRequest.UploadCount = lstIncrementalPolicies.Count;
                #endregion

                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "收到拆分政策" + lstIncrementalPolicies.Count.ToString() + "条政策包!开始上传..."
                });
                Policies policy = lstIncrementalPolicies.LastOrDefault();
                qunarIncrementRequest.PolicyDataOrgin = lstIncrementalPolicies;
                context.SetRequest(qunarIncrementRequest);
                Next.Invoke(context);
            }
            catch (Exception ex)
            {
                OnMiddlewareWorking(new EventMsg()
                {
                    Status = Enums.RunStatus.Exception, Msg = "QunarFilterSplitMiddleware:" + ex.Message, Exception = ex, PurchaserType = Enums.PurchaserType.Qunar
                });
                context.UploadResponse = new UploadPolicyResponse()
                {
                    ErrCode = ResultType.Failed, ErrMsg = "QunarFilterSplitMiddleware:" + ex.Message, Excption = ex
                };
                return;
            }
        }
        public override void Invoke(IHandlerContext context)
        {
            try
            {
                QunarUploadPolicyRequest qunarRequest = CoreHelper.ChangeToChild <UpLoadPolicyRequest, QunarUploadPolicyRequest>(context.Request);

                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "开始获取去哪儿全量更新包..."
                });
                //PolicySyncRecLib syncLib = new PolicySyncRecLib();
                //PolicyRecord policyRec = CoreHelper.GetLastUpTimeAndId("Qunar\\QunarFullPolicyRecLog");//去哪儿全量选择日志
                #region 查询政策
                SearchPolicyRequest request = new SearchPolicyRequest()
                {
                    CommisionMoney     = qunarRequest.CommisionMoney,
                    CommsionPoint      = qunarRequest.CommsionPoint,
                    IsUpload           = true,
                    OperName           = qunarRequest.OperName,
                    PageSize           = qunarRequest.PageSize,
                    PolicyType         = qunarRequest.PolicyType,
                    pType              = PurchaserType.Qunar,
                    SqlWhere           = qunarRequest.SqlWhere,
                    UType              = qunarRequest.UploadType,
                    IsSearchTotalCount = false
                };
                string searchContent           = CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["SearchPolicyUrl"].ToString(), request);
                SearchPolicyResponse rep       = JsonConvert.DeserializeObject <SearchPolicyResponse>(searchContent);//先查询一遍,获取要上传的政策
                PolicyRecord         policyRec = rep.LastPolicyRecord;
                context.UploadResponse.BeforePolicyRecord = policyRec;
                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "载入上次更新记录,更新时间:" + policyRec.LastUpdateTime.ToString("yyyy-MM-dd HH:mm:ss.fff") + ",上次最后一条更新id:" + policyRec.LastPolicyId.ToString() + ",收到全量政策包:" + rep.lstPolicies.Count + "条"
                });
                qunarRequest.PolicyDataOrgin = rep.lstPolicies;
                context.SetRequest(qunarRequest);
                Next.Invoke(context);
                #endregion
                #region 注释
                //bool isHaveAll = false;
                ////过滤政策
                //#region 过滤政策
                //int count = rep.lstPolicies == null ? 0 : rep.lstPolicies.Count;
                //OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "查询到政策数量:" + count + " 条,开始过滤..." });
                //List<Policies> lstFiltedPolicy = CoreHelper.FilterPolicy(qunarRequest.LstQunarCodes, rep.lstPolicies, ref isHaveAll);
                //if (lstFiltedPolicy.Count <= 0)
                //{
                //    OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "经过去哪儿三子码过滤后未筛选到要上传的政策" });
                //    return;
                //}
                ////if (isHaveAll)
                ////{
                ////  return;
                ////DialogResult dr = MessageBox.Show("当前上传的政策有全国对全国的政策,是否继续上传", "提示", MessageBoxButtons.OKCancel);
                ////if (dr == DialogResult.Cancel)
                ////{
                ////    return;
                ////}
                ////}
                //#endregion
                //List<Policies> lstAddPolicies = CoreHelper.SplitPolicy(request.pType, lstFiltedPolicy, qunarRequest.LstQunarCodes);//拆分政策
                //qunarRequest.UploadCount = lstAddPolicies.Count;
                //context.UploadResponse.BeforePolicyRecord = policyRec;
                //// List<Policies> lstAddPolicies = syncLib.LoadPolicy(context.Request.PageSize, policyRec, context.Request.SqlWhere, PurchaserType.Qunar, ref selectSql,ref totalCount, UploadType.FullUpload, context.Request.CommisionMoney, context.Request.CommsionPoint);//获取要上传的政策
                //// List<Policies> lstAddPolicies = syncLib.LoadPolicy(policyRec, context.Request.CommisionMoney, context.Request.CommsionPoint, context.Request.PageSize, context.Request.SqlWhere, ref selectSql, ref totalCount, UploadType.FullUpload);//获取要上传的政策


                ////if(!context.Request.IsPrintSql)
                ////{
                ////    selectSql = "";
                ////}
                ////selectSql = context.Request.IsPrintSql ? "\r\n筛选sql为:\r\n" + selectSql+"\r\n" : "";
                //if (lstAddPolicies.Count <= 0)
                //{
                //    OnMiddlewareWorking(new EventMsg { Status = RunStatus.Normal, Msg = "未筛选到要上传的政策,或者筛选的政策已经上传!" });
                //    context.UploadResponse = new UploadPolicyResponse() { ErrCode = ResultType.Failed, ErrMsg = "未筛选到要上传的政策,或者筛选的政策已经上传!" };
                //    return;
                //}
                #endregion
            }
            catch (Exception ex)
            {
                OnMiddlewareWorking(new EventMsg()
                {
                    Status = ND.PolicyService.Enums.RunStatus.Exception, Msg = "QunarLoadFullPolicyMiddleware:" + ex.Message, Exception = ex, PurchaserType = ND.PolicyService.Enums.PurchaserType.Qunar
                });
                context.UploadResponse = new UploadPolicyResponse()
                {
                    ErrCode = ND.PolicyService.Enums.ResultType.Failed, ErrMsg = ex.Message, Excption = ex
                };
                return;
            }
        }
Esempio n. 5
0
 public override void Invoke(IHandlerContext context)
 {
     try
     {
         QunarUploadPolicyRequest qunarIncrementRequest = CoreHelper.ChangeToChild <UpLoadPolicyRequest, QunarUploadPolicyRequest>(context.Request);
         //获取所有在去哪儿上传过的政策
         string responseContent = CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["SearchCompleteUploadPolicyUrl"].ToString(), null);
         if (string.IsNullOrEmpty(responseContent))
         {
             OnMiddlewareWorking(new EventMsg()
             {
                 PurchaserType = Enums.PurchaserType.Qunar, Status = Enums.RunStatus.Normal, Msg = "暂未上传过任何政策,不用更新!"
             });
             context.UploadResponse = new UploadPolicyResponse()
             {
                 ErrCode = Enums.ResultType.Sucess
             };
             return;
         }
         CompleteUploadPolicyResponse rep = JsonConvert.DeserializeObject <CompleteUploadPolicyResponse>(responseContent);
         if (rep.ErrCode == Enums.ResultType.Failed || rep.CompleteUploadPolicyCollection == null || rep.CompleteUploadPolicyCollection.Count <= 0)
         {
             OnMiddlewareWorking(new EventMsg()
             {
                 Status = Enums.RunStatus.Normal, Msg = "暂未上传过任何政策,不用更新!"
             });
             context.UploadResponse = new UploadPolicyResponse()
             {
                 ErrCode = Enums.ResultType.Sucess
             };
             return;
         }
         Dictionary <QunarPolicyType, List <Policies> > dic = CoreHelper.ReserveHaveUploadPolicy(qunarIncrementRequest.PolicyDataOrgin, rep.CompleteUploadPolicyCollection);
         if (dic.Count <= 0)
         {
             OnMiddlewareWorking(new EventMsg()
             {
                 Status = Enums.RunStatus.Normal, Msg = "此次更新包不在上传政策列表中,不用更新!"
             });
             context.UploadResponse = new UploadPolicyResponse()
             {
                 ErrCode = Enums.ResultType.Sucess
             };
             return;
         }
         foreach (KeyValuePair <QunarPolicyType, List <Policies> > item in dic)//分批上传不同类型的政策
         {
             qunarIncrementRequest.PolicyType      = item.Key;
             qunarIncrementRequest.PolicyDataOrgin = item.Value;
             context.SetRequest(qunarIncrementRequest);
             Next.Invoke(context);
         }
     }
     catch (Exception ex)
     {
         OnMiddlewareWorking(new EventMsg()
         {
             Status = Enums.RunStatus.Exception, Msg = "QunarFilterRepeatUploadMiddleware:" + ex.Message, Exception = ex, PurchaserType = Enums.PurchaserType.Qunar
         });
         context.UploadResponse = new UploadPolicyResponse()
         {
             ErrCode = Enums.ResultType.Failed, ErrMsg = ex.Message, Excption = ex
         };
         return;
     }
 }
        public override void Invoke(IHandlerContext context)
        {
            try
            {
                QunarUploadPolicyRequest qunarRequest  = CoreHelper.ChangeToChild <UpLoadPolicyRequest, QunarUploadPolicyRequest>(context.Request);
                PolicyRecord             lastPolicyRec = new PolicyRecord()
                {
                    LastPolicyId = 0, LastUpdateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"))
                };
                context.UploadResponse.PolicyRec[UploadType.Incremental] = lastPolicyRec;//保存上次更新记录
                #region 判断是否分批并交由下个中间件处理
                int upLoadCount = System.Configuration.ConfigurationManager.AppSettings["MaxUploadCount"] == null ? 1000 : int.Parse(System.Configuration.ConfigurationManager.AppSettings["MaxUploadCount"].ToString());
                if (qunarRequest.PolicyDataOrgin.Count < upLoadCount)//小于10000,自动上传
                {
                    OnMiddlewareWorking(new EventMsg {
                        Status = RunStatus.Normal, Msg = "当前政策为" + qunarRequest.PolicyDataOrgin.Count + "条,小于最高限制条数:" + upLoadCount + "条,不用分批上传"
                    });
                    List <Policies> lstAddPolicies = qunarRequest.PolicyDataOrgin.Where(x => x.DelDegree == 1).ToList();
                    List <Policies> lstDelPolicies = qunarRequest.PolicyDataOrgin.Where(x => x.DelDegree == 0).ToList();
                    qunarRequest.PolicyData.Add(UploadTypeDetail.IncrementalAdd, lstAddPolicies);
                    qunarRequest.PolicyData.Add(UploadTypeDetail.IncrementalDelete, lstDelPolicies);
                    context.SetRequest(qunarRequest);
                    Next.Invoke(context);
                }
                else
                {
                    OnMiddlewareWorking(new EventMsg {
                        Status = RunStatus.Normal, Msg = "当前政策为" + qunarRequest.PolicyDataOrgin.Count + "条,大于最高限制条数:" + upLoadCount + "条,开始分批上传.."
                    });
                    int index = 1;
                    while (qunarRequest.PolicyDataOrgin.Count > 0)
                    {
                        List <Policies> lstPolicies = new List <Policies>();
                        lstPolicies = qunarRequest.PolicyDataOrgin.Take(upLoadCount).ToList();//取一万条先上传
                        qunarRequest.UploadCount = lstPolicies.Count;
                        if (lstPolicies.Count > 0)
                        {
                            qunarRequest.PolicyDataOrgin.RemoveRange(0, lstPolicies.Count);
                        }
                        OnMiddlewareWorking(new EventMsg {
                            Status = RunStatus.Normal, Msg = "收到政策数量:" + lstPolicies.Count + "条,开始第" + index + "次分批上传"
                        });
                        List <Policies> lstAddPolicies = lstPolicies.Where(x => x.DelDegree == 1).ToList();
                        List <Policies> lstDelPolicies = lstPolicies.Where(x => x.DelDegree == 0).ToList();
                        PolicyRecord    rec            = new PolicyRecord()
                        {
                            LastPolicyId = lstPolicies.LastOrDefault().Id, LastUpdateTime = lstPolicies.LastOrDefault().UpdateTime
                        };
                        context.UploadResponse.BeforePolicyRecord = rec;                 //每次都保留上回更新的记录
                        qunarRequest.PolicyData.Remove(UploadTypeDetail.IncrementalAdd); //先移除后添加,防止key冲突
                        qunarRequest.PolicyData.Remove(UploadTypeDetail.IncrementalDelete);
                        qunarRequest.PolicyData.Add(UploadTypeDetail.IncrementalAdd, lstAddPolicies);
                        qunarRequest.PolicyData.Add(UploadTypeDetail.IncrementalDelete, lstDelPolicies);
                        context.SetRequest(qunarRequest);
                        if (index <= 1)
                        {
                            Next.Invoke(context);
                        }
                        else
                        {
                            //先判断是否上传成功
                            OnMiddlewareWorking(new EventMsg {
                                Status = RunStatus.Normal, Msg = "查询是否上传成功..."
                            });
                            bool flag = SearchNotifyStatus(context.UploadResponse.UploadStatusId);
                            if (flag)
                            {
                                OnMiddlewareWorking(new EventMsg {
                                    Status = RunStatus.Normal, Msg = "上传成功,自动进入下次上传..."
                                });
                                Next.Invoke(context);
                            }
                            else
                            {
                                while (!flag)
                                {
                                    Thread.Sleep(2000);//休息俩秒继续查询
                                    OnMiddlewareWorking(new EventMsg {
                                        Status = RunStatus.Normal, Msg = "上传中,继续查询是否上传成功..."
                                    });
                                    flag = SearchNotifyStatus(context.UploadResponse.UploadStatusId);
                                    if (flag)
                                    {
                                        flag = false;
                                        OnMiddlewareWorking(new EventMsg {
                                            Status = RunStatus.Normal, Msg = "上传成功,自动进入下次上传..."
                                        });
                                    }
                                }
                                Next.Invoke(context);
                            }
                        }

                        index++;
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                OnMiddlewareWorking(new EventMsg()
                {
                    Status = Enums.RunStatus.Exception, Msg = "QunarIncrementalDispatcherMiddleware:" + ex.Message, Exception = ex, PurchaserType = Enums.PurchaserType.Qunar
                });
                context.UploadResponse = new UploadPolicyResponse()
                {
                    ErrCode = ResultType.Failed, ErrMsg = "QunarIncrementalDispatcherMiddleware:" + ex.Message, Excption = ex
                };
                return;
            }
        }