protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //{"ext":"\"11\"","msg":"","result":"Exec successful,0/1 is error!ReplicateCount is1"}


                SortedDictionary <string, string> pams = GetRequestPost(Request.RequestContext.HttpContext.Request);
                // CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\Qunar\\" + System.Guid.NewGuid() + ".txt", JsonConvert.SerializeObject(pams));//创建文件   JsonConvert.SerializeObject(pams);
                string        result       = pams["result"] == null ? "" : pams["result"].ToString();
                SuccessStatus notifyResult = SuccessStatus.Other;
                bool          isSucess     = true;
                if (result.IndexOf("successful") > -1)
                {
                    isSucess     = true;
                    notifyResult = SuccessStatus.Success;
                }
                else
                {
                    isSucess     = false;
                    notifyResult = SuccessStatus.Failed;
                    CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\Qunar\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", JsonConvert.SerializeObject(pams));//创建文件
                }

                UpdateNotifyRequest request = new UpdateNotifyRequest()
                {
                    UpdateStatusId = pams["ext"] == null || string.IsNullOrEmpty(pams["ext"])? "0" : pams["ext"].ToString().Replace("\\", ""),
                    ResponseParams = JsonConvert.SerializeObject(pams),
                    NotifyResult   = notifyResult,
                    IsSucess       = isSucess
                };

                IPolicyNotify notify = new DefaultPolicyNotify();
                EmptyResponse res    = notify.UpdateNotify(request);
                if (res.ErrCode == PolicyService.Enums.ResultType.Failed)
                {
                    string log = DateTime.Now + ":回调内容:" + JsonConvert.SerializeObject(pams) + ",更新回调结果:" + JsonConvert.SerializeObject(res);
                    CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\Qunar\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", log);//创建文件
                    Response.Write("F");
                    //Response.End();
                }
                else
                {
                    Response.Write("S");
                }
                //Response.End();
            }
            catch (Exception ex)
            {
                CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\Qunar\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", JsonConvert.SerializeObject(ex));//创建文件
            }
        }
        public EmptyResponse UpdateNotify(UpdateNotifyRequest request)
        {
            try
            {
                UpLoadRecordLib       recLib       = new UpLoadRecordLib();
                UploadPolicyRecordLib recPolicyLib = new UploadPolicyRecordLib();
                PolicySyncRecLib      syncLib      = new PolicySyncRecLib();


                request.UpdateStatusId = request.UpdateStatusId.Replace("\"", "").Replace("\\", "");
                UpLoadRecord rec = recLib.GetModel(int.Parse(request.UpdateStatusId));
                if (rec == null)
                {
                    return(new EmptyResponse {
                        ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = "未找到此上传的记录!"
                    });
                }
                if (rec.OperName.ToLower() == "system")
                {
                    if ((SuccessStatus)request.NotifyResult == SuccessStatus.Success)
                    {
                        recPolicyLib.BlukyUpdatePolicy(rec.Id.ToString(), true);
                        recLib.Delete(rec.Id);//删除
                    }
                    else
                    {
                        recPolicyLib.BlukyUpdatePolicy(rec.Id.ToString(), false);
                        recLib.Delete(rec.Id);//删除
                    }
                    return(new EmptyResponse {
                        ErrCode = PolicyService.Enums.ResultType.Sucess
                    });
                }


                PurchaserType Purchaser = (PurchaserType)Enum.Parse(typeof(PurchaserType), rec.PurchaserType);
                UploadType    uType     = (UploadType)Enum.Parse(typeof(UploadType), rec.UploadType);

                #region 1.保存文件记录
                if (request.IsSucess)
                {
                    string timeAndId = Convert.ToDateTime(rec.LastUpdateTime).ToString("yyyy-MM-dd HH:mm:ss.fff") + "|" + rec.LastPolicyId.ToString();
                    // CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\" + System.Guid.NewGuid() + ".txt", "读取最后记录"+timeAndId);//创建文件
                    // File.WriteAllText("e://1.txt", timeAndId);
                    string name = uType == UploadType.FullUpload ? rec.PurchaserType + "\\" + rec.PurchaserType + "FullPolicyRecLog" : rec.PurchaserType + "\\" + rec.PurchaserType + "IncrementPolicyRecLog";
                    CoreHelper.SaveLastUpTimeAndId(timeAndId, name);
                    // CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\" + System.Guid.NewGuid() + ".txt", "保存最后记录成功");//创建文件
                }

                #endregion

                #region 2.更新表中记录

                rec.ResponseParams = request.ResponseParams;
                rec.NotifyResult   = (int)request.NotifyResult;
                rec.FailedCount    = request.NotifyResult == SuccessStatus.Failed ? rec.FailedCount + 1 : rec.FailedCount;
                rec.CompleteTime   = DateTime.Now;
                rec.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd") + " 0:00:00";
                rec.LastPolicyId   = "0";
                bool r = recLib.Update(rec);
                if (!r)
                {
                    return(new EmptyResponse {
                        ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = "更新记录失败!"
                    });
                }
                bool flag = false;
                if (request.NotifyResult == SuccessStatus.Failed || request.NotifyResult == SuccessStatus.Other)
                {
                    flag = false;
                }
                else
                {
                    flag = true;
                }
                recPolicyLib.BlukyUpdatePolicy(rec.Id.ToString(), flag);
                #endregion


                #region 3.批量更新已经上传完成的政策
                if (request.IsSucess)
                {
                    string selectSql  = "";
                    int    totalCount = 0;
                    List <UploadPolicyRecord> lstUploadIds   = recPolicyLib.GetModelList(" UId='" + rec.Id + "'");
                    List <string>             lstAddPolicies = new List <string>();
                    lstUploadIds.ForEach(x =>
                    {
                        lstAddPolicies.Add(x.PolicyId);
                    });
                    //List<string> lstAddPolicies = rec.Remark.Split(',').ToList();
                    if (lstAddPolicies.Count > 0)
                    {
                        bool r2 = syncLib.BlukyUpdatePolicyUploaded(lstAddPolicies);
                        if (!r)
                        {
                            return(new EmptyResponse {
                                ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = "批量把政策置为已上传失败!"
                            });
                        }
                    }
                }
                #endregion

                return(new EmptyResponse {
                    ErrCode = PolicyService.Enums.ResultType.Sucess
                });
            }
            catch (Exception ex)
            {
                return(new EmptyResponse {
                    ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = JsonConvert.SerializeObject(ex)
                });
            }
        }