CreateTableHelper.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Threading;
  5. using Library;
  6. using LitJson;
  7. using MySystem;
  8. public class CreateTableHelper
  9. {
  10. public readonly static CreateTableHelper Instance = new CreateTableHelper();
  11. private CreateTableHelper()
  12. { }
  13. public void Start()
  14. {
  15. Thread th = new Thread(DoWorks);
  16. th.IsBackground = true;
  17. th.Start();
  18. }
  19. public void DoWorks()
  20. {
  21. while (true)
  22. {
  23. if(DateTime.Now.Day > 25 && DateTime.Now.Hour > 0 && DateTime.Now.Hour < 3)
  24. {
  25. try
  26. {
  27. string month = DateTime.Now.AddMonths(1).ToString("yyyyMM");
  28. if(string.IsNullOrEmpty(RedisDbconn.Instance.Get<string>("TradeRecord" + month)))
  29. {
  30. CustomerSqlConn.op(AppConfig.Base.CreateTradeRecord.Replace("#DateTime#", month), AppConfig.Base.RdsSqlConn);
  31. RedisDbconn.Instance.Set("TradeRecord" + month, "1");
  32. int sec = 3600 * 12 * 35;
  33. RedisDbconn.Instance.SetExpire("TradeRecord" + month, sec);
  34. Thread.Sleep(2000);
  35. }
  36. }
  37. catch (Exception ex)
  38. {
  39. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "创建分表异常");
  40. }
  41. Thread.Sleep(5000);
  42. }
  43. else
  44. {
  45. Thread.Sleep(3600000);
  46. }
  47. }
  48. }
  49. }