TkLogCore.cs 52 KB

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