TkLogCore.cs 60 KB

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