private void MonthCarNoRepeatPost(RequestParam param) { var strParam = JsonConvert.SerializeObject(param); while (true) { string result = HttpPost(_passCarHttp, strParam); if (string.IsNullOrEmpty(result)) { logger.Info("result is null,break while."); } else { var resultList = JsonConvert.DeserializeObject <ResultList>(result); if (resultList.Code != "0") { logger.Info("result is wrong!"); logger.Info(result); break; } if (resultList.MonthCarResult != null) { monthCarList.AddRange(resultList.MonthCarResult); } if (resultList.MonthCarResult == null || resultList.MonthCarResult.Count < _limit) { break; } Thread.Sleep(500); } } }
/// <summary> /// 定时触发事件 /// 在时间段内返回的数据不重复 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RollingNoRepeatModel_Elapse(object sender, ElapsedEventArgs e) { try { DateTime now = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"); if (_lastCheckTime < now.AddDays(-1)) { passCarList.Clear(); monthCarList.Clear(); //请求参数处理 RequestParam param = new RequestParam(); param.parkingCode = _parkingCode; param.retLimit = _limit.ToString(); param.startTime = _lastCheckTime.ToString("yyyy-MM-dd") + " 00:00:00"; param.endTime = _lastCheckTime.ToString("yyyy-MM-dd") + " 23:59:59"; param.requestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); param.signature = FormsAuthentication.HashPasswordForStoringInConfigFile(string.Format("endTime={0}&" + "parkingCode={1}&" + "requestTime={2}&" + "retLimit={3}&" + "startTime={4}&{5}", param.endTime, param.parkingCode, param.requestTime, param.retLimit, param.startTime, _md5Key), "MD5"); //处理过车 DeserializablePassCar(); PassCarNoRepeatPost(param); //处理月租车 DeserializableMonthCar(); MonthCarNoRepeatPost(param); //生成订单 } } catch (Exception ex) { logger.Debug(ex.ToString()); } finally { if (passCarList.Count > 0) { SerializablePassCar(); } if (monthCarList.Count > 0) { SerializableMonthCar(); } } }
/// <summary> /// 定时触发事件 /// 在时间段内返回的数据重复 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RollingRepeatModel_Elapse(object sender, ElapsedEventArgs e) { try { if (_lastCheckTime < DateTime.Now.AddDays(-2) && isRun == false) { isRun = true; passCarList = new List <Op_PassCar>(); monthCarList = new List <Op_MonthCar>(); DateTime startTime = _lastCheckTime; DateTime endTime = _lastCheckTime.AddDays(1).AddSeconds(-1); int count = 0; logger.Info(string.Format("本次同步开始【开始时间:{0};结束时间:{1}】...", startTime, endTime)); //数据同步 while (startTime < endTime) { //请求参数处理 DateTime tempTime = startTime.AddSeconds(_passSeconds); if (tempTime >= endTime) { tempTime = endTime; } logger.Info(string.Format("开始第{0}次数据请求,", ++count)); RequestParam param = new RequestParam(); param.parkingCode = _parkingCode; param.retLimit = _limit.ToString(); param.startTime = startTime.ToString("yyyy-MM-dd HH:mm:ss"); param.endTime = tempTime.ToString("yyyy-MM-dd HH:mm:ss"); param.requestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); param.signature = FormsAuthentication.HashPasswordForStoringInConfigFile(string.Format("endTime={0}&" + "parkingCode={1}&" + "requestTime={2}&" + "retLimit={3}&" + "startTime={4}&{5}", param.endTime, param.parkingCode, param.requestTime, param.retLimit, param.startTime, _md5Key), "MD5").ToLower(); var strParam = JsonConvert.SerializeObject(param); logger.Info(string.Format("请求过车数据,开始时间:{0}-结束时间:{1}", startTime, tempTime)); PassCarRepeatPost(strParam); logger.Info(string.Format("请求月租数据,开始时间:{0}-结束时间:{1}", startTime, tempTime)); MonthCarRepeatPost(strParam); startTime = tempTime.AddMilliseconds(1); Thread.Sleep(500); } logger.Info("同步完成,处理数据..."); //同步完成 DorllyOrderModel model = new DorllyOrderModel(); logger.Info(string.Format("原始数据处理...【过车数据{0}条,月租充值{1}条】", passCarList.Count(), monthCarList.Count)); //保存原始数据 passCarList = passCarList.GroupBy(a => a.UniqueID).Select(a => a.First()).ToList(); foreach (var item in passCarList) { model.Op_PassCar.AddOrUpdate(item); } monthCarList = monthCarList.GroupBy(a => a.CarNo).Select(a => a.First()).ToList(); foreach (var item in monthCarList) { model.Op_MonthCar.AddOrUpdate(item); } logger.Info("订单数据处理..."); string orderID = Guid.NewGuid().ToString(); decimal rateAmount = AddOrderDetail(orderID, passCarList, monthCarList, model); //订单明细填充 AddOrderHeader(orderID, rateAmount, passCarList, monthCarList, model); //订单主体填充 logger.Info("数据提交..."); model.SaveChanges(); logger.Info("配置处理..."); _lastCheckTime = endTime.AddSeconds(1); //ConfigurationManager.AppSettings.Set("LastCheckTime", _lastCheckTime.ToString("yyyy-MM-dd HH:mm:ss")); //ConfigurationManager.RefreshSection("appSettings"); Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["LastCheckTime"].Value = _lastCheckTime.ToString("yyyy-MM-dd HH:mm:ss"); config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); passCarList.Clear(); monthCarList.Clear(); logger.Info("处理结束,将进行下一次同步!"); //this.Stop(); isRun = false; } } catch (Exception ex) { logger.Debug("本次同步异常,详情见下面异常描述,等待下次同步!"); logger.Debug(ex.ToString()); logger.Debug(ex.InnerException.Message); isRun = false; //this.Stop(); } }