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 static List <Policies> SplitPolicy(PurchaserType pType, List <Policies> lstPolicies, List <string> lstQunarCodes, PoliciesType policyType) { SplitPolicyResponse splitResponse = new SplitPolicyResponse(); int maxArrCityCount = 25; int maxDptCityCount = 1; int maxFlightInCount = 25; int splitMaxTaskCount = 10; int splitPerTaskMaxCount = 50; int maxSeatCount = 29; switch (policyType) { case PoliciesType.COMMON: //普通政策 break; case PoliciesType.CUSTOMER: //包机切位政策 break; case PoliciesType.LOWPRICE: //特价政策 break; case PoliciesType.PREPAY: //预付政策 { maxSeatCount = 1; maxArrCityCount = 1; } break; case PoliciesType.ROUNDALL: //往返所有类型政策 break; case PoliciesType.ROUNDPREPAY: //往返预付政策 break; case PoliciesType.ROUNDSPECIAL: //往返特价政策 break; case PoliciesType.SINGLEALL: //单程所有类型政策 break; case PoliciesType.APPLY: //申请政策 break; default: break; } switch (pType) { case PurchaserType.Qunar: { QunarSplitPolicyRequest splitQunarRequst = new QunarSplitPolicyRequest() { MaxArrCityCount = maxArrCityCount, //最大支持出发城市个数 MaxDptCityCount = maxDptCityCount, //最大支持出发城市个数 MaxFlightInCount = maxFlightInCount, //包含航班最大个数 SplitMaxTaskCount = splitMaxTaskCount, //最大可开启任务数量 SplitPerTaskMaxCount = splitPerTaskMaxCount, //每个task处理的数量 StorageMaxTaskCount = 10, //最多可开启存储的线程 StoragePerTaskMaxCount = 1000, //每个存储线程最多可处理的数量 MaxSeatCount = maxSeatCount, Purchaser = PurchaserType.Qunar, //供应商类型 Policies = lstPolicies, //政策数据 LstQunarCodes = lstQunarCodes, PolicyType = policyType }; IPolicySplit policySplit = new QunarPolicySplit(); //去哪儿拆分政策 //拆分政策 splitResponse = policySplit.PolicySplit(splitQunarRequst); if (splitResponse.ErrCode == ResultType.Failed) { // MessageBox.Show("拆分政策失败:" + splitResponse.ErrMsg); return(new List <Policies>()); } } break; case PurchaserType.TaoBao: break; default: break; } return(splitResponse.PoliciesData); }