jd.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 queue_parse_jd_key = "queue:parse_logs:jd";
  9. public static int task_insert_parse_jd_logs(int limit, CSRedisClient redis)
  10. {
  11. int total = 0;
  12. using var connection = DBContext.GetOpenConnection();
  13. connection.Open();
  14. using var transaction = connection.BeginTransaction();
  15. try
  16. {
  17. for (int i = 0; i < limit; i++)
  18. {
  19. var data = redis.LPop<JdDataDTO>(queue_parse_jd_key);
  20. if (data == null) break;
  21. if (_test_oaid.Equals(data.oaid) ||
  22. data.ip.Contains("127.0.0"))
  23. {
  24. save_jd_parse_logs(data, "jd_parse_logs_test", connection, transaction);
  25. }
  26. else
  27. {
  28. //save_jd_parse_logs(data, "jd_parse_logs", connection, transaction);
  29. if (save_dailys_log)
  30. {
  31. string daily_table = $"jd_parse_logs_{data.create_time:yyyyMMdd}";
  32. save_jd_parse_logs(data, daily_table, connection, transaction);
  33. }
  34. if (data.elapsedTime > 1000)
  35. {
  36. save_jd_parse_logs(data, "jd_parse_logs_test", connection, transaction);
  37. }
  38. if (data.success)
  39. {
  40. save_jd_parse_logs(data, "jd_parse_logs_success", connection, transaction);
  41. }
  42. }
  43. total++;
  44. }
  45. transaction.Commit();
  46. }
  47. catch (Exception ex)
  48. {
  49. transaction.Rollback();
  50. new LoggerLibrary("TkLogCore_error", "task_insert_parse_jd_logs")
  51. .Info(ex.Message, ex.StackTrace)
  52. .SaveAsync();
  53. throw;
  54. }
  55. finally
  56. {
  57. connection.Close();
  58. }
  59. return total;
  60. }
  61. public static async Task ParseLogAsync(JdDataDTO response)
  62. {
  63. try
  64. {
  65. var ts = DateTime.Now - response.create_time;
  66. response.elapsedTime = (int)ts.TotalMilliseconds;
  67. _ = RedisHelper.RPushAsync(queue_parse_jd_key, response);
  68. if (!response.ip.Contains("127.0.0"))
  69. {
  70. saveParseCache(response.channel.ToString(), response.accountId,
  71. response.accountName, response.success, response.message, response.reason,
  72. response.deeplink_url);
  73. }
  74. if (response.success || response.message.Equals("转链失败"))
  75. {
  76. JdPoolCore.CallsIncrBy(response.accountId);
  77. }
  78. //CallsIncrBy
  79. if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
  80. if (!response.success && ("nologin".Equals(response.reason) ||
  81. "方法不存在".Equals(response.reason) ||
  82. "未登录".Equals(response.reason)))
  83. {
  84. await Task.Run(() =>
  85. {
  86. JdPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  87. });
  88. //switch (response.channel)
  89. //{
  90. // case TkChannelEnum.tb:
  91. // //await Task.Run(() =>
  92. // //{
  93. // // if (alimamaPlus != null)
  94. // // {
  95. // // (bool success, string message) = alimamaPlus.RenewCookie();
  96. // // if (success) return;
  97. // // }
  98. // // TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  99. // //});
  100. // break;
  101. //}
  102. }
  103. if ("没有匹配账号".Equals(response.reason))
  104. {
  105. JdPoolCore.AccountExhausted();
  106. }
  107. }
  108. catch (Exception ex) { }
  109. }
  110. private static int save_jd_parse_logs(JdDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  111. {
  112. return new DBContext.Table(connection, tablename)
  113. .Add("end_point", data.end_point)
  114. .Add("channel", (int)data.channel)
  115. .Add("accountId", data.accountId)
  116. .Add("accountName", data.accountName)
  117. .Add("rawContent", data.rawContent)
  118. .Add("success", data.success)
  119. .Add("message", data.message)
  120. .Add("reason", data.reason)
  121. .Add("content", data.content)
  122. .Add("itemId", data.itemId)
  123. .Add("itemName", data.itemName)
  124. .Add("pic", data.pic)
  125. .Add("couponAmount", data.couponAmount)
  126. .Add("promotionPrice", data.promotionPrice)
  127. .Add("taoToken", data.taoToken)
  128. .Add("shortLinkurl", data.shortLinkurl)
  129. .Add("deeplink_url", data.deeplink_url)
  130. .Add("elapsedTime", data.elapsedTime)
  131. .Add("subCode", data.subCode)
  132. .Add("ip", data.ip)
  133. .Add("oaid", data.oaid)
  134. .Add("create_time", data.create_time)
  135. .Create(DBContext.InsertType.NORMAL, transaction);
  136. }
  137. }
  138. }