TkLogCore.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc.Controllers;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using dodohold.core;
  9. using static dodohold.core.ZTOExpress.CreateOrderArgs;
  10. using System.Net;
  11. using System.Security.Cryptography;
  12. using Spire.Pdf.Exporting.XPS.Schema;
  13. using System.Xml.Linq;
  14. using static QRCoder.PayloadGenerator;
  15. using TencentCloud.Ssl.V20191205.Models;
  16. using CSRedis;
  17. using System.Data;
  18. using TencentCloud.Omics.V20221128.Models;
  19. using TencentCloud.Csip.V20221121.Models;
  20. namespace molilian.core
  21. {
  22. public class TkLogCore
  23. {
  24. static string queue_tb_key = "queue:logs:tb";
  25. static string queue_jd_key = "queue:logs:jd";
  26. static string queue_parse_tb_key = "queue:parse_logs:tb";
  27. static string queue_parse_jd_key = "queue:parse_logs:jd";
  28. static string queue_parse_dy_key = "queue:parse_logs:dy";
  29. static string queue_parse_tool_key = "queue:parse_logs:tool";
  30. static string queue_coupon_key = "queue:coupon_logs";
  31. static string promotion_img_key = "queue:promotion:img";
  32. public static int BatchInsertLogDB(int limit)
  33. {
  34. var result = EndPointCore.ProcessEndPointNodes<int>(node =>
  35. {
  36. if (!node.is_public_api) return 0;
  37. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  38. return BatchInsertLogDB(limit, redis);
  39. });
  40. return result.Sum();
  41. }
  42. private static int save_tk_log(TkDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  43. {
  44. return new DBContext.Table(connection, tablename)
  45. .Add("end_point", data.end_point)
  46. .Add("channel", (int)data.channel)
  47. .Add("accountId", data.accountId)
  48. .Add("accountName", data.accountName)
  49. .Add("rawContent", data.rawContent)
  50. .Add("rawContent2", data.rawContent2)
  51. .Add("success", data.success)
  52. .Add("message", data.message)
  53. .Add("reason", data.reason)
  54. .Add("content", data.content)
  55. .Add("couponAmount", data.couponAmount)
  56. .Add("itemId", data.itemId)
  57. .Add("itemName", data.itemName)
  58. .Add("pic", data.pic)
  59. .Add("promotionPrice", data.promotionPrice)
  60. .Add("taoToken", data.taoToken)
  61. .Add("shortLinkurl", data.shortLinkurl)
  62. .Add("deeplink_url", data.deeplink_url)
  63. .Add("num_iid", data.num_iid)
  64. .Add("elapsedTime", data.elapsedTime)
  65. .Add("subCode", data.subCode)
  66. .Add("ip", data.ip)
  67. .Add("oaid", data.oaid)
  68. .Add("create_time", data.create_time)
  69. .Create(DBContext.InsertType.NORMAL, transaction);
  70. }
  71. private static int save_tk_parse_logs(TkDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  72. {
  73. return new DBContext.Table(connection, tablename)
  74. .Add("end_point", data.end_point)
  75. .Add("channel", (int)data.channel)
  76. .Add("accountId", data.accountId)
  77. .Add("accountName", data.accountName)
  78. .Add("rawContent", data.rawContent)
  79. .Add("success", data.success)
  80. .Add("message", data.message)
  81. .Add("reason", data.reason)
  82. .Add("content", data.content)
  83. .Add("itemId", data.itemId)
  84. .Add("itemName", data.itemName)
  85. .Add("pic", data.pic)
  86. .Add("couponAmount", data.couponAmount)
  87. .Add("promotionPrice", data.promotionPrice)
  88. .Add("taoToken", data.taoToken)
  89. .Add("shortLinkurl", data.shortLinkurl)
  90. .Add("deeplink_url", data.deeplink_url)
  91. .Add("num_iid", data.num_iid)
  92. .Add("elapsedTime", data.elapsedTime)
  93. .Add("elapsedTime2", data.elapsedTime2)
  94. .Add("elapsedTime3", data.elapsedTime3)
  95. .Add("subCode", data.subCode)
  96. .Add("ip", data.ip)
  97. .Add("oaid", data.oaid)
  98. .Add("create_time", data.create_time)
  99. .Create(DBContext.InsertType.NORMAL, transaction);
  100. }
  101. public static int BatchInsertLogDB(int limit, CSRedisClient redis)
  102. {
  103. int total = 0;
  104. using var connection = DBContext.GetOpenConnection();
  105. connection.Open();
  106. using var transaction = connection.BeginTransaction();
  107. string cacheKey = ":lock_key:start_comparison_tk";
  108. bool start_comparison_tk = RedisHelper.Get<int>(cacheKey) > 0;
  109. try
  110. {
  111. for (int i = 0; i < limit; i++)
  112. {
  113. var data = redis.LPop<TkDataDTO>(queue_tb_key);
  114. if (data == null) break;
  115. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  116. "127.0.0.1".Equals(data.ip) || data.elapsedTime > 1000)
  117. {
  118. save_tk_log(data, "tk_logs_test", connection, transaction);
  119. }
  120. else
  121. {
  122. data.id = save_tk_log(data, "tk_logs", connection, transaction);
  123. if (data.success)
  124. {
  125. save_tk_log(data, "tk_success_logs", connection, transaction);
  126. }
  127. //if (data.success || data.message.Contains("该链接不支持转化,请更换链接尝试"))
  128. //{
  129. // if (start_comparison_tk)
  130. // {
  131. // save_tk_log(data, "comparison_tk_logs", connection, transaction);
  132. // }
  133. //}
  134. if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
  135. }
  136. total++;
  137. }
  138. for (int i = 0; i < limit; i++)
  139. {
  140. var data = redis.LPop<JdDataDTO>(queue_jd_key);
  141. if (data == null) break;
  142. new DBContext.Table(connection, "tk_logs")
  143. .Add("end_point", data.end_point)
  144. .Add("channel", (int)data.channel)
  145. .Add("accountId", data.accountId)
  146. .Add("accountName", data.accountName)
  147. .Add("rawContent", data.rawContent)
  148. .Add("rawContent2", data.rawContent2)
  149. .Add("success", data.success)
  150. .Add("message", data.message)
  151. .Add("reason", data.reason)
  152. .Add("shortLinkurl", data.shortLinkurl)
  153. .Add("deeplink_url", data.deeplink_url)
  154. .Add("elapsedTime", data.elapsedTime)
  155. .Add("ip", data.ip)
  156. .Add("oaid", data.oaid)
  157. .Add("create_time", data.create_time)
  158. .Create(DBContext.InsertType.NORMAL, transaction);
  159. total++;
  160. }
  161. for (int i = 0; i < limit; i++)
  162. {
  163. var data = redis.LPop<TkDataDTO>(queue_parse_tb_key);
  164. if (data == null) break;
  165. //switch (data.oaid)
  166. //{
  167. // case "test-comparison_tk_logs":
  168. // save_tk_parse_logs(data, "comparison_tk_parse_logs", connection, transaction);
  169. // break;
  170. // case "test-comparison_tk_logs_raw":
  171. // save_tk_parse_logs(data, "comparison_tk_parse_logs_raw", connection, transaction);
  172. // break;
  173. // default:
  174. // break;
  175. //}
  176. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  177. "127.0.0.1".Equals(data.ip) || data.elapsedTime > 1000)
  178. {
  179. save_tk_parse_logs(data, "tk_parse_logs_test", connection, transaction);
  180. }
  181. else
  182. {
  183. data.id = save_tk_parse_logs(data, "tk_parse_logs", connection, transaction);
  184. if (data.success)
  185. {
  186. save_tk_parse_logs(data, "tk_success_parse_logs", connection, transaction);
  187. }
  188. if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
  189. }
  190. if (data.reason.Contains("初步筛选2") && !data.rawContent.Contains("I:/kWqN5t623Hx"))
  191. {
  192. save_tk_parse_logs(data, "tk_parse_logs_test2", connection, transaction);
  193. }
  194. if (data.reason.Contains("初步筛选1.5"))
  195. {
  196. save_tk_parse_logs(data, "tk_parse_logs_multi_token", connection, transaction);
  197. }
  198. if (data.reason.Contains("霸下验证码"))
  199. {
  200. save_tk_parse_logs(data, "tk_parse_logs_captcha", connection, transaction);
  201. }
  202. total++;
  203. }
  204. for (int i = 0; i < limit; i++)
  205. {
  206. var data = redis.LPop<JdDataDTO>(queue_parse_jd_key);
  207. if (data == null) break;
  208. new DBContext.Table(connection, "jd_parse_logs")
  209. .Add("end_point", data.end_point)
  210. .Add("channel", (int)data.channel)
  211. .Add("accountId", data.accountId)
  212. .Add("accountName", data.accountName)
  213. .Add("rawContent", data.rawContent)
  214. .Add("success", data.success)
  215. .Add("message", data.message)
  216. .Add("reason", data.reason)
  217. .Add("content", data.content)
  218. .Add("itemId", data.itemId)
  219. .Add("itemName", data.itemName)
  220. .Add("pic", data.pic)
  221. .Add("couponAmount", data.couponAmount)
  222. .Add("promotionPrice", data.promotionPrice)
  223. .Add("taoToken", data.taoToken)
  224. .Add("shortLinkurl", data.shortLinkurl)
  225. .Add("deeplink_url", data.deeplink_url)
  226. .Add("elapsedTime", data.elapsedTime)
  227. .Add("subCode", data.subCode)
  228. .Add("ip", data.ip)
  229. .Add("oaid", data.oaid)
  230. .Add("create_time", data.create_time)
  231. .Create(DBContext.InsertType.NORMAL, transaction);
  232. total++;
  233. }
  234. for (int i = 0; i < limit; i++)
  235. {
  236. var data = redis.LPop<DyDataDTO>(queue_parse_dy_key);
  237. if (data == null) break;
  238. new DBContext.Table(connection, "tk_parse_logs")
  239. .Add("end_point", data.end_point)
  240. .Add("channel", (int)data.channel)
  241. .Add("accountId", data.accountId)
  242. .Add("accountName", data.accountName)
  243. .Add("rawContent", data.rawContent)
  244. .Add("success", data.success)
  245. .Add("message", data.message)
  246. .Add("reason", data.reason)
  247. .Add("content", data.content)
  248. .Add("itemId", data.itemId)
  249. .Add("itemName", data.itemName)
  250. .Add("pic", data.pic)
  251. .Add("couponAmount", data.couponAmount)
  252. .Add("promotionPrice", data.promotionPrice)
  253. .Add("taoToken", data.taoToken)
  254. .Add("shortLinkurl", data.shortLinkurl)
  255. .Add("deeplink_url", data.deeplink_url)
  256. .Add("elapsedTime", data.elapsedTime)
  257. .Add("subCode", data.subCode)
  258. .Add("ip", data.ip)
  259. .Add("oaid", data.oaid)
  260. .Add("create_time", data.create_time)
  261. .Create(DBContext.InsertType.NORMAL, transaction);
  262. total++;
  263. }
  264. for (int i = 0; i < limit; i++)
  265. {
  266. var data = redis.LPop<ToolParseDataDTO>(queue_parse_tool_key);
  267. if (data == null) break;
  268. new DBContext.Table(connection, "tool_parse_logs")
  269. .Add("end_point", data.end_point)
  270. .Add("channel", (int)data.channel)
  271. .Add("rawContent", data.rawContent)
  272. .Add("success", data.success)
  273. .Add("message", data.message)
  274. .Add("reason", data.reason)
  275. .Add("content", data.content)
  276. .Add("taoToken", data.taoToken)
  277. .Add("shortLinkurl", data.shortLinkurl)
  278. .Add("deeplink_url", data.deeplink_url)
  279. .Add("elapsedTime", data.elapsedTime)
  280. .Add("ip", data.ip)
  281. .Add("oaid", data.oaid)
  282. .Add("create_time", data.create_time)
  283. .Create(DBContext.InsertType.NORMAL, transaction);
  284. total++;
  285. }
  286. for (int i = 0; i < limit; i++)
  287. {
  288. var data = redis.LPop<UnionCouponDTO>(queue_coupon_key);
  289. if (data == null) break;
  290. connection.Insert(data);
  291. total++;
  292. }
  293. for (int i = 0; i < limit; i++)
  294. {
  295. var data = redis.LPop<PromotionQueryDTO>(promotion_img_key);
  296. if (data == null) break;
  297. connection.Insert(data);
  298. total++;
  299. }
  300. transaction.Commit();
  301. }
  302. catch (Exception ex)
  303. {
  304. transaction.Rollback();
  305. _ = new LoggerLibrary("database_error", "parse_log")
  306. .Info(ex.Message, ex.StackTrace)
  307. .SaveAsync();
  308. NotifyCore.Notify(new NifyMessage
  309. {
  310. message = $"【写入日志异常】\n{ex.Message}\n{ex.StackTrace}",
  311. priority = NifyMessagePriority.high,
  312. tags = ["red_circle"]
  313. });
  314. }
  315. finally
  316. {
  317. connection.Close();
  318. }
  319. return total;
  320. }
  321. public static async Task PromotionImgLogAsync(PromotionQueryDTO response)
  322. {
  323. try
  324. {
  325. var ts = DateTime.Now - response.create_time;
  326. response.elapsedTime = (int)ts.TotalMilliseconds;
  327. _ = RedisHelper.RPushAsync(promotion_img_key, response);
  328. //using var connection = DBContext.GetOpenConnection();
  329. //connection.Insert(response);
  330. savePromotionCache(response.accountId, response.accountName, response.success, response.message, response.reason);
  331. }
  332. catch (Exception ex) { }
  333. }
  334. public static async Task LogAsync(JdDataDTO response)
  335. {
  336. try
  337. {
  338. var ts = DateTime.Now - response.create_time;
  339. response.elapsedTime = (int)ts.TotalMilliseconds;
  340. _ = RedisHelper.RPushAsync(queue_jd_key, response);
  341. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  342. }
  343. catch (Exception ex) { }
  344. }
  345. public static async Task LogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
  346. {
  347. try
  348. {
  349. var ts = DateTime.Now - response.create_time;
  350. response.elapsedTime = (int)ts.TotalMilliseconds;
  351. _ = RedisHelper.RPushAsync(queue_tb_key, response);
  352. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  353. if (!response.success && "nologin".Equals(response.message))
  354. {
  355. switch (response.channel)
  356. {
  357. case TkChannelEnum.tb:
  358. await Task.Run(() =>
  359. {
  360. if (alimamaPlus != null)
  361. {
  362. (bool success, string message) = alimamaPlus.RenewCookie();
  363. if (success) return;
  364. }
  365. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  366. });
  367. break;
  368. }
  369. }
  370. if ("没有匹配账号".Equals(response.reason))
  371. {
  372. TkPoolCore.AccountExhausted();
  373. }
  374. }
  375. catch (Exception ex)
  376. {
  377. _ = new LoggerLibrary("unionParse", "database_error")
  378. .Info(response.rawContent, response.rawContent2)
  379. .Info(response.Convert2Json())
  380. .Info(ex.Message, ex.StackTrace)
  381. .SaveAsync();
  382. }
  383. }
  384. public static async Task ParseLogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
  385. {
  386. #if DEBUG
  387. //return;
  388. #endif
  389. try
  390. {
  391. var ts = DateTime.Now - response.create_time;
  392. response.elapsedTime = (int)ts.TotalMilliseconds;
  393. _ = RedisHelper.RPushAsync(queue_parse_tb_key, response);
  394. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  395. if (!string.IsNullOrEmpty(response.itemId)) TkOrderTrackingCore.SaveLinkSummary(response);
  396. if (!response.success && "nologin".Equals(response.message))
  397. {
  398. switch (response.channel)
  399. {
  400. case TkChannelEnum.tb:
  401. await Task.Run(() =>
  402. {
  403. if (alimamaPlus != null)
  404. {
  405. (bool success, string message) = alimamaPlus.RenewCookie();
  406. if (success) return;
  407. }
  408. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}");
  409. }); break;
  410. }
  411. }
  412. }
  413. catch (Exception ex)
  414. {
  415. _ = new LoggerLibrary("unionParse", "database_error")
  416. .Info(response.rawContent)
  417. .Info(response.Convert2Json())
  418. .Info(ex.Message, ex.StackTrace)
  419. .SaveAsync();
  420. }
  421. }
  422. public static async Task CouponLogAsync(UnionCouponDTO response, AlimamaPlus? alimamaPlus = null)
  423. {
  424. try
  425. {
  426. var ts = DateTime.Now - response.create_time;
  427. response.elapsedTime = (int)ts.TotalMilliseconds;
  428. _ = RedisHelper.RPushAsync(queue_coupon_key, response);
  429. saveCouponCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  430. if (!response.success && "nologin".Equals(response.message))
  431. {
  432. switch (response.channel)
  433. {
  434. case TkChannelEnum.tb:
  435. await Task.Run(() =>
  436. {
  437. if (alimamaPlus != null)
  438. {
  439. (bool success, string message) = alimamaPlus.RenewCookie();
  440. if (success) return;
  441. }
  442. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}");
  443. }); break;
  444. }
  445. }
  446. }
  447. catch (Exception ex)
  448. {
  449. _ = new LoggerLibrary("unionCoupon", "database_error")
  450. .Info(response.rawContent)
  451. .Info(response.Convert2Json())
  452. .Info(ex.Message, ex.StackTrace)
  453. .SaveAsync();
  454. }
  455. }
  456. public static async Task ParseLogAsync(JdDataDTO response)
  457. {
  458. try
  459. {
  460. var ts = DateTime.Now - response.create_time;
  461. response.elapsedTime = (int)ts.TotalMilliseconds;
  462. _ = RedisHelper.RPushAsync(queue_parse_jd_key, response);
  463. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  464. }
  465. catch (Exception ex) { }
  466. }
  467. public static async Task ParseLogAsync(DyDataDTO response)
  468. {
  469. try
  470. {
  471. var ts = DateTime.Now - response.create_time;
  472. response.elapsedTime = (int)ts.TotalMilliseconds;
  473. _ = RedisHelper.RPushAsync(queue_parse_dy_key, response);
  474. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  475. }
  476. catch (Exception ex) { }
  477. }
  478. public static async Task ParseLogAsync(ToolParseDataDTO response)
  479. {
  480. try
  481. {
  482. var ts = DateTime.Now - response.create_time;
  483. response.elapsedTime = (int)ts.TotalMilliseconds;
  484. _ = RedisHelper.RPushAsync(queue_parse_tool_key, response);
  485. saveParseCache(response.channel.ToString(), 0, "tool", response.success, response.message, response.reason);
  486. }
  487. catch (Exception ex) { }
  488. }
  489. private static void saveCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  490. {
  491. saveAccountCache("all", success, message, reason);
  492. saveAccountCache($"{channel}", success, message, reason);
  493. saveAccountCache($"{accountName}", success, message, reason);
  494. if (accountId != 0)
  495. {
  496. //todo 放着跑两天,要将读取的地方改成读取accountid
  497. saveAccountCache($"{channel}_{accountId}", success, message, reason);
  498. }
  499. }
  500. private static void saveAccountCache(string accountName, bool success, string message, string reason)
  501. {
  502. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMM}");
  503. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMdd}");
  504. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  505. string result = success ? "success" : "fail";
  506. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  507. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  508. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  509. if (!string.IsNullOrEmpty(message))
  510. {
  511. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  512. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  513. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  514. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  515. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  516. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  517. }
  518. if (!string.IsNullOrEmpty(reason))
  519. {
  520. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  521. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  522. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  523. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  524. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  525. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  526. }
  527. }
  528. private static void saveParseCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  529. {
  530. saveParseAccountCache("all", success, message, reason);
  531. saveParseAccountCache($"{channel}", success, message, reason);
  532. saveParseAccountCache($"{accountName}", success, message, reason);
  533. if (accountId != 0)
  534. {
  535. //todo 放着跑两天,要将读取的地方改成读取accountid
  536. saveParseAccountCache($"{channel}_{accountId}", success, message, reason);
  537. }
  538. }
  539. private static void saveParseAccountCache(string accountName, bool success, string message, string reason)
  540. {
  541. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMM}");
  542. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  543. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  544. string result = success ? "success" : "fail";
  545. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  546. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  547. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  548. if (!string.IsNullOrEmpty(message))
  549. {
  550. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  551. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  552. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  553. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  554. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  555. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  556. }
  557. if (!string.IsNullOrEmpty(reason))
  558. {
  559. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  560. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  561. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  562. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  563. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  564. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  565. }
  566. }
  567. private static void savePromotionCache(int accountId, string accountName, bool success, string message, string reason)
  568. {
  569. savePromotionAccountCache("all", success, message, reason);
  570. savePromotionAccountCache($"{accountId}", success, message, reason);
  571. }
  572. private static void savePromotionAccountCache(string accountName, bool success, string message, string reason)
  573. {
  574. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMM}");
  575. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  576. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  577. string result = success ? "success" : "fail";
  578. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  579. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  580. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  581. if (!string.IsNullOrEmpty(message))
  582. {
  583. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  584. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  585. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  586. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  587. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  588. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  589. }
  590. if (!string.IsNullOrEmpty(reason))
  591. {
  592. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  593. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  594. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  595. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  596. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  597. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  598. }
  599. }
  600. private static void saveCouponCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  601. {
  602. saveAccountCouponCache("all", success, message, reason);
  603. saveAccountCouponCache($"{channel}", success, message, reason);
  604. if (accountId != 0)
  605. {
  606. saveAccountCouponCache($"{channel}_{accountId}", success, message, reason);
  607. }
  608. }
  609. private static void saveAccountCouponCache(string accountName, bool success, string message, string reason)
  610. {
  611. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMM}");
  612. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  613. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  614. string result = success ? "success" : "fail";
  615. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  616. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  617. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  618. if (!string.IsNullOrEmpty(message))
  619. {
  620. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  621. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  622. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  623. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  624. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  625. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  626. }
  627. if (!string.IsNullOrEmpty(reason))
  628. {
  629. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  630. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  631. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  632. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  633. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  634. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  635. }
  636. }
  637. public static int GetTotal(string keyname, bool all_node = true)
  638. {
  639. var result = EndPointCore.ProcessEndPointNodes<int>(node =>
  640. {
  641. if (!node.is_public_api) return 0;
  642. #if DEBUG
  643. switch (node.name)
  644. {
  645. case "bj":
  646. node.redis_server = "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  647. break;
  648. case "gz":
  649. node.redis_server = "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  650. break;
  651. }
  652. #endif
  653. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  654. return redis.Get<int>(keyname);
  655. });
  656. return result.Sum();
  657. }
  658. public static string[] GetTotalKeys(string keyname, bool all_node = true)
  659. {
  660. var result = EndPointCore.ProcessEndPointNodes<string[]>(node =>
  661. {
  662. if (!node.is_public_api) return [];
  663. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  664. string[] message_keys = redis.SMembers(keyname);
  665. return message_keys;
  666. });
  667. string[] message_keys = [];
  668. foreach (var arr in result)
  669. {
  670. message_keys = message_keys.Union(arr).ToArray();
  671. }
  672. return message_keys;
  673. }
  674. //if (item.total_count > 0) continue;
  675. //item.total_count = RedisHelper.Get<int>($":total:all:{item.report_date:yyyyMMdd}");
  676. //if (item.total_count == 0) continue;
  677. //item.success_count = RedisHelper.Get<int>($":total:all:success:{item.report_date:yyyyMMdd}");
  678. //item.abandon_count = RedisHelper.Get<int>($":total:all:放弃转链:{item.report_date:yyyyMMdd}");
  679. }
  680. }