dy.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_dy_key = "queue:parse_logs:dy";
  9. public static int task_insert_parse_dy_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<DyDataDTO>(queue_parse_dy_key);
  20. if (data == null) break;
  21. new DBContext.Table(connection, "tk_parse_logs")
  22. .Add("end_point", data.end_point)
  23. .Add("channel", (int)data.channel)
  24. .Add("accountId", data.accountId)
  25. .Add("accountName", data.accountName)
  26. .Add("rawContent", data.rawContent)
  27. .Add("success", data.success)
  28. .Add("message", data.message)
  29. .Add("reason", data.reason)
  30. .Add("content", data.content)
  31. .Add("itemId", data.itemId)
  32. .Add("itemName", data.itemName)
  33. .Add("pic", data.pic)
  34. .Add("couponAmount", data.couponAmount)
  35. .Add("promotionPrice", data.promotionPrice)
  36. .Add("taoToken", data.taoToken)
  37. .Add("shortLinkurl", data.shortLinkurl)
  38. .Add("deeplink_url", data.deeplink_url)
  39. .Add("elapsedTime", data.elapsedTime)
  40. .Add("subCode", data.subCode)
  41. .Add("ip", data.ip)
  42. .Add("oaid", data.oaid)
  43. .Add("create_time", data.create_time)
  44. .Create(DBContext.InsertType.NORMAL, transaction);
  45. total++;
  46. }
  47. transaction.Commit();
  48. }
  49. catch (Exception ex)
  50. {
  51. transaction.Rollback();
  52. new LoggerLibrary("TkLogCore_error", "task_insert_parse_dy_logs")
  53. .Info(ex.Message, ex.StackTrace)
  54. .SaveAsync();
  55. throw;
  56. }
  57. finally
  58. {
  59. connection.Close();
  60. }
  61. return total;
  62. }
  63. public static async Task ParseLogAsync(DyDataDTO response)
  64. {
  65. try
  66. {
  67. var ts = DateTime.Now - response.create_time;
  68. response.elapsedTime = (int)ts.TotalMilliseconds;
  69. _ = RedisHelper.RPushAsync(queue_parse_dy_key, response);
  70. saveClientRequestTotal(response.channel, response.ip, response.oaid);
  71. if (!response.ip.Contains("127.0.0"))
  72. {
  73. saveParseCache(response.channel.ToString(), response.accountId,
  74. response.accountName, response.success, response.message, response.reason,
  75. response.deeplink_url);
  76. }
  77. }
  78. catch (Exception ex) { }
  79. }
  80. }
  81. }