KL8_BeiJing.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 KL8_BeiJing : 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.KL8BeiJingService.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(new char[] { ',', '+' });
  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.OpenCode.Add(TypeConverter.StrToInt(data[3]));
  55. entity.OpenCode.Add(TypeConverter.StrToInt(data[4]));
  56. entity.OpenCode.Add(TypeConverter.StrToInt(data[5]));
  57. entity.OpenCode.Add(TypeConverter.StrToInt(data[6]));
  58. entity.OpenCode.Add(TypeConverter.StrToInt(data[7]));
  59. entity.OpenCode.Add(TypeConverter.StrToInt(data[8]));
  60. entity.OpenCode.Add(TypeConverter.StrToInt(data[9]));
  61. entity.OpenCode.Add(TypeConverter.StrToInt(data[10]));
  62. entity.OpenCode.Add(TypeConverter.StrToInt(data[11]));
  63. entity.OpenCode.Add(TypeConverter.StrToInt(data[12]));
  64. entity.OpenCode.Add(TypeConverter.StrToInt(data[13]));
  65. entity.OpenCode.Add(TypeConverter.StrToInt(data[14]));
  66. entity.OpenCode.Add(TypeConverter.StrToInt(data[15]));
  67. entity.OpenCode.Add(TypeConverter.StrToInt(data[16]));
  68. entity.OpenCode.Add(TypeConverter.StrToInt(data[17]));
  69. entity.OpenCode.Add(TypeConverter.StrToInt(data[18]));
  70. entity.OpenCode.Add(TypeConverter.StrToInt(data[19]));
  71. entity.OpenCode.Add(TypeConverter.StrToInt(data[20]));
  72. entity.Addtime = DateTime.Now;
  73. entity.OpenTime = GetRealOpenTime(config.StartTime, config.OpenPeriod, qi, TypeConverter.StrToDateTime(node.Attributes["opentime"].Value.Trim(), entity.Addtime), 8, 2);
  74. list.Add(entity);
  75. }
  76. return list;
  77. }
  78. catch (Exception ex)
  79. {
  80. throw ex;
  81. }
  82. }
  83. public override int SaveData(IList<LotteryOpenCode> list, ref LotteryParamKeys keys)
  84. {
  85. if (null == list || 0 >= list.Count)
  86. return -1;
  87. int n = 0;
  88. long term = Convert.ToInt64(keys.LocalTerm);
  89. DateTime t = keys.LastOpenTime;
  90. KL8Info_BeiJing entity = null;
  91. foreach (var item in list)
  92. {
  93. entity = new KL8Info_BeiJing()
  94. {
  95. Term = item.Term,
  96. OpenCode1 = item.OpenCode[0],
  97. OpenCode2 = item.OpenCode[1],
  98. OpenCode3 = item.OpenCode[2],
  99. OpenCode4 = item.OpenCode[3],
  100. OpenCode5 = item.OpenCode[4],
  101. OpenCode6 = item.OpenCode[5],
  102. OpenCode7 = item.OpenCode[6],
  103. OpenCode8 = item.OpenCode[7],
  104. OpenCode9 = item.OpenCode[8],
  105. OpenCode10 = item.OpenCode[9],
  106. OpenCode11 = item.OpenCode[10],
  107. OpenCode12 = item.OpenCode[11],
  108. OpenCode13 = item.OpenCode[12],
  109. OpenCode14 = item.OpenCode[13],
  110. OpenCode15 = item.OpenCode[14],
  111. OpenCode16 = item.OpenCode[15],
  112. OpenCode17 = item.OpenCode[16],
  113. OpenCode18 = item.OpenCode[17],
  114. OpenCode19 = item.OpenCode[18],
  115. OpenCode20 = item.OpenCode[19],
  116. OpenCode21 = item.OpenCode[20],
  117. OpenTime = item.OpenTime,
  118. Addtime = item.Addtime
  119. };
  120. if (CB.Data.Frequency.KL8BeiJingService.Save(entity))
  121. {
  122. n++;
  123. if (term < item.Term)
  124. term = item.Term;
  125. if (t < item.OpenTime)
  126. t = item.OpenTime;
  127. }
  128. }
  129. if (0 < n)
  130. {
  131. keys.IsCatch = 1;
  132. keys.LocalTerm = term.ToString();
  133. keys.LastOpenTime = t;
  134. }
  135. return n;
  136. }
  137. protected override DateTime GetRealOpenTime(TimeSpan startTime, int openPeriod, string localTerm, DateTime openTime, int startIndex, int length)
  138. {
  139. return openTime;
  140. }
  141. }
  142. }