TkLogCore.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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. namespace molilian.core
  18. {
  19. public class TkLogCore
  20. {
  21. static string queue_tb_key = "queue:logs:tb";
  22. static string queue_jd_key = "queue:logs:jd";
  23. static string queue_parse_tb_key = "queue:parse_logs:tb";
  24. static string queue_parse_jd_key = "queue:parse_logs:jd";
  25. static string queue_parse_dy_key = "queue:parse_logs:dy";
  26. static string queue_parse_tool_key = "queue:parse_logs:tool";
  27. static string queue_coupon_key = "queue:coupon_logs";
  28. public static int BatchInsertLogDB(int limit)
  29. {
  30. var result = EndPointCore.ProcessEndPointNodes<int>(node =>
  31. {
  32. if (!node.is_public_api) return 0;
  33. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  34. return BatchInsertLogDB(limit, redis);
  35. });
  36. return result.Sum();
  37. }
  38. public static int BatchInsertLogDB(int limit, CSRedisClient redis)
  39. {
  40. int total = 0;
  41. using var connection = DBContext.GetOpenConnection();
  42. connection.Open();
  43. using var transaction = connection.BeginTransaction();
  44. try
  45. {
  46. for (int i = 0; i < limit; i++)
  47. {
  48. var data = redis.LPop<TkDataDTO>(queue_tb_key);
  49. if (data == null) break;
  50. data.id = new DBContext.Table(connection, "tk_logs")
  51. .Add("end_point", data.end_point)
  52. .Add("channel", (int)data.channel)
  53. .Add("accountId", data.accountId)
  54. .Add("accountName", data.accountName)
  55. .Add("rawContent", data.rawContent)
  56. .Add("rawContent2", data.rawContent2)
  57. .Add("success", data.success)
  58. .Add("message", data.message)
  59. .Add("reason", data.reason)
  60. .Add("content", data.content)
  61. .Add("couponAmount", data.couponAmount)
  62. .Add("itemId", data.itemId)
  63. .Add("itemName", data.itemName)
  64. .Add("pic", data.pic)
  65. .Add("promotionPrice", data.promotionPrice)
  66. .Add("taoToken", data.taoToken)
  67. .Add("shortLinkurl", data.shortLinkurl)
  68. .Add("deeplink_url", data.deeplink_url)
  69. .Add("num_iid", data.num_iid)
  70. .Add("elapsedTime", data.elapsedTime)
  71. .Add("ip", data.ip)
  72. .Add("oaid", data.oaid)
  73. .Add("create_time", data.create_time)
  74. .Create(DBContext.InsertType.NORMAL, transaction);
  75. if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
  76. total++;
  77. }
  78. for (int i = 0; i < limit; i++)
  79. {
  80. var data = redis.LPop<JdDataDTO>(queue_jd_key);
  81. if (data == null) break;
  82. new DBContext.Table(connection, "tk_logs")
  83. .Add("end_point", data.end_point)
  84. .Add("channel", (int)data.channel)
  85. .Add("accountId", data.accountId)
  86. .Add("accountName", data.accountName)
  87. .Add("rawContent", data.rawContent)
  88. .Add("rawContent2", data.rawContent2)
  89. .Add("success", data.success)
  90. .Add("message", data.message)
  91. .Add("reason", data.reason)
  92. .Add("shortLinkurl", data.shortLinkurl)
  93. .Add("deeplink_url", data.deeplink_url)
  94. .Add("elapsedTime", data.elapsedTime)
  95. .Add("ip", data.ip)
  96. .Add("oaid", data.oaid)
  97. .Add("create_time", data.create_time)
  98. .Create(DBContext.InsertType.NORMAL, transaction);
  99. total++;
  100. }
  101. for (int i = 0; i < limit; i++)
  102. {
  103. var data = redis.LPop<TkDataDTO>(queue_parse_tb_key);
  104. if (data == null) break;
  105. data.id = new DBContext.Table(connection, "tk_parse_logs")
  106. .Add("end_point", data.end_point)
  107. .Add("channel", (int)data.channel)
  108. .Add("accountId", data.accountId)
  109. .Add("accountName", data.accountName)
  110. .Add("rawContent", data.rawContent)
  111. .Add("success", data.success)
  112. .Add("message", data.message)
  113. .Add("reason", data.reason)
  114. .Add("content", data.content)
  115. .Add("itemId", data.itemId)
  116. .Add("itemName", data.itemName)
  117. .Add("pic", data.pic)
  118. .Add("couponAmount", data.couponAmount)
  119. .Add("promotionPrice", data.promotionPrice)
  120. .Add("taoToken", data.taoToken)
  121. .Add("shortLinkurl", data.shortLinkurl)
  122. .Add("deeplink_url", data.deeplink_url)
  123. .Add("num_iid", data.num_iid)
  124. .Add("elapsedTime", data.elapsedTime)
  125. .Add("elapsedTime2", data.elapsedTime2)
  126. .Add("elapsedTime3", data.elapsedTime3)
  127. .Add("ip", data.ip)
  128. .Add("oaid", data.oaid)
  129. .Add("create_time", data.create_time)
  130. .Create(DBContext.InsertType.NORMAL, transaction);
  131. if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
  132. total++;
  133. }
  134. for (int i = 0; i < limit; i++)
  135. {
  136. var data = redis.LPop<JdDataDTO>(queue_parse_jd_key);
  137. if (data == null) break;
  138. new DBContext.Table(connection, "tk_parse_logs")
  139. .Add("end_point", data.end_point)
  140. .Add("channel", (int)data.channel)
  141. .Add("accountId", data.accountId)
  142. .Add("accountName", data.accountName)
  143. .Add("rawContent", data.rawContent)
  144. .Add("success", data.success)
  145. .Add("message", data.message)
  146. .Add("reason", data.reason)
  147. .Add("content", data.content)
  148. .Add("itemId", data.itemId)
  149. .Add("itemName", data.itemName)
  150. .Add("pic", data.pic)
  151. .Add("couponAmount", data.couponAmount)
  152. .Add("promotionPrice", data.promotionPrice)
  153. .Add("taoToken", data.taoToken)
  154. .Add("shortLinkurl", data.shortLinkurl)
  155. .Add("deeplink_url", data.deeplink_url)
  156. .Add("elapsedTime", data.elapsedTime)
  157. .Add("ip", data.ip)
  158. .Add("oaid", data.oaid)
  159. .Add("create_time", data.create_time)
  160. .Create(DBContext.InsertType.NORMAL, transaction);
  161. total++;
  162. }
  163. for (int i = 0; i < limit; i++)
  164. {
  165. var data = redis.LPop<DyDataDTO>(queue_parse_dy_key);
  166. if (data == null) break;
  167. new DBContext.Table(connection, "tk_parse_logs")
  168. .Add("end_point", data.end_point)
  169. .Add("channel", (int)data.channel)
  170. .Add("accountId", data.accountId)
  171. .Add("accountName", data.accountName)
  172. .Add("rawContent", data.rawContent)
  173. .Add("success", data.success)
  174. .Add("message", data.message)
  175. .Add("reason", data.reason)
  176. .Add("content", data.content)
  177. .Add("itemId", data.itemId)
  178. .Add("itemName", data.itemName)
  179. .Add("pic", data.pic)
  180. .Add("couponAmount", data.couponAmount)
  181. .Add("promotionPrice", data.promotionPrice)
  182. .Add("taoToken", data.taoToken)
  183. .Add("shortLinkurl", data.shortLinkurl)
  184. .Add("deeplink_url", data.deeplink_url)
  185. .Add("elapsedTime", data.elapsedTime)
  186. .Add("ip", data.ip)
  187. .Add("oaid", data.oaid)
  188. .Add("create_time", data.create_time)
  189. .Create(DBContext.InsertType.NORMAL, transaction);
  190. total++;
  191. }
  192. for (int i = 0; i < limit; i++)
  193. {
  194. var data = redis.LPop<ToolParseDataDTO>(queue_parse_tool_key);
  195. if (data == null) break;
  196. new DBContext.Table(connection, "tool_parse_logs")
  197. .Add("end_point", data.end_point)
  198. .Add("channel", (int)data.channel)
  199. .Add("rawContent", data.rawContent)
  200. .Add("success", data.success)
  201. .Add("message", data.message)
  202. .Add("reason", data.reason)
  203. .Add("content", data.content)
  204. .Add("taoToken", data.taoToken)
  205. .Add("shortLinkurl", data.shortLinkurl)
  206. .Add("deeplink_url", data.deeplink_url)
  207. .Add("elapsedTime", data.elapsedTime)
  208. .Add("ip", data.ip)
  209. .Add("oaid", data.oaid)
  210. .Add("create_time", data.create_time)
  211. .Create(DBContext.InsertType.NORMAL, transaction);
  212. total++;
  213. }
  214. for (int i = 0; i < limit; i++)
  215. {
  216. var data = redis.LPop<UnionCouponDTO>(queue_coupon_key);
  217. if (data == null) break;
  218. connection.Insert(data);
  219. total++;
  220. }
  221. transaction.Commit();
  222. }
  223. catch (Exception ex)
  224. {
  225. transaction.Rollback();
  226. _ = new LoggerLibrary("database_error", "parse_log")
  227. .Info(ex.Message, ex.StackTrace)
  228. .SaveAsync();
  229. NotifyCore.Notify(new NifyMessage
  230. {
  231. message = $"【写入日志异常】\n{ex.Message}\n{ex.StackTrace}",
  232. priority = NifyMessagePriority.high,
  233. tags = ["red_circle"]
  234. });
  235. }
  236. finally
  237. {
  238. connection.Close();
  239. }
  240. return total;
  241. }
  242. public static async Task LogAsync(JdDataDTO response)
  243. {
  244. try
  245. {
  246. var ts = DateTime.Now - response.create_time;
  247. response.elapsedTime = (int)ts.TotalMilliseconds;
  248. RedisHelper.RPush(queue_jd_key, response);
  249. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  250. }
  251. catch (Exception ex) { }
  252. }
  253. public static async Task LogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
  254. {
  255. try
  256. {
  257. var ts = DateTime.Now - response.create_time;
  258. response.elapsedTime = (int)ts.TotalMilliseconds;
  259. RedisHelper.RPush(queue_tb_key, response);
  260. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  261. if (!response.success && "nologin".Equals(response.message))
  262. {
  263. switch (response.channel)
  264. {
  265. case TkChannelEnum.tb:
  266. await Task.Run(() =>
  267. {
  268. if (alimamaPlus != null)
  269. {
  270. (bool success, string message) = alimamaPlus.RenewCookie();
  271. if (success) return;
  272. }
  273. TkPoolCore.Disabled(response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  274. });
  275. break;
  276. }
  277. }
  278. if ("没有匹配账号".Equals(response.reason))
  279. {
  280. TkPoolCore.AccountExhausted();
  281. }
  282. }
  283. catch (Exception ex)
  284. {
  285. _ = new LoggerLibrary("unionParse", "database_error")
  286. .Info(response.rawContent, response.rawContent2)
  287. .Info(response.Convert2Json())
  288. .Info(ex.Message, ex.StackTrace)
  289. .SaveAsync();
  290. }
  291. }
  292. public static async Task ParseLogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
  293. {
  294. #if DEBUG
  295. //return;
  296. #endif
  297. try
  298. {
  299. var ts = DateTime.Now - response.create_time;
  300. response.elapsedTime = (int)ts.TotalMilliseconds;
  301. RedisHelper.RPush(queue_parse_tb_key, response);
  302. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  303. if (!string.IsNullOrEmpty(response.itemId)) TkOrderTrackingCore.SaveLinkSummary(response);
  304. if (!response.success && "nologin".Equals(response.message))
  305. {
  306. switch (response.channel)
  307. {
  308. case TkChannelEnum.tb:
  309. await Task.Run(() =>
  310. {
  311. if (alimamaPlus != null)
  312. {
  313. (bool success, string message) = alimamaPlus.RenewCookie();
  314. if (success) return;
  315. }
  316. TkPoolCore.Disabled(response.accountName, $"{response.rawContent}");
  317. }); break;
  318. }
  319. }
  320. }
  321. catch (Exception ex)
  322. {
  323. _ = new LoggerLibrary("unionParse", "database_error")
  324. .Info(response.rawContent)
  325. .Info(response.Convert2Json())
  326. .Info(ex.Message, ex.StackTrace)
  327. .SaveAsync();
  328. }
  329. }
  330. public static async Task CouponLogAsync(UnionCouponDTO response, AlimamaPlus? alimamaPlus = null)
  331. {
  332. try
  333. {
  334. var ts = DateTime.Now - response.create_time;
  335. response.elapsedTime = (int)ts.TotalMilliseconds;
  336. RedisHelper.RPush(queue_coupon_key, response);
  337. saveCouponCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  338. if (!response.success && "nologin".Equals(response.message))
  339. {
  340. switch (response.channel)
  341. {
  342. case TkChannelEnum.tb:
  343. await Task.Run(() =>
  344. {
  345. if (alimamaPlus != null)
  346. {
  347. (bool success, string message) = alimamaPlus.RenewCookie();
  348. if (success) return;
  349. }
  350. TkPoolCore.Disabled(response.accountName, $"{response.rawContent}");
  351. }); break;
  352. }
  353. }
  354. }
  355. catch (Exception ex)
  356. {
  357. _ = new LoggerLibrary("unionCoupon", "database_error")
  358. .Info(response.rawContent)
  359. .Info(response.Convert2Json())
  360. .Info(ex.Message, ex.StackTrace)
  361. .SaveAsync();
  362. }
  363. }
  364. public static async Task ParseLogAsync(JdDataDTO response)
  365. {
  366. try
  367. {
  368. var ts = DateTime.Now - response.create_time;
  369. response.elapsedTime = (int)ts.TotalMilliseconds;
  370. RedisHelper.RPush(queue_parse_jd_key, response);
  371. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  372. }
  373. catch (Exception ex) { }
  374. }
  375. public static async Task ParseLogAsync(DyDataDTO response)
  376. {
  377. try
  378. {
  379. var ts = DateTime.Now - response.create_time;
  380. response.elapsedTime = (int)ts.TotalMilliseconds;
  381. RedisHelper.RPush(queue_parse_dy_key, response);
  382. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  383. }
  384. catch (Exception ex) { }
  385. }
  386. public static async Task ParseLogAsync(ToolParseDataDTO response)
  387. {
  388. try
  389. {
  390. var ts = DateTime.Now - response.create_time;
  391. response.elapsedTime = (int)ts.TotalMilliseconds;
  392. RedisHelper.RPush(queue_parse_tool_key, response);
  393. saveParseCache(response.channel.ToString(), 0, "tool", response.success, response.message, response.reason);
  394. }
  395. catch (Exception ex) { }
  396. }
  397. private static void saveCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  398. {
  399. saveAccountCache("all", success, message, reason);
  400. saveAccountCache($"{channel}", success, message, reason);
  401. saveAccountCache($"{accountName}", success, message, reason);
  402. if (accountId != 0)
  403. {
  404. //todo 放着跑两天,要将读取的地方改成读取accountid
  405. saveAccountCache($"{channel}_{accountId}", success, message, reason);
  406. }
  407. }
  408. private static void saveAccountCache(string accountName, bool success, string message, string reason)
  409. {
  410. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMM}");
  411. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMdd}");
  412. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  413. string result = success ? "success" : "fail";
  414. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  415. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  416. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  417. if (!string.IsNullOrEmpty(message))
  418. {
  419. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  420. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  421. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  422. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  423. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  424. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  425. }
  426. if (!string.IsNullOrEmpty(reason))
  427. {
  428. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  429. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  430. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  431. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  432. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  433. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  434. }
  435. }
  436. private static void saveParseCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  437. {
  438. saveParseAccountCache("all", success, message, reason);
  439. saveParseAccountCache($"{channel}", success, message, reason);
  440. saveParseAccountCache($"{accountName}", success, message, reason);
  441. if (accountId != 0)
  442. {
  443. //todo 放着跑两天,要将读取的地方改成读取accountid
  444. saveParseAccountCache($"{channel}_{accountId}", success, message, reason);
  445. }
  446. }
  447. private static void saveParseAccountCache(string accountName, bool success, string message, string reason)
  448. {
  449. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMM}");
  450. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  451. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  452. string result = success ? "success" : "fail";
  453. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  454. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  455. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  456. if (!string.IsNullOrEmpty(message))
  457. {
  458. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  459. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  460. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  461. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  462. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  463. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  464. }
  465. if (!string.IsNullOrEmpty(reason))
  466. {
  467. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  468. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  469. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  470. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  471. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  472. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  473. }
  474. }
  475. private static void saveCouponCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  476. {
  477. saveAccountCouponCache("all", success, message, reason);
  478. saveAccountCouponCache($"{channel}", success, message, reason);
  479. if (accountId != 0)
  480. {
  481. //todo 放着跑两天,要将读取的地方改成读取accountid
  482. saveAccountCouponCache($"{channel}_{accountId}", success, message, reason);
  483. }
  484. }
  485. private static void saveAccountCouponCache(string accountName, bool success, string message, string reason)
  486. {
  487. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMM}");
  488. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  489. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  490. string result = success ? "success" : "fail";
  491. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  492. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  493. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  494. if (!string.IsNullOrEmpty(message))
  495. {
  496. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  497. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  498. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  499. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  500. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  501. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  502. }
  503. if (!string.IsNullOrEmpty(reason))
  504. {
  505. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  506. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  507. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  508. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  509. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  510. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  511. }
  512. }
  513. public static int GetTotal(string keyname, bool all_node = true)
  514. {
  515. int result = RedisHelper.Get<int>(keyname);
  516. return result;
  517. }
  518. public static string[] GetTotalKeys(string keyname, bool all_node = true)
  519. {
  520. string[] message_keys = RedisHelper.SMembers(keyname);
  521. return message_keys;
  522. //string[] message_keys2 = RedisHelper.SMembers(keyname.Replace(":total:", ":parse_total:"));
  523. //message_keys = message_keys.Union(message_keys2).ToArray();
  524. //string[] message_keys3 = RedisHelper.SMembers(keyname.Replace(":total:", ":coupon_total:"));
  525. //message_keys = message_keys.Union(message_keys3).ToArray();
  526. }
  527. //if (item.total_count > 0) continue;
  528. //item.total_count = RedisHelper.Get<int>($":total:all:{item.report_date:yyyyMMdd}");
  529. //if (item.total_count == 0) continue;
  530. //item.success_count = RedisHelper.Get<int>($":total:all:success:{item.report_date:yyyyMMdd}");
  531. //item.abandon_count = RedisHelper.Get<int>($":total:all:放弃转链:{item.report_date:yyyyMMdd}");
  532. }
  533. }