FJ31X7Job.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using Quartz;
  7. using SCC.Common;
  8. using SCC.Models;
  9. using SCC.Interface;
  10. using Newtonsoft.Json;
  11. using HtmlAgilityPack;
  12. namespace SCC.Crawler.DT
  13. {
  14. /// <summary>
  15. /// 数据爬取类
  16. /// 福建31选7
  17. /// </summary>
  18. [DisallowConcurrentExecution]
  19. [PersistJobDataAfterExecution]
  20. public class FJ31X7Job : IJob
  21. {
  22. /// <summary>
  23. /// 构造函数
  24. /// </summary>
  25. public FJ31X7Job()
  26. {
  27. log = new LogHelper();
  28. services = IOC.Resolve<IDTOpenCode>();
  29. email = IOC.Resolve<IEmail>();
  30. }
  31. /// <summary>
  32. /// 作业执行入口
  33. /// </summary>
  34. /// <param name="context">作业执行上下文</param>
  35. public void Execute(IJobExecutionContext context)
  36. {
  37. Config = CommonHelper.GetConfigFromDataMap(context.JobDetail.JobDataMap);
  38. //预设节假日不开奖
  39. if (Config.SkipDate.Contains(CommonHelper.SCCSysDateTime.ToString("yyyyMMdd"))) return;
  40. LatestItem = context.JobDetail.JobDataMap["LatestItem"] as OpenCode8DTModel;
  41. try
  42. {
  43. //服务启动时配置初始数据
  44. if (LatestItem == null)
  45. {
  46. LatestItem = services.GetOpenCode8DTLastItem(currentLottery);
  47. if (LatestItem == null)
  48. {
  49. //服务第一次启动,数据库一条数据都没有时
  50. LatestItem = new OpenCode8DTModel()
  51. {
  52. Term = CommonHelper.GenerateQiHaoYYQQQ(0),
  53. OpenTime = new DateTime(CommonHelper.SCCSysDateTime.Year, 1, 1)
  54. };
  55. }
  56. }
  57. //程序时间第二天,程序根据配置检查是否昨天有开奖
  58. isGetData = false;
  59. if (CommonHelper.CheckDTIsNeedGetData(Config))
  60. {
  61. CheckingOpenDayTheLotteryData();
  62. }
  63. if (!LatestItem.Term.ToString().StartsWith(CommonHelper.SCCSysDateTime.ToString("yy")))
  64. {
  65. //翻年时
  66. LatestItem = new OpenCode8DTModel()
  67. {
  68. Term = CommonHelper.GenerateQiHaoYYQQQ(0),
  69. OpenTime = new DateTime(CommonHelper.SCCSysDateTime.Year, 1, 1)
  70. };
  71. }
  72. //当今日开奖并且当前时间是晚上8点过后开始抓取
  73. if (CommonHelper.CheckTodayIsOpenDay(Config) && CommonHelper.SCCSysDateTime.Hour > 12)
  74. {
  75. DoTodayJobByMainUrl();
  76. DoTodayJobByBackUrl();
  77. }
  78. if (isGetData)
  79. TrendChartHelper.GenerateFJ31X7TrendChart(log);
  80. }
  81. catch (Exception ex)
  82. {
  83. log.Error(typeof(FJ31X7Job), string.Format("【{0}】抓取时发生错误,错误信息【{1}】", Config.Area + Config.LotteryName, ex.Message));
  84. }
  85. //保存最新期号
  86. context.JobDetail.JobDataMap["LatestItem"] = LatestItem;
  87. }
  88. /// <summary>
  89. /// 自检爬取未爬取到的开奖数据,并对昨日开奖但未爬取到开奖数据的彩种添加邮件提醒
  90. /// </summary>
  91. private void CheckingOpenDayTheLotteryData()
  92. {
  93. //从数据库中获取昨天数据抓取失败列表
  94. FailedQiHaoList = services.GetFailedYYQQQList(currentLottery);
  95. if (FailedQiHaoList.Count > 0)
  96. {
  97. DoYesterdayFailedListByMainUrl();
  98. DoYesterdayFailedListByBackUrl();
  99. foreach (var fQiHao in FailedQiHaoList)
  100. {
  101. //将抓取失败数据推送至邮件列表,待邮件服务发送至配置管理员的邮箱中
  102. if (email.AddEmail(Config.Area + Config.LotteryName, fQiHao, CommonHelper.GenerateDTOpenTime(Config)))
  103. log.Error(typeof(FJ31X7Job), CommonHelper.GetJobLogError(Config, fQiHao));
  104. }
  105. }
  106. if (LatestItem.OpenTime.ToString("yyyyMMdd") != CommonHelper.SCCSysDateTime.AddDays(-1).ToString("yyyyMMdd"))
  107. {
  108. //开奖时间(昨天)未抓取到最新开奖数据,则再抓取一次,若还不成功则写入待发送邮件列表
  109. DoTodayJobByMainUrl();
  110. DoTodayJobByBackUrl();
  111. if (LatestItem.OpenTime.ToString("yyyyMMdd") != CommonHelper.SCCSysDateTime.AddDays(-1).ToString("yyyyMMdd"))
  112. {
  113. var openQiHao = (LatestItem.Term + 1).ToString();
  114. if (email.AddEmail(Config.Area + Config.LotteryName, openQiHao, CommonHelper.GenerateDTOpenTime(Config)))
  115. log.Error(typeof(FJ31X7Job), CommonHelper.GetJobLogError(Config, openQiHao));
  116. }
  117. }
  118. }
  119. /// <summary>
  120. /// 通过主站点爬取开奖数据
  121. /// (福建体彩网)
  122. /// </summary>
  123. private void DoTodayJobByMainUrl()
  124. {
  125. if (!string.IsNullOrEmpty(Config.MainUrl))
  126. {
  127. var OpenList = GetOpenListFromMainUrl();
  128. if (OpenList.Count == 0) return;//无抓取数据
  129. var newestQiHao = OpenList.First().Term.ToString();
  130. var startQiNum = Convert.ToInt32(LatestItem.Term.ToString().Substring(2)) + 1;
  131. var newestQiNum = Convert.ToInt32(newestQiHao.Substring(2));
  132. if (startQiNum > newestQiNum) return;//无最新数据
  133. //处理最新开奖数据
  134. string getQiHao = string.Empty;
  135. OpenCode8DTModel matchItem = null;
  136. for (var i = startQiNum; i <= newestQiNum; i++)
  137. {
  138. getQiHao = LatestItem.Term.ToString().Substring(0, 2) + i.ToString().PadLeft(3, '0');
  139. matchItem = OpenList.Where(R => R.Term.ToString() == getQiHao).FirstOrDefault();
  140. if (matchItem != null && services.AddDTOpen8Code(currentLottery, matchItem))
  141. {
  142. //Do Success Log
  143. log.Info(typeof(FJ31X7Job), CommonHelper.GetJobMainLogInfo(Config, getQiHao));
  144. LatestItem = matchItem;
  145. isGetData = true;
  146. }
  147. }
  148. }
  149. }
  150. /// <summary>
  151. /// 通过主站爬取错误期号列表中每一个期号
  152. /// (福建体彩网)
  153. /// </summary>
  154. private void DoYesterdayFailedListByMainUrl()
  155. {
  156. if (!string.IsNullOrEmpty(Config.MainUrl) && FailedQiHaoList.Count > 0)
  157. {
  158. var OpenList = GetOpenListFromMainUrl();
  159. if (OpenList.Count == 0) return;//无抓取数据
  160. OpenCode8DTModel matchItem = null;
  161. var SuccessList = new List<string>();
  162. foreach (string failedQiHao in FailedQiHaoList)
  163. {
  164. matchItem = OpenList.Where(R => R.Term.ToString() == failedQiHao).FirstOrDefault();
  165. if (matchItem != null && services.AddDTOpen8Code(currentLottery, matchItem))
  166. {
  167. //Do Success Log
  168. log.Info(typeof(FJ31X7Job), CommonHelper.GetJobMainLogInfo(Config, failedQiHao));
  169. if (matchItem.Term > LatestItem.Term)
  170. {
  171. LatestItem = matchItem;
  172. }
  173. isGetData = true;
  174. SuccessList.Add(failedQiHao);
  175. }
  176. }
  177. foreach (var successQiHao in SuccessList)
  178. {
  179. FailedQiHaoList.Remove(successQiHao);
  180. }
  181. }
  182. }
  183. /// <summary>
  184. /// 获取主站开奖列表数据
  185. /// </summary>
  186. /// <returns></returns>
  187. private List<OpenCode8DTModel> GetOpenListFromMainUrl()
  188. {
  189. List<OpenCode8DTModel> result = new List<OpenCode8DTModel>();
  190. try
  191. {
  192. var htmlResource = NetHelper.GetUrlResponse(Config.MainUrl + string.Format("&r={0}", new Random().Next(1000, 9999)));//只取第一页数据,最新5条记录
  193. if (!string.IsNullOrWhiteSpace(htmlResource))
  194. {
  195. HtmlDocument doc = new HtmlDocument();
  196. doc.LoadHtml(htmlResource);
  197. var divSections = doc.DocumentNode.SelectNodes("//div[@class='artCon KJDetail']").ToList();
  198. OpenCode8DTModel model = null;
  199. var lastYear = (CommonHelper.SCCSysDateTime.Year - 1).ToString().Substring(2);
  200. int Level1Num = 0, Level2Num = 0, Level3Num = 0, Level4Num = 0, Level5Num = 0, Level6Num = 0;
  201. decimal Level1Money = 0, Level2Money = 0, Level3Money = 0, Level4Money = 0, Level5Money = 0, Level6Money = 0, Sales = 0, Jackpot = 0;
  202. HtmlNode divSummary, divDetail, table, tbody;
  203. List<HtmlNode> divContent, divInfos, spans, trs, tds, divDetails, divTexts;
  204. string term = string.Empty, detailName = string.Empty, detailNum = string.Empty, detailMoney = string.Empty;
  205. string[] openCode = null;
  206. Regex reg = null;
  207. Match m = null;
  208. foreach (var divSection in divSections)
  209. {
  210. model = new OpenCode8DTModel();
  211. divInfos = divSection.ChildNodes.Where(N => N.Name.ToLower() == "div").ToList();
  212. if (divInfos.Count < 2) continue;
  213. divContent = divInfos[1].ChildNodes.Where(N => N.Name.ToLower() == "div").ToList();
  214. if (divContent.Count < 2) continue;
  215. divSummary = divContent[0];//概述
  216. divDetail = divContent[1];//详情
  217. spans = divSummary.ChildNodes.Where(N => N.Name.ToLower() == "strong").First().ChildNodes.Where(N => N.Name.ToLower() == "span").ToList();
  218. term = spans[0].InnerText;
  219. if (term.StartsWith(lastYear))
  220. {
  221. break;
  222. }
  223. model.Term = Convert.ToInt32(term);
  224. model.OpenTime = Convert.ToDateTime(spans[2].InnerText.Replace("年", "-").Replace("月", "-").Replace("日", string.Empty));
  225. openCode = (spans[3].InnerText + " " + spans[4].InnerText).Trim().Split(' ');
  226. model.OpenCode1 = Convert.ToInt32(openCode[0]);
  227. model.OpenCode2 = Convert.ToInt32(openCode[1]);
  228. model.OpenCode3 = Convert.ToInt32(openCode[2]);
  229. model.OpenCode4 = Convert.ToInt32(openCode[3]);
  230. model.OpenCode5 = Convert.ToInt32(openCode[4]);
  231. model.OpenCode6 = Convert.ToInt32(openCode[5]);
  232. model.OpenCode7 = Convert.ToInt32(openCode[6]);
  233. model.OpenCode8 = Convert.ToInt32(openCode[7]);
  234. Sales = Convert.ToDecimal(spans[1].InnerText);
  235. table = divDetail.ChildNodes.Where(N => N.Name.ToLower() == "table").FirstOrDefault();
  236. if (table == null)
  237. {
  238. divDetails = divDetail.ChildNodes.Where(N => N.Name.ToLower() == "div").ToList();
  239. if (divDetails.Count < 14) continue;
  240. for (var i = 4; i < 12; i++)
  241. {
  242. divTexts = divDetails[i].ChildNodes.Where(N => N.Name.ToLower() == "#text").ToList();
  243. if (divTexts.Count < 4) continue;
  244. detailName = divTexts[0].InnerText.Replace("&nbsp;", string.Empty).Trim();
  245. detailNum = divTexts[1].InnerText.Replace("&nbsp;", string.Empty).Replace("注", string.Empty).Trim();
  246. detailMoney = divTexts[2].InnerText.Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Replace("元", string.Empty).Trim();
  247. if (detailName == "一等奖")
  248. {
  249. Level1Num = Convert.ToInt32(detailNum);
  250. Level1Money = Convert.ToDecimal(detailMoney);
  251. }
  252. else if (detailName == "二等奖")
  253. {
  254. Level2Num = Convert.ToInt32(detailNum);
  255. Level2Money = Convert.ToDecimal(detailMoney);
  256. }
  257. else if (detailName == "三等奖")
  258. {
  259. Level3Num = Convert.ToInt32(detailNum);
  260. Level3Money = Convert.ToDecimal(detailMoney);
  261. }
  262. else if (detailName == "四等奖")
  263. {
  264. Level4Num = Convert.ToInt32(detailNum);
  265. Level4Money = Convert.ToDecimal(detailMoney);
  266. }
  267. else if (detailName == "五等奖")
  268. {
  269. Level5Num = Convert.ToInt32(detailNum);
  270. Level5Money = Convert.ToDecimal(detailMoney);
  271. }
  272. else if (detailName == "六等奖")
  273. {
  274. Level6Num = Convert.ToInt32(detailNum);
  275. Level6Money = Convert.ToDecimal(detailMoney);
  276. }
  277. }
  278. }
  279. else
  280. {
  281. tbody = table.ChildNodes.Where(N => N.Name.ToLower() == "tbody").FirstOrDefault();
  282. if (tbody == null) continue;
  283. trs = tbody.ChildNodes.Where(N => N.Name.ToLower() == "tr").ToList();
  284. for (var i = 4; i < trs.Count; i++)//第一二三四行是表头
  285. {
  286. tds = trs[i].ChildNodes.Where(N => N.Name.ToLower() == "td").ToList();
  287. if (tds.Count < 4) continue;
  288. if (tds[0].InnerText.Trim() == "一等奖")
  289. {
  290. Level1Num = Convert.ToInt32(tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Trim());
  291. Level1Money = Convert.ToDecimal(tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty).Trim());
  292. }
  293. else if (tds[0].InnerText.Trim() == "二等奖")
  294. {
  295. Level2Num = Convert.ToInt32(tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Trim());
  296. Level2Money = Convert.ToDecimal(tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty).Trim());
  297. }
  298. else if (tds[0].InnerText.Trim() == "三等奖")
  299. {
  300. Level3Num = Convert.ToInt32(tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Trim());
  301. Level3Money = Convert.ToDecimal(tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty).Trim());
  302. }
  303. else if (tds[0].InnerText.Trim() == "四等奖")
  304. {
  305. Level4Num = Convert.ToInt32(tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Trim());
  306. Level4Money = Convert.ToDecimal(tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty).Trim());
  307. }
  308. else if (tds[0].InnerText.Trim() == "五等奖")
  309. {
  310. Level5Num = Convert.ToInt32(tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Trim());
  311. Level5Money = Convert.ToDecimal(tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty).Trim());
  312. }
  313. else if (tds[0].InnerText.Trim() == "六等奖")
  314. {
  315. Level6Num = Convert.ToInt32(tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Trim());
  316. Level6Money = Convert.ToDecimal(tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty).Trim());
  317. }
  318. }
  319. }
  320. //抓取奖池累计数据
  321. reg = new Regex(@"([\d,.]*?)元奖金滚入下期奖池");
  322. m = reg.Match(divSection.InnerHtml);
  323. if (m.Success)
  324. Jackpot = Convert.ToDecimal(m.Result("$1"));
  325. model.Detail = string.Format("{0},{1}^一等奖|{2}|{3},二等奖|{4}|{5},三等奖|{6}|{7},四等奖|{8}|{9},五等奖|{10}|{11},六等奖|{12}|{13}",
  326. Sales, Jackpot, Level1Num, Level1Money, Level2Num, Level2Money, Level3Num, Level3Money, Level4Num,
  327. Level4Money, Level5Num, Level5Money, Level6Num, Level6Money);
  328. result.Add(model);
  329. }
  330. }
  331. result = result.OrderByDescending(S => S.Term).ToList();
  332. }
  333. catch (Exception ex)
  334. {
  335. log.Error(typeof(FJ31X7Job), string.Format("【{0}】通过主站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + Config.LotteryName, ex.Message));
  336. }
  337. return result;
  338. }
  339. /// <summary>
  340. /// 通过备用站点抓取开奖数据
  341. /// (彩票两元网)
  342. /// </summary>
  343. private void DoTodayJobByBackUrl()
  344. {
  345. if (!string.IsNullOrEmpty(Config.BackUrl))
  346. {
  347. var OpenList = GetOpenListFromBackUrl();
  348. if (OpenList.Count == 0) return;//无抓取数据
  349. var newestQiHao = OpenList.First().Term.ToString();
  350. var startQiNum = Convert.ToInt32(LatestItem.Term.ToString().Substring(2)) + 1;
  351. var newestQiNum = Convert.ToInt32(newestQiHao.Substring(2));
  352. if (startQiNum > newestQiNum) return;//无最新数据
  353. //处理最新开奖数据
  354. var getQiHao = string.Empty;
  355. OpenCode8DTModel matchItem = null;
  356. for (var i = startQiNum; i <= newestQiNum; i++)
  357. {
  358. getQiHao = LatestItem.Term.ToString().Substring(0, 2) + i.ToString().PadLeft(3, '0');
  359. matchItem = OpenList.Where(R => R.Term.ToString() == getQiHao).FirstOrDefault();
  360. if (matchItem != null && OptimizeBackModel(ref matchItem) && services.AddDTOpen8Code(currentLottery, matchItem))
  361. {
  362. //Do Success Log
  363. log.Info(typeof(FJ31X7Job), CommonHelper.GetJobBackLogInfo(Config, getQiHao));
  364. LatestItem = matchItem;
  365. isGetData = true;
  366. }
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// 通过备用地址抓取错误期号列表中每一个期号
  372. /// (彩票两元网)
  373. /// </summary>
  374. private void DoYesterdayFailedListByBackUrl()
  375. {
  376. if (!string.IsNullOrEmpty(Config.BackUrl) && FailedQiHaoList.Count > 0)
  377. {
  378. var OpenList = GetOpenListFromBackUrl();
  379. if (OpenList.Count == 0) return;//无抓取数据
  380. OpenCode8DTModel matchItem = null;
  381. var SuccessList = new List<string>();
  382. foreach (string failedQiHao in FailedQiHaoList)
  383. {
  384. matchItem = OpenList.Where(R => R.Term.ToString() == failedQiHao).FirstOrDefault();
  385. if (matchItem != null && OptimizeBackModel(ref matchItem) && services.AddDTOpen8Code(currentLottery, matchItem))
  386. {
  387. //Do Success Log
  388. log.Info(typeof(FJ31X7Job), CommonHelper.GetJobBackLogInfo(Config, failedQiHao));
  389. if (matchItem.Term > LatestItem.Term)
  390. {
  391. LatestItem = matchItem;
  392. }
  393. SuccessList.Add(failedQiHao);
  394. isGetData = true;
  395. }
  396. }
  397. foreach (var successQiHao in SuccessList)
  398. {
  399. FailedQiHaoList.Remove(successQiHao);
  400. }
  401. }
  402. }
  403. /// <summary>
  404. /// 获取备用站点开奖列表数据
  405. /// </summary>
  406. /// <returns></returns>
  407. private List<OpenCode8DTModel> GetOpenListFromBackUrl()
  408. {
  409. List<OpenCode8DTModel> result = new List<OpenCode8DTModel>();
  410. try
  411. {
  412. Uri url = new Uri(Config.BackUrl);
  413. var htmlResource = NetHelper.GetUrlResponse(Config.BackUrl, Encoding.GetEncoding("gb2312"));
  414. if (string.IsNullOrWhiteSpace(htmlResource)) return result;
  415. HtmlDocument doc = new HtmlDocument();
  416. doc.LoadHtml(htmlResource);
  417. var table = doc.DocumentNode.SelectSingleNode("//table");
  418. if (table == null) return result;
  419. var trs = table.ChildNodes.Where(node => node.Name == "tr").ToList();
  420. OpenCode8DTModel model = null;
  421. HtmlNode nodeA = null;
  422. string optimizeUrl = string.Empty, term = string.Empty;
  423. for (var i = 2; i < trs.Count; i++)//第一二行为表头
  424. {
  425. var trstyle = trs[i].Attributes["style"];
  426. if (trstyle != null && trstyle.Value == "display:none")
  427. {
  428. continue;
  429. }
  430. var tds = trs[i].ChildNodes.Where(node => node.Name == "td").ToList();
  431. if (tds.Count < 10) continue;
  432. model = new OpenCode8DTModel();
  433. nodeA = tds[0].ChildNodes.Where(n => n.Name == "a").FirstOrDefault();
  434. if (nodeA == null) continue;
  435. term = nodeA.InnerText.Trim().Substring(2);
  436. if (!term.StartsWith(CommonHelper.SCCSysDateTime.ToString("yy"))) break;
  437. model.Term = Convert.ToInt64(term);
  438. optimizeUrl = nodeA.Attributes["href"].Value;
  439. model.DetailUrl = new Uri(url, optimizeUrl).AbsoluteUri;
  440. model.OpenTime = Convert.ToDateTime(tds[9].InnerText);
  441. if (tds[1].ChildNodes.Count == 0) continue;
  442. var opencodeNode = tds[1].ChildNodes.Where(n => n.Name.ToLower() == "i").ToList();
  443. if (opencodeNode.Count < 8) continue;
  444. model.OpenCode1 = Convert.ToInt32(opencodeNode[0].InnerText.Trim());
  445. model.OpenCode2 = Convert.ToInt32(opencodeNode[1].InnerText.Trim());
  446. model.OpenCode3 = Convert.ToInt32(opencodeNode[2].InnerText.Trim());
  447. model.OpenCode4 = Convert.ToInt32(opencodeNode[3].InnerText.Trim());
  448. model.OpenCode5 = Convert.ToInt32(opencodeNode[4].InnerText.Trim());
  449. model.OpenCode6 = Convert.ToInt32(opencodeNode[5].InnerText.Trim());
  450. model.OpenCode7 = Convert.ToInt32(opencodeNode[6].InnerText.Trim());
  451. model.OpenCode8 = Convert.ToInt32(opencodeNode[7].InnerText.Trim());
  452. result.Add(model);
  453. }
  454. result = result.OrderByDescending(S => S.Term).ToList();
  455. }
  456. catch (Exception ex)
  457. {
  458. log.Error(typeof(FJ31X7Job), string.Format("【{0}】通过备用站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + Config.LotteryName, ex.Message));
  459. }
  460. return result;
  461. }
  462. /// <summary>
  463. /// 完善备用站点福建31选7开奖实体信息
  464. /// </summary>
  465. /// <param name="model"></param>
  466. private bool OptimizeBackModel(ref OpenCode8DTModel model)
  467. {
  468. try
  469. {
  470. var htmlResource = NetHelper.GetUrlResponse(model.DetailUrl, Encoding.GetEncoding("gb2312"));
  471. if (string.IsNullOrWhiteSpace(htmlResource)) return false;
  472. HtmlDocument doc = new HtmlDocument();
  473. doc.LoadHtml(htmlResource);
  474. var table = doc.DocumentNode.SelectSingleNode("//table");
  475. if (table == null) return false;
  476. var trs = table.ChildNodes.Where(N => N.Name.ToLower() == "tr").ToList();
  477. List<HtmlNode> tds = null;
  478. int Level1Num = 0, Level2Num = 0, Level3Num = 0, Level4Num = 0, Level5Num = 0, Level6Num = 0;
  479. decimal Level1Money = 0, Level2Money = 0, Level3Money = 0, Level4Money = 0, Level5Money = 0, Level6Money = 0, Sales = 0, Jackpot = 0;
  480. for (var i = 1; i < trs.Count; i++)//第一行为表头
  481. {
  482. tds = trs[i].ChildNodes.Where(N => N.Name.ToLower() == "td").ToList();
  483. if (tds.Count < 5) continue;
  484. if (tds[1].InnerText == "一等奖")
  485. {
  486. Level1Num = Convert.ToInt32(tds[2].InnerText.Replace("注", string.Empty));
  487. Level1Money = Convert.ToDecimal(tds[3].InnerText);
  488. }
  489. if (tds[1].InnerText == "二等奖")
  490. {
  491. Level2Num = Convert.ToInt32(tds[2].InnerText.Replace("注", string.Empty));
  492. Level2Money = Convert.ToDecimal(tds[3].InnerText);
  493. }
  494. if (tds[1].InnerText == "三等奖")
  495. {
  496. Level3Num = Convert.ToInt32(tds[2].InnerText.Replace("注", string.Empty));
  497. Level3Money = Convert.ToDecimal(tds[3].InnerText);
  498. }
  499. if (tds[1].InnerText == "四等奖")
  500. {
  501. Level4Num = Convert.ToInt32(tds[2].InnerText.Replace("注", string.Empty));
  502. Level4Money = Convert.ToDecimal(tds[3].InnerText);
  503. }
  504. if (tds[1].InnerText == "五等奖")
  505. {
  506. Level5Num = Convert.ToInt32(tds[2].InnerText.Replace("注", string.Empty));
  507. Level5Money = Convert.ToDecimal(tds[3].InnerText);
  508. }
  509. if (tds[1].InnerText == "六等奖")
  510. {
  511. Level6Num = Convert.ToInt32(tds[2].InnerText.Replace("注", string.Empty));
  512. Level6Money = Convert.ToDecimal(tds[3].InnerText);
  513. }
  514. }
  515. Regex reg = new Regex(@"本期投注总额:([\d.,]*?)元");
  516. var match = reg.Match(htmlResource);
  517. if (match.Success)
  518. {
  519. Sales = Convert.ToDecimal(match.Result("$1").Replace(",", string.Empty));
  520. }
  521. reg = new Regex(@"奖池资金累计金额:([\d.,]*?)元");
  522. match = reg.Match(htmlResource);
  523. if (match.Success)
  524. {
  525. Jackpot = Convert.ToDecimal(match.Result("$1").Replace(",", string.Empty));
  526. }
  527. model.Detail = string.Format("{0},{1}^一等奖|{2}|{3},二等奖|{4}|{5},三等奖|{6}|{7},四等奖|{8}|{9},五等奖|{10}|{11},六等奖|{12}|{13}",
  528. Sales, Jackpot, Level1Num, Level1Money, Level2Num, Level2Money, Level3Num, Level3Money, Level4Num,
  529. Level4Money, Level5Num, Level5Money, Level6Num, Level6Money);
  530. return true;
  531. }
  532. catch (Exception ex)
  533. {
  534. log.Error(typeof(FJ31X7Job), string.Format("【{0}】通过备用站点优化开奖列表时发生错误,错误信息【{1}】", Config.Area + Config.LotteryName, ex.Message));
  535. }
  536. return false;
  537. }
  538. #region Attribute
  539. /// <summary>
  540. /// 配置信息
  541. /// </summary>
  542. private SCCConfig Config = null;
  543. /// <summary>
  544. /// 当天抓取的最新一期开奖记录
  545. /// </summary>
  546. private OpenCode8DTModel LatestItem = null;
  547. /// <summary>
  548. /// 当天抓取失败列表
  549. /// </summary>
  550. private List<string> FailedQiHaoList = null;
  551. /// <summary>
  552. /// 日志对象
  553. /// </summary>
  554. private LogHelper log = null;
  555. /// <summary>
  556. /// 数据服务
  557. /// </summary>
  558. private IDTOpenCode services = null;
  559. /// <summary>
  560. /// 当前彩种
  561. /// </summary>
  562. private SCCLottery currentLottery
  563. {
  564. get
  565. {
  566. return SCCLottery.FJ31X7;
  567. }
  568. }
  569. /// <summary>
  570. /// 邮件接口
  571. /// </summary>
  572. private IEmail email = null;
  573. /// <summary>
  574. /// 是否本次运行抓取到开奖数据
  575. /// </summary>
  576. private bool isGetData = false;
  577. #endregion
  578. }
  579. }