CatchData.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using CB.LotteryCatchData.Entity;
  4. using CB.LotteryCatchData.Interface;
  5. namespace CB.LotteryCatchData
  6. {
  7. public class CatchData
  8. {
  9. /// <summary>
  10. /// 彩票开奖数据抓取
  11. /// </summary>
  12. /// <param name="config"></param>
  13. public static void CatchLotteryData(LotteryConfigInfo config)
  14. {
  15. //实例化处理类
  16. var provider = CatchProvider.GetProvider(config.CatchDataProvider);
  17. //获取临时配置
  18. var keys = provider.GetLotteryParamKeys(config.GetParamKeyPath());
  19. if (string.IsNullOrEmpty(keys.LocalTerm) || "0" == keys.LocalTerm)
  20. {
  21. //数据库读取最新一期开奖信息
  22. keys.LocalTerm = "0";
  23. var entity = provider.GetLatestOpenCode();
  24. if (null != entity)
  25. {
  26. keys.LocalTerm = entity.Term.ToString();
  27. keys.LastOpenTime = entity.OpenTime;
  28. }
  29. }
  30. //抓取数据
  31. var list = provider.CatchData(config, keys);
  32. if (null != list && 0 < list.Count)
  33. {
  34. //保存数据
  35. var n = provider.SaveData(list, ref keys);
  36. CB.Common.FileUtil.WriteLog(config.Name + "--共抓取" + list.Count + "条有效数据,存储了" + n + "条!");
  37. //存储临时配置数据
  38. keys.Save(config.GetParamKeyPath());
  39. }
  40. }
  41. }
  42. }