/// <summary>克隆一份设置参数</summary> /// <param name="src"></param> /// <returns></returns> public static IExtractSetting Clone(this IExtractSetting src) { var set = new ExtractSetting(); set.Copy(src); return(set); }
/// <summary>抽取一批数据</summary> /// <returns></returns> public virtual IEntityList Fetch() { if (Field == null) { throw new ArgumentNullException(nameof(FieldName), "未指定用于顺序抽取数据的时间字段!"); } var set = Setting; if (set == null) { set = Setting = new ExtractSetting(); } if (!set.Enable) { return(null); } // 验证时间段 var start = set.Start; // 有步进且位于第一页时,重新计算最小时间 if (set.Step > 0 && set.Row == 0) { start = GetMinTime(start); } var now = DateTime.Now; if (start >= now) { return(null); } // 结束时间,必须是小于当前时间的有效值 var end = set.Step <= 0 ? DateTime.MaxValue : start.AddSeconds(set.Step); //var end = DateTime.MaxValue; // 结束时间有效时,设定末端边界 if (set.End > DateTime.MinValue && set.End < DateTime.MaxValue && set.End < end) { end = set.End; } // 区间无效 if (start >= end) { return(null); } BatchEnd = end; var size = set.BatchSize; if (size <= 0) { size = 1000; } // 分批获取数据,如果没有取到,则结束 var list = FetchData(start, end, set.Row, size); // 取到数据,需要滑动窗口 if (list.Count > 0) { var last = (DateTime)list.Last()[FieldName]; // 满一批,后续还有数据 if (list.Count >= size) { // 最大时间行数 var maxCount = list.Count(e => (DateTime)e[FieldName] == last); // 以最后时间为起点,跳过若干行。注意可能产生连续分页的情况 if (last == NextStart) { NextRow = set.Row + maxCount; } else { NextRow = maxCount; } NextStart = last; } else { NextStart = last.AddSeconds(1); NextRow = 0; } } else if (set.Step > 0) { NextStart = end; NextRow = 0; } return(list); }