private static void AnsyNetDataCatch(object data) { AnsyNetData adata = (AnsyNetData)data; DataCatchRequest dataCatch = adata.DataCatch; CacthConfig config = adata.Config; NotifyMessage notifyMsg = adata.NotifyMsg; SendDetailState detailState = new SendDetailState((msg) => { if (!(msg is ActionMessage)) { notifyMsg(config.User, new ActionMessage() { Message = msg.ToString() }); return; } notifyMsg(config.User, (ActionMessage)msg); }); if (config.IsCacthing != null && config.IsCacthing.Value) { detailState("之前的抓取正在进行"); return; } config.IsCacthing = true; try { detailState(string.Format("开始下载【{0}】到当前时间产生的订单", config.StartDate)); Thread.Sleep(2000);//停留2s List <HashMap> listData = dataCatch.GetDataList(config.StartDate, config.Cookies); ActionMessage action = new ActionMessage() { Action = ActionType.SendRequestData, Data = listData }; if (listData.Count != 0) { detailState(string.Format("成功下载{0}条主订单信息", listData.Count)); dataCatch.GetDetailsData(config.Cookies, listData, detailState); action.Message = string.Format("明细数据下载完成"); } detailState(action); config.IsCacthing = false; config.StartDate = config.ServerCurrentData; } catch (Exception t) { detailState(string.Format("错误消息:{0}", t.Message)); config.IsCacthing = false; } }
internal void GetDetailsData(string cookies, List <HashMap> billDataList, SendDetailState detailSetate = null) { if (string.IsNullOrEmpty(cookies)) { throw new Exception("请输入cookies"); } string user = GetUser(cookies); Dictionary <ulong, string> dictionary = new Dictionary <ulong, string>(); JsonSerializer serializer = JsonSerializer.CreateInstance(); for (int i = 0; i < billDataList.Count; i++) { IHashMap item = billDataList[i]; string status = item.Get <string>("status"); HashMap tempHash = serializer.Deserialize <HashMap>(item["content"].ToString()); if (tempHash == null) { continue; } ArrayList array = (ArrayList)((HashMap)tempHash["statusInfo"])["operations"]; foreach (HashMap aitem in array) { if (!"详情".Equals(aitem.Get <string>("text"))) { continue; } string url = string.Format("https:{0}", aitem.Get <string>("url")); string tbid = item.Get <string>("tbid"); HashMap detail = GetBillDetail(tbid, url, cookies, i + 1, billDataList.Count, detailSetate); //if (detail == null)//下载出错,直接移除 //{ // billDataList.RemoveAt(i); // i--; //} item.Add("detail", detail); break; } } }
private HashMap GetBillDetail(string tbid, string url, string cookies, int downedCount, int allCount, SendDetailState detailSetate = null) { Thread.Sleep(1000);//休眠1s BillManage bill = new BillManage(); string user = GetUser(cookies); HashMap detail = new HashMap(); try { detail.Add("tbid", tbid); detail.Add("content", bill.GetBillDetailByUrl(url, cookies)); detail.Add("user", user); if (detailSetate != null) { detailSetate(string.Format("【{3}】:总共有{0}条明细,已下载{1}条明细,还剩{2}条明细未下", allCount, downedCount, allCount - downedCount, user)); } } catch (Exception e) { if (detailSetate != null) { detailSetate(string.Format("【{1}】订单号【{2}】下载明细时出错:{0}", e.Message, user, tbid)); } return(null); } return(detail); }