TkLogCore.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  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. using COSXML.Network;
  21. namespace molilian.core
  22. {
  23. public class TkLogCore
  24. {
  25. static string queue_tb_key = "queue:logs:tb";
  26. static string queue_jd_key = "queue:logs:jd";
  27. static string queue_parse_tb_key = "queue:parse_logs:tb";
  28. static string queue_parse_jd_key = "queue:parse_logs:jd";
  29. static string queue_parse_dy_key = "queue:parse_logs:dy";
  30. static string queue_parse_tool_key = "queue:parse_logs:tool";
  31. static string queue_coupon_key = "queue:coupon_logs";
  32. static string promotion_img_key = "queue:promotion:img";
  33. static string queue_cps_key = "queue:cps_logs";
  34. public static bool save_dailys_log = false;
  35. static TkLogCore()
  36. {
  37. int flag = RedisHelper.Get<int>("turn:save_dailys_log");
  38. if (flag == 1) save_dailys_log = true;
  39. }
  40. public static int BatchInsertLogDB(int limit)
  41. {
  42. var result = EndPointCore.ProcessEndPointNodes<int>(node =>
  43. {
  44. if (!node.is_public_api) return 0;
  45. if (CenterHub.IsCenter)
  46. {
  47. if (node.is_coupon_api) return 0;
  48. }
  49. else
  50. {
  51. if (!node.is_coupon_api) return 0;
  52. }
  53. if (string.IsNullOrEmpty(node.redis_server)) return 0;
  54. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  55. return BatchInsertLogDB(limit, redis);
  56. });
  57. return result.Sum();
  58. }
  59. private static int save_tk_log(TkDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  60. {
  61. return new DBContext.Table(connection, tablename)
  62. .Add("end_point", data.end_point)
  63. .Add("channel", (int)data.channel)
  64. .Add("accountId", data.accountId)
  65. .Add("accountName", data.accountName)
  66. .Add("rawContent", data.rawContent)
  67. .Add("rawContent2", data.rawContent2)
  68. .Add("success", data.success)
  69. .Add("message", data.message)
  70. .Add("reason", data.reason)
  71. .Add("content", data.content)
  72. .Add("couponAmount", data.couponAmount)
  73. .Add("itemId", data.itemId)
  74. .Add("itemName", data.itemName)
  75. .Add("pic", data.pic)
  76. .Add("promotionPrice", data.promotionPrice)
  77. .Add("taoToken", data.taoToken)
  78. .Add("shortLinkurl", data.shortLinkurl)
  79. .Add("deeplink_url", data.deeplink_url)
  80. .Add("num_iid", data.num_iid)
  81. .Add("elapsedTime", data.elapsedTime)
  82. .Add("subCode", data.subCode)
  83. .Add("ip", data.ip)
  84. .Add("oaid", data.oaid)
  85. .Add("create_time", data.create_time)
  86. .Create(DBContext.InsertType.NORMAL, transaction);
  87. }
  88. private static int save_tk_parse_logs(TkDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  89. {
  90. return new DBContext.Table(connection, tablename)
  91. .Add("end_point", data.end_point)
  92. .Add("channel", (int)data.channel)
  93. .Add("linkType", (int)data.link_type)
  94. .Add("accountId", data.accountId)
  95. .Add("accountName", data.accountName)
  96. .Add("rawContent", data.rawContent)
  97. .Add("success", data.success)
  98. .Add("message", data.message)
  99. .Add("reason", data.reason)
  100. .Add("content", data.content)
  101. .Add("itemId", data.itemId)
  102. .Add("itemName", data.itemName)
  103. .Add("pic", data.pic)
  104. .Add("couponAmount", data.couponAmount)
  105. .Add("promotionPrice", data.promotionPrice)
  106. .Add("taoToken", data.taoToken)
  107. .Add("shortLinkurl", data.shortLinkurl)
  108. .Add("deeplink_url", data.deeplink_url)
  109. .Add("num_iid", data.num_iid)
  110. .Add("elapsedTime", data.elapsedTime)
  111. .Add("elapsedTime2", data.elapsedTime2)
  112. .Add("elapsedTime3", data.elapsedTime3)
  113. .Add("subCode", data.subCode)
  114. .Add("ip", data.ip)
  115. .Add("oaid", data.oaid)
  116. .Add("create_time", data.create_time)
  117. .Create(DBContext.InsertType.NORMAL, transaction);
  118. }
  119. private static int save_jd_parse_logs(JdDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  120. {
  121. return new DBContext.Table(connection, tablename)
  122. .Add("end_point", data.end_point)
  123. .Add("channel", (int)data.channel)
  124. .Add("accountId", data.accountId)
  125. .Add("accountName", data.accountName)
  126. .Add("rawContent", data.rawContent)
  127. .Add("success", data.success)
  128. .Add("message", data.message)
  129. .Add("reason", data.reason)
  130. .Add("content", data.content)
  131. .Add("itemId", data.itemId)
  132. .Add("itemName", data.itemName)
  133. .Add("pic", data.pic)
  134. .Add("couponAmount", data.couponAmount)
  135. .Add("promotionPrice", data.promotionPrice)
  136. .Add("taoToken", data.taoToken)
  137. .Add("shortLinkurl", data.shortLinkurl)
  138. .Add("deeplink_url", data.deeplink_url)
  139. .Add("elapsedTime", data.elapsedTime)
  140. .Add("subCode", data.subCode)
  141. .Add("ip", data.ip)
  142. .Add("oaid", data.oaid)
  143. .Add("create_time", data.create_time)
  144. .Create(DBContext.InsertType.NORMAL, transaction);
  145. }
  146. public static int BatchInsertLogDB(int limit, CSRedisClient redis)
  147. {
  148. int total = 0;
  149. using var connection = DBContext.GetOpenConnection();
  150. connection.Open();
  151. using var transaction = connection.BeginTransaction();
  152. string cacheKey = ":lock_key:start_comparison_tk";
  153. bool start_comparison_tk = RedisHelper.Get<int>(cacheKey) > 0;
  154. try
  155. {
  156. for (int i = 0; i < limit; i++)
  157. {
  158. var data = redis.LPop<TkDataDTO>(queue_tb_key);
  159. if (data == null) break;
  160. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  161. data.ip.Contains("127.0.0"))
  162. {
  163. save_tk_log(data, "tk_logs_test", connection, transaction);
  164. }
  165. else
  166. {
  167. data.id = save_tk_log(data, "tk_logs", connection, transaction);
  168. if (data.elapsedTime > 1000)
  169. {
  170. save_tk_log(data, "tk_logs_test", connection, transaction);
  171. }
  172. if (data.success)
  173. {
  174. save_tk_log(data, "tk_success_logs", connection, transaction);
  175. }
  176. if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
  177. }
  178. total++;
  179. }
  180. for (int i = 0; i < limit; i++)
  181. {
  182. var data = redis.LPop<JdDataDTO>(queue_jd_key);
  183. if (data == null) break;
  184. new DBContext.Table(connection, "tk_logs")
  185. .Add("end_point", data.end_point)
  186. .Add("channel", (int)data.channel)
  187. .Add("accountId", data.accountId)
  188. .Add("accountName", data.accountName)
  189. .Add("rawContent", data.rawContent)
  190. .Add("rawContent2", data.rawContent2)
  191. .Add("success", data.success)
  192. .Add("message", data.message)
  193. .Add("reason", data.reason)
  194. .Add("shortLinkurl", data.shortLinkurl)
  195. .Add("deeplink_url", data.deeplink_url)
  196. .Add("elapsedTime", data.elapsedTime)
  197. .Add("ip", data.ip)
  198. .Add("oaid", data.oaid)
  199. .Add("create_time", data.create_time)
  200. .Create(DBContext.InsertType.NORMAL, transaction);
  201. total++;
  202. }
  203. for (int i = 0; i < limit; i++)
  204. {
  205. var data = redis.LPop<TkDataDTO>(queue_parse_tb_key);
  206. if (data == null) break;
  207. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  208. data.ip.Contains("127.0.0"))
  209. {
  210. save_tk_parse_logs(data, "tk_parse_logs_test", connection, transaction);
  211. }
  212. else
  213. {
  214. data.id = save_tk_parse_logs(data, "tk_parse_logs", connection, transaction);
  215. //每日分表
  216. if (save_dailys_log)
  217. {
  218. string daily_table = $"tk_parse_logs_{DateTime.Now:yyyyMMdd}";
  219. save_tk_parse_logs(data, daily_table, connection, transaction);
  220. }
  221. if (data.elapsedTime > 1000)
  222. {
  223. save_tk_parse_logs(data, "tk_parse_logs_test", connection, transaction);
  224. }
  225. if (data.success)
  226. {
  227. save_tk_parse_logs(data, "tk_success_parse_logs", connection, transaction);
  228. }
  229. if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
  230. }
  231. if (data.reason.Contains("初步筛选2") && !data.rawContent.Contains("I:/kWqN5t623Hx"))
  232. {
  233. save_tk_parse_logs(data, "tk_parse_logs_test2", connection, transaction);
  234. }
  235. if (data.reason.Contains("初步筛选1.5"))
  236. {
  237. save_tk_parse_logs(data, "tk_parse_logs_multi_token", connection, transaction);
  238. }
  239. if (data.reason.Contains("霸下验证码"))
  240. {
  241. save_tk_parse_logs(data, "tk_parse_logs_captcha", connection, transaction);
  242. }
  243. total++;
  244. }
  245. for (int i = 0; i < limit; i++)
  246. {
  247. var data = redis.LPop<JdDataDTO>(queue_parse_jd_key);
  248. if (data == null) break;
  249. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  250. data.ip.Contains("127.0.0"))
  251. {
  252. save_jd_parse_logs(data, "jd_parse_logs_test", connection, transaction);
  253. }
  254. else
  255. {
  256. save_jd_parse_logs(data, "jd_parse_logs", connection, transaction);
  257. if (save_dailys_log)
  258. {
  259. string daily_table = $"jd_parse_logs_{DateTime.Now:yyyyMMdd}";
  260. save_jd_parse_logs(data, daily_table, connection, transaction);
  261. }
  262. if (data.elapsedTime > 1000)
  263. {
  264. save_jd_parse_logs(data, "jd_parse_logs_test", connection, transaction);
  265. }
  266. if (data.success)
  267. {
  268. save_jd_parse_logs(data, "jd_parse_logs_success", connection, transaction);
  269. }
  270. }
  271. total++;
  272. }
  273. for (int i = 0; i < limit; i++)
  274. {
  275. var data = redis.LPop<DyDataDTO>(queue_parse_dy_key);
  276. if (data == null) break;
  277. new DBContext.Table(connection, "tk_parse_logs")
  278. .Add("end_point", data.end_point)
  279. .Add("channel", (int)data.channel)
  280. .Add("accountId", data.accountId)
  281. .Add("accountName", data.accountName)
  282. .Add("rawContent", data.rawContent)
  283. .Add("success", data.success)
  284. .Add("message", data.message)
  285. .Add("reason", data.reason)
  286. .Add("content", data.content)
  287. .Add("itemId", data.itemId)
  288. .Add("itemName", data.itemName)
  289. .Add("pic", data.pic)
  290. .Add("couponAmount", data.couponAmount)
  291. .Add("promotionPrice", data.promotionPrice)
  292. .Add("taoToken", data.taoToken)
  293. .Add("shortLinkurl", data.shortLinkurl)
  294. .Add("deeplink_url", data.deeplink_url)
  295. .Add("elapsedTime", data.elapsedTime)
  296. .Add("subCode", data.subCode)
  297. .Add("ip", data.ip)
  298. .Add("oaid", data.oaid)
  299. .Add("create_time", data.create_time)
  300. .Create(DBContext.InsertType.NORMAL, transaction);
  301. total++;
  302. }
  303. for (int i = 0; i < limit; i++)
  304. {
  305. var data = redis.LPop<ToolParseDataDTO>(queue_parse_tool_key);
  306. if (data == null) break;
  307. new DBContext.Table(connection, "tool_parse_logs")
  308. .Add("end_point", data.end_point)
  309. .Add("channel", (int)data.channel)
  310. .Add("rawContent", data.rawContent)
  311. .Add("success", data.success)
  312. .Add("message", data.message)
  313. .Add("reason", data.reason)
  314. .Add("content", data.content)
  315. .Add("taoToken", data.taoToken)
  316. .Add("shortLinkurl", data.shortLinkurl)
  317. .Add("deeplink_url", data.deeplink_url)
  318. .Add("elapsedTime", data.elapsedTime)
  319. .Add("ip", data.ip)
  320. .Add("oaid", data.oaid)
  321. .Add("create_time", data.create_time)
  322. .Create(DBContext.InsertType.NORMAL, transaction);
  323. total++;
  324. }
  325. for (int i = 0; i < limit; i++)
  326. {
  327. var data = redis.LPop<UnionCouponDTO>(queue_coupon_key);
  328. if (data == null) break;
  329. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  330. data.ip.Contains("127.0.0"))
  331. {
  332. var test_data = data.Convert2Json().Convert2Object<TestUnionCouponDTO>();
  333. connection.Insert(test_data);
  334. }
  335. else
  336. {
  337. connection.Insert(data);
  338. if (data.success)
  339. {
  340. var success_data = data.Convert2Json().Convert2Object<SuccessUnionCouponDTO>();
  341. connection.Insert(success_data);
  342. }
  343. }
  344. total++;
  345. }
  346. for (int i = 0; i < limit; i++)
  347. {
  348. var data = redis.LPop<UnionCpsDTO>(queue_cps_key);
  349. if (data == null) break;
  350. if (data.ip.Contains("127.0.0"))
  351. {
  352. var test_data = data.Convert2Json().Convert2Object<TestUnionCpsDTO>();
  353. connection.Insert(test_data);
  354. }
  355. else
  356. {
  357. connection.Insert(data);
  358. if (data.success)
  359. {
  360. var success_data = data.Convert2Json().Convert2Object<SuccessUnionCpsDTO>();
  361. connection.Insert(success_data);
  362. }
  363. }
  364. total++;
  365. }
  366. for (int i = 0; i < limit; i++)
  367. {
  368. var data = redis.LPop<PromotionQueryDTO>(promotion_img_key);
  369. if (data == null) break;
  370. connection.Insert(data);
  371. total++;
  372. }
  373. transaction.Commit();
  374. }
  375. catch (Exception ex)
  376. {
  377. transaction.Rollback();
  378. _ = new LoggerLibrary("database_error", "parse_log")
  379. .Info(ex.Message, ex.StackTrace)
  380. .SaveAsync();
  381. NotifyCore.Notify(new NifyMessage
  382. {
  383. message = $"【写入日志异常】\n{ex.Message}\n{ex.StackTrace}",
  384. priority = NifyMessagePriority.high,
  385. tags = ["red_circle"]
  386. });
  387. }
  388. finally
  389. {
  390. connection.Close();
  391. }
  392. return total;
  393. }
  394. public static async Task PromotionImgLogAsync(PromotionQueryDTO response)
  395. {
  396. try
  397. {
  398. var ts = DateTime.Now - response.create_time;
  399. response.elapsedTime = (int)ts.TotalMilliseconds;
  400. _ = RedisHelper.RPushAsync(promotion_img_key, response);
  401. //using var connection = DBContext.GetOpenConnection();
  402. //connection.Insert(response);
  403. savePromotionCache(response.accountId, response.accountName, response.success, response.message, response.reason);
  404. }
  405. catch (Exception ex) { }
  406. }
  407. public static async Task LogAsync(JdDataDTO response)
  408. {
  409. try
  410. {
  411. var ts = DateTime.Now - response.create_time;
  412. response.elapsedTime = (int)ts.TotalMilliseconds;
  413. _ = RedisHelper.RPushAsync(queue_jd_key, response);
  414. if (!response.ip.Contains("127.0.0"))
  415. {
  416. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  417. }
  418. }
  419. catch (Exception ex) { }
  420. }
  421. public static async Task LogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
  422. {
  423. try
  424. {
  425. var ts = DateTime.Now - response.create_time;
  426. response.elapsedTime = (int)ts.TotalMilliseconds;
  427. _ = RedisHelper.RPushAsync(queue_tb_key, response);
  428. if (!response.ip.Contains("127.0.0"))
  429. {
  430. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  431. }
  432. if (!response.success && "nologin".Equals(response.message))
  433. {
  434. switch (response.channel)
  435. {
  436. case TkChannelEnum.tb:
  437. await Task.Run(() =>
  438. {
  439. if (alimamaPlus != null)
  440. {
  441. (bool success, string message) = alimamaPlus.RenewCookie();
  442. if (success) return;
  443. }
  444. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  445. });
  446. break;
  447. }
  448. }
  449. if ("没有匹配账号".Equals(response.reason))
  450. {
  451. TkPoolCore.AccountExhausted();
  452. }
  453. }
  454. catch (Exception ex)
  455. {
  456. _ = new LoggerLibrary("unionParse", "database_error")
  457. .Info(response.rawContent, response.rawContent2)
  458. .Info(response.Convert2Json())
  459. .Info(ex.Message, ex.StackTrace)
  460. .SaveAsync();
  461. }
  462. }
  463. public static async Task ParseLogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
  464. {
  465. #if DEBUG
  466. //return;
  467. #endif
  468. try
  469. {
  470. var ts = DateTime.Now - response.create_time;
  471. response.elapsedTime = (int)ts.TotalMilliseconds;
  472. _ = RedisHelper.RPushAsync(queue_parse_tb_key, response);
  473. if (response.success)
  474. {
  475. _ = saveUnionCouponParseCacheAsync(response);
  476. }
  477. if (!response.ip.Contains("127.0.0"))
  478. {
  479. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  480. }
  481. if (!string.IsNullOrEmpty(response.itemId)) TkOrderTrackingCore.SaveLinkSummary(response);
  482. if (!response.success && "nologin".Equals(response.message))
  483. {
  484. switch (response.channel)
  485. {
  486. case TkChannelEnum.tb:
  487. await Task.Run(() =>
  488. {
  489. if (alimamaPlus != null)
  490. {
  491. (bool success, string message) = alimamaPlus.RenewCookie();
  492. if (success) return;
  493. }
  494. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}");
  495. }); break;
  496. }
  497. }
  498. if (response.subCode == TkSubCodeEnum.Captcha || "霸下验证码".Equals(response.reason))
  499. {
  500. TkPoolCore.Suspend(response.end_point, response.accountId, response.accountName, "霸下验证码");
  501. }
  502. }
  503. catch (Exception ex)
  504. {
  505. _ = new LoggerLibrary("unionParse", "database_error")
  506. .Info(response.rawContent)
  507. .Info(response.Convert2Json())
  508. .Info(ex.Message, ex.StackTrace)
  509. .SaveAsync();
  510. }
  511. }
  512. public static async Task CouponLogAsync(UnionCouponDTO response, AlimamaPlus? alimamaPlus = null)
  513. {
  514. try
  515. {
  516. var ts = DateTime.Now - response.create_time;
  517. response.elapsedTime = (int)ts.TotalMilliseconds;
  518. _ = RedisHelper.RPushAsync(queue_coupon_key, response);
  519. if (!response.ip.Contains("127.0.0"))
  520. {
  521. saveCouponCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  522. }
  523. if (!response.success && "nologin".Equals(response.message))
  524. {
  525. switch (response.channel)
  526. {
  527. case TkChannelEnum.tb:
  528. await Task.Run(() =>
  529. {
  530. if (alimamaPlus != null)
  531. {
  532. (bool success, string message) = alimamaPlus.RenewCookie();
  533. if (success) return;
  534. }
  535. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}");
  536. }); break;
  537. }
  538. }
  539. }
  540. catch (Exception ex)
  541. {
  542. _ = new LoggerLibrary("unionCoupon", "database_error")
  543. .Info(response.rawContent)
  544. .Info(response.Convert2Json())
  545. .Info(ex.Message, ex.StackTrace)
  546. .SaveAsync();
  547. }
  548. }
  549. public static async Task CpsLogAsync(UnionCpsDTO response, AlimamaPlus? alimamaPlus = null)
  550. {
  551. try
  552. {
  553. var ts = DateTime.Now - response.create_time;
  554. response.elapsedTime = (int)ts.TotalMilliseconds;
  555. _ = RedisHelper.RPushAsync(queue_cps_key, response);
  556. if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
  557. if (!response.ip.Contains("127.0.0"))
  558. {
  559. saveCpsCache(response.channel.ToString(), response.accountId, response.success, response.message, response.reason);
  560. }
  561. }
  562. catch (Exception ex)
  563. {
  564. _ = new LoggerLibrary("unionCps", "database_error")
  565. .Info(response.rawContent)
  566. .Info(response.Convert2Json())
  567. .Info(ex.Message, ex.StackTrace)
  568. .SaveAsync();
  569. }
  570. }
  571. public static async Task ParseLogAsync(JdDataDTO response)
  572. {
  573. try
  574. {
  575. var ts = DateTime.Now - response.create_time;
  576. response.elapsedTime = (int)ts.TotalMilliseconds;
  577. _ = RedisHelper.RPushAsync(queue_parse_jd_key, response);
  578. if (!response.ip.Contains("127.0.0"))
  579. {
  580. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  581. }
  582. if (response.success || response.message.Equals("转链失败"))
  583. {
  584. JdPoolCore.CallsIncrBy(response.accountId);
  585. }
  586. //CallsIncrBy
  587. if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
  588. if (!response.success && ("nologin".Equals(response.reason) ||
  589. "方法不存在".Equals(response.reason) ||
  590. "未登录".Equals(response.reason)))
  591. {
  592. await Task.Run(() =>
  593. {
  594. JdPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  595. });
  596. //switch (response.channel)
  597. //{
  598. // case TkChannelEnum.tb:
  599. // //await Task.Run(() =>
  600. // //{
  601. // // if (alimamaPlus != null)
  602. // // {
  603. // // (bool success, string message) = alimamaPlus.RenewCookie();
  604. // // if (success) return;
  605. // // }
  606. // // TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  607. // //});
  608. // break;
  609. //}
  610. }
  611. if ("没有匹配账号".Equals(response.reason))
  612. {
  613. JdPoolCore.AccountExhausted();
  614. }
  615. }
  616. catch (Exception ex) { }
  617. }
  618. public static async Task ParseLogAsync(DyDataDTO response)
  619. {
  620. try
  621. {
  622. var ts = DateTime.Now - response.create_time;
  623. response.elapsedTime = (int)ts.TotalMilliseconds;
  624. _ = RedisHelper.RPushAsync(queue_parse_dy_key, response);
  625. if (!response.ip.Contains("127.0.0"))
  626. {
  627. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  628. }
  629. }
  630. catch (Exception ex) { }
  631. }
  632. public static async Task ParseLogAsync(ToolParseDataDTO response)
  633. {
  634. try
  635. {
  636. var ts = DateTime.Now - response.create_time;
  637. response.elapsedTime = (int)ts.TotalMilliseconds;
  638. _ = RedisHelper.RPushAsync(queue_parse_tool_key, response);
  639. if (!response.ip.Contains("127.0.0"))
  640. {
  641. saveParseCache(response.channel.ToString(), 0, "tool", response.success, response.message, response.reason);
  642. }
  643. }
  644. catch (Exception ex) { }
  645. }
  646. private static void saveCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  647. {
  648. saveAccountCache("all", success, message, reason);
  649. saveAccountCache($"{channel}", success, message, reason);
  650. saveAccountCache($"{accountName}", success, message, reason);
  651. if (accountId != 0)
  652. {
  653. //todo 放着跑两天,要将读取的地方改成读取accountid
  654. saveAccountCache($"{channel}_{accountId}", success, message, reason);
  655. }
  656. }
  657. private static void saveAccountCache(string accountName, bool success, string message, string reason)
  658. {
  659. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMM}");
  660. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMdd}");
  661. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  662. string result = success ? "success" : "fail";
  663. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  664. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  665. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  666. if (!string.IsNullOrEmpty(message))
  667. {
  668. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  669. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  670. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  671. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  672. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  673. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  674. RedisHelper.IncrBy($":total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
  675. RedisHelper.IncrBy($":total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  676. RedisHelper.IncrBy($":total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  677. }
  678. if (!string.IsNullOrEmpty(reason))
  679. {
  680. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  681. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  682. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  683. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  684. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  685. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  686. RedisHelper.IncrBy($":total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  687. RedisHelper.IncrBy($":total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  688. RedisHelper.IncrBy($":total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  689. }
  690. }
  691. private static async Task saveUnionCouponParseCacheAsync(TkDataDTO data)
  692. {
  693. string cacheKey = $":cache:parse:{data.ip}_{data.oaid}_{data.itemId}";
  694. await EndPointCore.ProcessEndPointNodesAsync(node =>
  695. {
  696. if (!node.is_coupon_api) return Task.CompletedTask;
  697. if (string.IsNullOrEmpty(node.redis_server)) return Task.CompletedTask;
  698. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  699. redis.Set(cacheKey, 1, 2 * 86400);
  700. return Task.CompletedTask;
  701. });
  702. }
  703. private static void saveClientRequestTotal(TkChannelEnum channel, string ip, string oaid)
  704. {
  705. string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
  706. RedisHelper.IncrBy(cacheKey);
  707. RedisHelper.Expire(cacheKey, 86400);
  708. if (!string.IsNullOrEmpty(oaid))
  709. {
  710. cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
  711. RedisHelper.IncrBy(cacheKey);
  712. RedisHelper.Expire(cacheKey, 86400);
  713. }
  714. }
  715. public static int getClientRequestTotalByOAID(TkChannelEnum channel, string oaid)
  716. {
  717. if (string.IsNullOrEmpty(oaid)) return 0;
  718. string cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
  719. return RedisHelper.Get<int>(cacheKey);
  720. }
  721. public static int getClientRequestTotalByIp(TkChannelEnum channel, string ip)
  722. {
  723. if (string.IsNullOrEmpty(ip)) return 0;
  724. string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
  725. return RedisHelper.Get<int>(cacheKey);
  726. }
  727. private static void saveClientRequestTotal(CpsChannelEnum channel, string ip, string oaid)
  728. {
  729. string cacheKey = $":cache:cps_{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
  730. RedisHelper.IncrBy(cacheKey);
  731. RedisHelper.Expire(cacheKey, 86400);
  732. if (!string.IsNullOrEmpty(oaid))
  733. {
  734. cacheKey = $":cache:cps_{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
  735. RedisHelper.IncrBy(cacheKey);
  736. RedisHelper.Expire(cacheKey, 86400);
  737. }
  738. }
  739. public static int getClientRequestTotalByOAID(CpsChannelEnum channel, string oaid)
  740. {
  741. if (string.IsNullOrEmpty(oaid)) return 0;
  742. string cacheKey = $":cache:cps_{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
  743. return RedisHelper.Get<int>(cacheKey);
  744. }
  745. public static int getClientRequestTotalByIp(CpsChannelEnum channel, string ip)
  746. {
  747. if (string.IsNullOrEmpty(ip)) return 0;
  748. string cacheKey = $":cache:cps_{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
  749. return RedisHelper.Get<int>(cacheKey);
  750. }
  751. private static void saveParseCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  752. {
  753. saveParseAccountCache("all", success, message, reason);
  754. saveParseAccountCache($"{channel}", success, message, reason);
  755. saveParseAccountCache($"{accountName}", success, message, reason);
  756. if (accountId != 0)
  757. {
  758. //todo 放着跑两天,要将读取的地方改成读取accountid
  759. saveParseAccountCache($"{channel}_{accountId}", success, message, reason);
  760. }
  761. }
  762. private static void saveParseAccountCache(string accountName, bool success, string message, string reason)
  763. {
  764. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMM}");
  765. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  766. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  767. string result = success ? "success" : "fail";
  768. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  769. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  770. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  771. if (!string.IsNullOrEmpty(message))
  772. {
  773. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  774. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  775. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  776. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  777. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  778. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  779. RedisHelper.IncrBy($":parse_total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
  780. RedisHelper.IncrBy($":parse_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  781. RedisHelper.IncrBy($":parse_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  782. }
  783. if (!string.IsNullOrEmpty(reason))
  784. {
  785. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  786. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  787. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  788. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  789. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  790. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  791. RedisHelper.IncrBy($":parse_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  792. RedisHelper.IncrBy($":parse_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  793. RedisHelper.IncrBy($":parse_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  794. }
  795. }
  796. private static void savePromotionCache(int accountId, string accountName, bool success, string message, string reason)
  797. {
  798. savePromotionAccountCache("all", success, message, reason);
  799. savePromotionAccountCache($"{accountId}", success, message, reason);
  800. }
  801. private static void savePromotionAccountCache(string accountName, bool success, string message, string reason)
  802. {
  803. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMM}");
  804. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  805. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  806. string result = success ? "success" : "fail";
  807. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  808. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  809. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  810. if (!string.IsNullOrEmpty(message))
  811. {
  812. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  813. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  814. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  815. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  816. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  817. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  818. RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
  819. RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  820. RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  821. }
  822. if (!string.IsNullOrEmpty(reason))
  823. {
  824. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  825. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  826. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  827. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  828. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  829. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  830. RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  831. RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  832. RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  833. }
  834. }
  835. private static void saveCouponCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  836. {
  837. saveAccountCouponCache("all", success, message, reason);
  838. saveAccountCouponCache($"{channel}", success, message, reason);
  839. if (accountId != 0)
  840. {
  841. saveAccountCouponCache($"{channel}_{accountId}", success, message, reason);
  842. }
  843. }
  844. private static void saveAccountCouponCache(string accountName, bool success, string message, string reason)
  845. {
  846. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMM}");
  847. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  848. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  849. string result = success ? "success" : "fail";
  850. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  851. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  852. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  853. if (!string.IsNullOrEmpty(message))
  854. {
  855. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  856. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  857. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  858. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  859. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  860. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  861. RedisHelper.IncrBy($":coupon_total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
  862. RedisHelper.IncrBy($":coupon_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  863. RedisHelper.IncrBy($":coupon_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  864. }
  865. if (!string.IsNullOrEmpty(reason))
  866. {
  867. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  868. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  869. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  870. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  871. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  872. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  873. RedisHelper.IncrBy($":coupon_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  874. RedisHelper.IncrBy($":coupon_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  875. RedisHelper.IncrBy($":coupon_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  876. }
  877. }
  878. private static void saveCpsCache(string channel, int accountId, bool success, string message, string reason)
  879. {
  880. saveAccountCpsCache("all", success, message, reason);
  881. saveAccountCpsCache($"{channel}", success, message, reason);
  882. if (accountId != 0)
  883. {
  884. saveAccountCpsCache($"{channel}_{accountId}", success, message, reason);
  885. }
  886. }
  887. private static void saveAccountCpsCache(string flagName, bool success, string message, string reason)
  888. {
  889. RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMM}");
  890. RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMMdd}");
  891. RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMMddHH}");
  892. string result = success ? "success" : "fail";
  893. RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMM}");
  894. RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMMdd}");
  895. RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMMddHH}");
  896. if (!string.IsNullOrEmpty(message))
  897. {
  898. RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMM}", message);
  899. RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMMdd}", message);
  900. RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMMddHH}", message);
  901. RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMM}");
  902. RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMMdd}");
  903. RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMMddHH}");
  904. RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMM}");
  905. RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  906. RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  907. }
  908. if (!string.IsNullOrEmpty(reason))
  909. {
  910. RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMM}", reason);
  911. RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  912. RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  913. RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMM}");
  914. RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMMdd}");
  915. RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  916. RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  917. RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  918. RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  919. }
  920. }
  921. public static int GetTotal(string keyname, bool all_node = true)
  922. {
  923. //:coupon_total:tb:20240706
  924. //:coupon_total:tb:success:20240706
  925. //:coupon_total:tb:放弃转链:20240706
  926. var result = EndPointCore.ProcessEndPointNodes<int>(node =>
  927. {
  928. if (!node.is_public_api) return 0;
  929. if (string.IsNullOrEmpty(node.redis_server)) return 0;
  930. if (!all_node)
  931. {
  932. if (CenterHub.IsCenter)
  933. {
  934. if (node.is_coupon_api) { return 0; }
  935. }
  936. else
  937. {
  938. if (!node.is_coupon_api) { return 0; }
  939. }
  940. }
  941. #if DEBUG
  942. switch (node.name)
  943. {
  944. case "bj":
  945. node.redis_server = "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  946. break;
  947. case "gz":
  948. node.redis_server = "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  949. break;
  950. case "coupon1":
  951. node.redis_server = "c1api.molilian.com:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=coupon";
  952. break;
  953. default: return 0;
  954. }
  955. #endif
  956. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  957. int count = redis.Get<int>(keyname);
  958. return count;
  959. });
  960. return result.Sum();
  961. }
  962. public static string[] GetTotalKeys(string keyname, bool all_node = true)
  963. {
  964. var result = EndPointCore.ProcessEndPointNodes<string[]>(node =>
  965. {
  966. if (!node.is_public_api) return [];
  967. if (string.IsNullOrEmpty(node.redis_server)) return [];
  968. if (!all_node)
  969. {
  970. if (CenterHub.IsCenter)
  971. {
  972. if (node.is_coupon_api) { return []; }
  973. }
  974. else
  975. {
  976. if (!node.is_coupon_api) { return []; }
  977. }
  978. }
  979. #if DEBUG
  980. switch (node.name)
  981. {
  982. case "bj":
  983. node.redis_server = "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  984. break;
  985. case "gz":
  986. node.redis_server = "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  987. break;
  988. case "coupon1":
  989. node.redis_server = "c1api.molilian.com:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=coupon";
  990. break;
  991. default: return [];
  992. }
  993. #endif
  994. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  995. string[] message_keys = redis.SMembers(keyname);
  996. return message_keys;
  997. });
  998. string[] message_keys = [];
  999. foreach (var arr in result)
  1000. {
  1001. message_keys = message_keys.Union(arr).ToArray();
  1002. }
  1003. return message_keys;
  1004. }
  1005. //if (item.total_count > 0) continue;
  1006. //item.total_count = RedisHelper.Get<int>($":total:all:{item.report_date:yyyyMMdd}");
  1007. //if (item.total_count == 0) continue;
  1008. //item.success_count = RedisHelper.Get<int>($":total:all:success:{item.report_date:yyyyMMdd}");
  1009. //item.abandon_count = RedisHelper.Get<int>($":total:all:放弃转链:{item.report_date:yyyyMMdd}");
  1010. }
  1011. }