K3_AnHui.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml;
  4. using CB.Common;
  5. using CB.Entity;
  6. using CB.Entity.Frequency;
  7. using CB.Interface.Infrastructure.Frequency;
  8. using CB.LotteryCatchData.Entity;
  9. using CB.LotteryCatchData.Interface;
  10. namespace CB.LotteryCatchData.Opencai
  11. {
  12. /// <summary>
  13. /// 湖南幸运赛车数据抓取实现
  14. /// </summary>
  15. public class K3_AnHui : CatchRepository, ICatchDataProvider
  16. {
  17. public override LotteryParamKeys GetLotteryParamKeys(string fileName)
  18. {
  19. return GetLotteryParamKeysDefault(fileName);
  20. }
  21. public override LotteryOpenCode GetLatestOpenCode()
  22. {
  23. return CB.Data.Frequency.K3AnHuiService.GetLatestOpenCodeForCatch();
  24. }
  25. public override IList<LotteryOpenCode> CatchData(LotteryConfigInfo config, LotteryParamKeys keys)
  26. {
  27. if (!this.IsCatchData(config, keys))
  28. return null;
  29. XmlDocument doc = new XmlDocument();
  30. try
  31. {
  32. doc.Load(config.DataUrl);
  33. var nodeList = doc.SelectNodes("xml/row");
  34. if (null == nodeList || 0 >= nodeList.Count)
  35. return null;
  36. IList<LotteryOpenCode> list = new List<LotteryOpenCode>();
  37. LotteryOpenCode entity = null;
  38. string qi = "";
  39. string[] data;
  40. foreach (XmlNode node in nodeList)
  41. {
  42. qi = node.Attributes["expect"].Value.Trim();
  43. if (0 <= keys.LocalTerm.CompareTo(qi))
  44. continue;
  45. data = node.Attributes["opencode"].Value.Trim().Split(',');
  46. entity = new LotteryOpenCode()
  47. {
  48. Term = long.Parse(qi)
  49. };
  50. entity.OpenCode = new List<int>();
  51. entity.OpenCode.Add(TypeConverter.StrToInt(data[0]));
  52. entity.OpenCode.Add(TypeConverter.StrToInt(data[1]));
  53. entity.OpenCode.Add(TypeConverter.StrToInt(data[2]));
  54. entity.Addtime = DateTime.Now;
  55. entity.OpenTime = GetRealOpenTime(config.StartTime, config.OpenPeriod, qi, TypeConverter.StrToDateTime(node.Attributes["opentime"].Value.Trim(), entity.Addtime), 8, 3);
  56. list.Add(entity);
  57. }
  58. return list;
  59. }
  60. catch (Exception ex)
  61. {
  62. throw ex;
  63. }
  64. }
  65. public override int SaveData(IList<LotteryOpenCode> list, ref LotteryParamKeys keys)
  66. {
  67. if (null == list || 0 >= list.Count)
  68. return -1;
  69. int n = 0;
  70. long term = Convert.ToInt64(keys.LocalTerm);
  71. DateTime t = keys.LastOpenTime;
  72. K3Info_AnHui entity = null;
  73. foreach (var item in list)
  74. {
  75. entity = new K3Info_AnHui()
  76. {
  77. Term = item.Term,
  78. OpenCode1 = item.OpenCode[0],
  79. OpenCode2 = item.OpenCode[1],
  80. OpenCode3 = item.OpenCode[2],
  81. OpenTime = item.OpenTime,
  82. Addtime = item.Addtime
  83. };
  84. if (CB.Data.Frequency.K3AnHuiService.Save(entity))
  85. {
  86. n++;
  87. if (term < item.Term)
  88. term = item.Term;
  89. if (t < item.OpenTime)
  90. t = item.OpenTime;
  91. }
  92. }
  93. if (0 < n)
  94. {
  95. keys.IsCatch = 1;
  96. keys.LocalTerm = term.ToString();
  97. keys.LastOpenTime = t;
  98. }
  99. return n;
  100. }
  101. }
  102. }