AutoAddNewestLotteryManager.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using System;
  2. using System.ComponentModel;
  3. using System.Text;
  4. using Lottomat.Application.Busines.LotteryNumberManage;
  5. using Lottomat.Application.Busines.OpenCodeManage;
  6. using Lottomat.Application.Code;
  7. using Lottomat.Application.Entity.CommonEntity;
  8. using Lottomat.Application.SystemAutoJob.Interface;
  9. using Lottomat.Util;
  10. using Lottomat.Util.Extension;
  11. using Lottomat.Utils;
  12. namespace Lottomat.Application.SystemAutoJob
  13. {
  14. /// <summary>
  15. /// 自动添加一条最新开奖信息,无开奖号
  16. /// </summary>
  17. public class AutoAddNewestLotteryManager : ISchedulerJob
  18. {
  19. /// <summary>
  20. /// 对象锁
  21. /// </summary>
  22. private static readonly object _lock = new object();
  23. private static QGFC3DBLL qgfc3Dbll = new QGFC3DBLL();
  24. private static Open3CodeBLL open3CodeBll = new Open3CodeBLL();
  25. private static Open4CodeBLL open4CodeBll = new Open4CodeBLL();
  26. private static Open5CodeBLL open5CodeBll = new Open5CodeBLL();
  27. private static Open7CodeBLL open7CodeBll = new Open7CodeBLL();
  28. private static Open8CodeBLL open8CodeBll = new Open8CodeBLL();
  29. private static Open10CodeBLL open10CodeBll = new Open10CodeBLL();
  30. private static Open21CodeBLL open21CodeBll = new Open21CodeBLL();
  31. /// <summary>
  32. /// 入口程序
  33. /// </summary>
  34. public void Execute()
  35. {
  36. lock (_lock)
  37. {
  38. DoSomething();
  39. }
  40. }
  41. /// <summary>
  42. /// 真正操作逻辑
  43. /// </summary>
  44. private void DoSomething()
  45. {
  46. string config = ConfigHelper.GetValue("AutoAddNewestLottery");
  47. if (!string.IsNullOrEmpty(config))
  48. {
  49. string[] arr = config.Split(",".ToCharArray());
  50. foreach (string s in arr)
  51. {
  52. bool isSucc = Enum.TryParse<SCCLottery>(s, true, out SCCLottery type);
  53. //SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), arg.EnumCode, true);
  54. if (!isSucc) continue;
  55. //官网最新期数
  56. string latestaward = GrabTheLatestAwardManager.GetTheLatestAward(type);
  57. if (!string.IsNullOrEmpty(latestaward))
  58. {
  59. //处理期数
  60. latestaward = latestaward.IndexOf("20", 0, 2, StringComparison.Ordinal) >= 0 ? latestaward : "20" + latestaward;
  61. //本地最新期数
  62. string old = (qgfc3Dbll.GetNewTermByTableName(type.GetSCCLotteryTableName()).TryToInt32() - 1).ToString();
  63. StringBuilder builder = new StringBuilder();
  64. //TODO 检测二者之间差了多少期,并将差了的期插入本地
  65. int o = old.TryToInt32();
  66. int l = latestaward.TryToInt32();
  67. if (o < l)
  68. {
  69. while (o + 1 <= l)
  70. {
  71. o++;
  72. //向本地插入一条不包括开奖号的数据
  73. int totalBall = string.IsNullOrEmpty(type.GetEnumText()) ? 0 : type.GetEnumText().TryToInt32();
  74. //插入差额期数
  75. Insert(totalBall, o.ToString(), type);
  76. builder.Append(o.ToString() + "、");
  77. }
  78. //TODO 插入下一期开奖信息并且发送邮件对未复查的进行提醒
  79. SendEmail(StringHelper.DelLastChar(builder.ToString(), "、"), type);
  80. }
  81. }
  82. }
  83. }
  84. }
  85. /// <summary>
  86. /// 插入下一期开奖信息并且发送邮件对未复查的进行提醒
  87. /// </summary>
  88. /// <param name="latestaward"></param>
  89. /// <param name="scc"></param>
  90. private void SendEmail(string latestaward, SCCLottery scc)
  91. {
  92. //发送邮件
  93. string address = ConfigHelper.GetValue("ErrorReportTo");
  94. string subject = scc.GetEnumDescription() + "[第" + latestaward + "期]开奖号未及时复查提醒";
  95. string body = "系统管理员请注意:" + scc.GetEnumDescription() + "[第" + latestaward +
  96. "期]开奖号未及时复查,请尽快登陆系统后台进行复查操作!<br /><br />" + scc.GetEnumDescription() + "官方参考网址为:<a href='" + GrabTheLatestAwardManager.GetRequestUrlAndXPath(scc)[0] + "'>【点我前往】</a>";
  97. MailHelper.SendByThread(address, subject, body);
  98. //同时插入下一期
  99. //int totalBall = string.IsNullOrEmpty(scc.GetEnumText()) ? 0 : scc.GetEnumText().TryToInt32();
  100. //string[] arr = latestaward.Split("、".ToCharArray());
  101. //Insert(totalBall, (arr[arr.Length - 1].TryToInt32() + 1).ToString(), scc);
  102. }
  103. /// <summary>
  104. /// 插入
  105. /// </summary>
  106. /// <param name="totalBall"></param>
  107. /// <param name="latestaward"></param>
  108. /// <param name="scc"></param>
  109. private void Insert(int totalBall, string latestaward, SCCLottery scc)
  110. {
  111. switch (totalBall)
  112. {
  113. case 3:
  114. open3CodeBll.AddOpen3Code(scc, new OpenCode3Model
  115. {
  116. Term = latestaward.TryToInt32(),
  117. OpenCode1 = -1,
  118. OpenCode2 = -1,
  119. OpenCode3 = -1,
  120. OpenTime = DateTime.Now
  121. });
  122. break;
  123. case 4:
  124. open4CodeBll.AddOpen4Code(scc, new OpenCode4Model
  125. {
  126. Term = latestaward.TryToInt32(),
  127. OpenCode1 = -1,
  128. OpenCode2 = -1,
  129. OpenCode3 = -1,
  130. OpenCode4 = -1,
  131. OpenTime = DateTime.Now
  132. });
  133. break;
  134. case 5:
  135. open5CodeBll.AddOpen5Code(scc, new OpenCode5Model
  136. {
  137. Term = latestaward.TryToInt32(),
  138. OpenCode1 = -1,
  139. OpenCode2 = -1,
  140. OpenCode3 = -1,
  141. OpenCode4 = -1,
  142. OpenCode5 = -1,
  143. OpenTime = DateTime.Now
  144. });
  145. break;
  146. case 7:
  147. open7CodeBll.AddOpen7Code(scc, new OpenCode7Model
  148. {
  149. Term = latestaward.TryToInt32(),
  150. OpenCode1 = -1,
  151. OpenCode2 = -1,
  152. OpenCode3 = -1,
  153. OpenCode4 = -1,
  154. OpenCode5 = -1,
  155. OpenCode6 = -1,
  156. OpenCode7 = -1,
  157. OpenTime = DateTime.Now
  158. });
  159. break;
  160. case 8:
  161. open8CodeBll.AddOpen8Code(scc, new OpenCode8Model
  162. {
  163. Term = latestaward.TryToInt32(),
  164. OpenCode1 = -1,
  165. OpenCode2 = -1,
  166. OpenCode3 = -1,
  167. OpenCode4 = -1,
  168. OpenCode5 = -1,
  169. OpenCode6 = -1,
  170. OpenCode7 = -1,
  171. OpenCode8 = -1,
  172. OpenTime = DateTime.Now
  173. });
  174. break;
  175. case 10:
  176. open10CodeBll.AddOpen10Code(scc, new OpenCode10Model
  177. {
  178. Term = latestaward.TryToInt32(),
  179. OpenCode1 = -1,
  180. OpenCode2 = -1,
  181. OpenCode3 = -1,
  182. OpenCode4 = -1,
  183. OpenCode5 = -1,
  184. OpenCode6 = -1,
  185. OpenCode7 = -1,
  186. OpenCode8 = -1,
  187. OpenCode9 = -1,
  188. OpenCode10 = -1,
  189. OpenTime = DateTime.Now
  190. });
  191. break;
  192. case 21:
  193. open21CodeBll.AddOpen21Code(scc, new OpenCode21Model
  194. {
  195. Term = latestaward.TryToInt32(),
  196. OpenCode1 = -1,
  197. OpenCode2 = -1,
  198. OpenCode3 = -1,
  199. OpenCode4 = -1,
  200. OpenCode5 = -1,
  201. OpenCode6 = -1,
  202. OpenCode7 = -1,
  203. OpenCode8 = -1,
  204. OpenCode9 = -1,
  205. OpenCode10 = -1,
  206. OpenCode11 = -1,
  207. OpenCode12 = -1,
  208. OpenCode13 = -1,
  209. OpenCode14 = -1,
  210. OpenCode15 = -1,
  211. OpenCode16 = -1,
  212. OpenCode17 = -1,
  213. OpenCode18 = -1,
  214. OpenCode19 = -1,
  215. OpenCode20 = -1,
  216. OpenCode21 = -1,
  217. OpenTime = DateTime.Now
  218. });
  219. break;
  220. default:
  221. break;
  222. }
  223. }
  224. }
  225. }