StatTimerService.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using MySystem.PxcModels;
  8. namespace MySystem
  9. {
  10. public class StatTimerService
  11. {
  12. public readonly static StatTimerService Instance = new StatTimerService();
  13. private StatTimerService()
  14. { }
  15. public void Start(JobMqMsg jobInfo)
  16. {
  17. string content = "";
  18. try
  19. {
  20. dosomething();
  21. string Msg = "success";
  22. jobInfo.Status = Msg == "success" ? 1 : 0;
  23. jobInfo.Msg = Msg == "success" ? "执行完成" : Msg;
  24. RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
  25. }
  26. catch (Exception ex)
  27. {
  28. if (!string.IsNullOrEmpty(content))
  29. {
  30. Dictionary<string, string> data = new Dictionary<string, string>();
  31. data.Add("ErrTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  32. data.Add("ErrMsg", ex.ToString());
  33. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(data), "public_err");
  34. }
  35. else
  36. {
  37. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
  38. }
  39. }
  40. }
  41. public void dosomething()
  42. {
  43. WebCMSEntities db = new WebCMSEntities();
  44. string yesterday = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  45. string today = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  46. // DataTable dt = dbconn.dtable("select Id from Users where CreateDate>='" + yesterday + "' and CreateDate<'" + today + "' order by Id");
  47. // foreach (DataRow dr in dt.Rows)
  48. // {
  49. // int UserId = int.Parse(dr["Id"].ToString()); //创客ID
  50. // int Level = 0;
  51. // while (UserId > 0)
  52. // {
  53. // Level += 1;
  54. // Users user = db.Users.FirstOrDefault(m => m.Id == UserId);
  55. // if (user != null)
  56. // {
  57. // if (user.AuthFlag == 1)
  58. // {
  59. // if (Level == 1)
  60. // {
  61. // RedisDbconn.Instance.AddInt("TotalUser:" + UserId); //累计总创客
  62. // RedisDbconn.Instance.AddInt("AddUser:" + UserId + ":" + TradeDate); //新增创客
  63. // RedisDbconn.Instance.AddInt("AddUser:" + UserId + ":" + TradeMonth); //新增创客
  64. // }
  65. // RedisDbconn.Instance.AddInt("TeamTotalUser:" + UserId); //累计总创客
  66. // RedisDbconn.Instance.AddInt("TeamAddUser:" + UserId + ":" + TradeDate); //新增创客
  67. // RedisDbconn.Instance.AddInt("TeamAddUser:" + UserId + ":" + TradeMonth); //新增创客
  68. // }
  69. // UserId = user.ParentUserId;
  70. // }
  71. // }
  72. // }
  73. DataTable dt = dbconn.dtable("select UserId,BrandId,MerStandardDate from PosMerchantInfo where MerStandardDate>='" + yesterday + "' and MerStandardDate<'" + today + "' and QueryCount=0");
  74. dbconn.op("update PosMerchantInfo set QueryCount=1 where MerStandardDate>='" + yesterday + "' and MerStandardDate<'" + today + "' and QueryCount=0");
  75. foreach (DataRow dr in dt.Rows)
  76. {
  77. DateTime date = DateTime.Parse(dr["MerStandardDate"].ToString());
  78. string TradeMonth = date.ToString("yyyyMM");
  79. string TradeDate = date.ToString("yyyyMMdd");
  80. int UserId = int.Parse(dr["UserId"].ToString()); //创客ID
  81. int BrandId = int.Parse(dr["BrandId"].ToString()); //品牌
  82. int MerchantCount = 1;
  83. int Level = 0;
  84. while (UserId > 0)
  85. {
  86. Level += 1;
  87. Users user = db.Users.FirstOrDefault(m => m.Id == UserId);
  88. if (user != null)
  89. {
  90. if (user.AuthFlag == 1)
  91. {
  92. if (Level == 1)
  93. {
  94. RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
  95. RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
  96. RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
  97. RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
  98. }
  99. RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
  100. RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
  101. RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
  102. RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
  103. }
  104. UserId = user.ParentUserId;
  105. }
  106. }
  107. }
  108. db.Dispose();
  109. }
  110. }
  111. }