promotion.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using dodohold.core;
  2. using CSRedis;
  3. using System.Data;
  4. namespace molilian.core
  5. {
  6. public partial class TkLogCore
  7. {
  8. static string promotion_img_key = "queue:promotion:img";
  9. public static int task_insert_promotion_img_logs(IDbConnection connection, IDbTransaction transaction, int limit, CSRedisClient redis)
  10. {
  11. int total = 0;
  12. for (int i = 0; i < limit; i++)
  13. {
  14. var data = redis.LPop<PromotionQueryDTO>(promotion_img_key);
  15. if (data == null) break;
  16. if (data.success)
  17. {
  18. data.similarPromotion = string.Empty;
  19. data.promotionImg = string.Empty;
  20. }
  21. connection.Insert(data);
  22. total++;
  23. }
  24. return total;
  25. }
  26. public static async Task PromotionImgLogAsync(PromotionQueryDTO response)
  27. {
  28. try
  29. {
  30. var ts = DateTime.Now - response.create_time;
  31. response.elapsedTime = (int)ts.TotalMilliseconds;
  32. _ = RedisHelper.RPushAsync(promotion_img_key, response);
  33. //using var connection = DBContext.GetOpenConnection();
  34. //connection.Insert(response);
  35. savePromotionCache(response.accountId, response.accountName, response.success, response.message, response.reason);
  36. }
  37. catch (Exception ex) { }
  38. }
  39. private static void savePromotionCache(int accountId, string accountName, bool success, string message, string reason)
  40. {
  41. savePromotionAccountCache("all", success, message, reason);
  42. savePromotionAccountCache($"{accountId}", success, message, reason);
  43. }
  44. private static void savePromotionAccountCache(string accountName, bool success, string message, string reason)
  45. {
  46. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMM}");
  47. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  48. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  49. string result = success ? "success" : "fail";
  50. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  51. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  52. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  53. if (!string.IsNullOrEmpty(message))
  54. {
  55. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  56. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  57. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  58. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  59. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  60. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  61. RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
  62. RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  63. RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  64. }
  65. if (!string.IsNullOrEmpty(reason))
  66. {
  67. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  68. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  69. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  70. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  71. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  72. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  73. RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  74. RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  75. RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  76. }
  77. }
  78. }
  79. }