| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.AspNetCore.Mvc.Filters;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using dodohold.core;
- using static dodohold.core.ZTOExpress.CreateOrderArgs;
- using System.Net;
- using System.Security.Cryptography;
- using Spire.Pdf.Exporting.XPS.Schema;
- using System.Xml.Linq;
- using static QRCoder.PayloadGenerator;
- using TencentCloud.Ssl.V20191205.Models;
- using CSRedis;
- using System.Data;
- using TencentCloud.Omics.V20221128.Models;
- using TencentCloud.Csip.V20221121.Models;
- namespace molilian.core
- {
- public class TkLogCore
- {
- static string queue_tb_key = "queue:logs:tb";
- static string queue_jd_key = "queue:logs:jd";
- static string queue_parse_tb_key = "queue:parse_logs:tb";
- static string queue_parse_jd_key = "queue:parse_logs:jd";
- static string queue_parse_dy_key = "queue:parse_logs:dy";
- static string queue_parse_tool_key = "queue:parse_logs:tool";
- static string queue_coupon_key = "queue:coupon_logs";
- static string promotion_img_key = "queue:promotion:img";
- public static int BatchInsertLogDB(int limit)
- {
- var result = EndPointCore.ProcessEndPointNodes<int>(node =>
- {
- if (!node.is_public_api) return 0;
- var redis = RedisClientManager.GetRedisClient(node.redis_server);
- return BatchInsertLogDB(limit, redis);
- });
- return result.Sum();
- }
- private static int save_tk_log(TkDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
- {
- return new DBContext.Table(connection, tablename)
- .Add("end_point", data.end_point)
- .Add("channel", (int)data.channel)
- .Add("accountId", data.accountId)
- .Add("accountName", data.accountName)
- .Add("rawContent", data.rawContent)
- .Add("rawContent2", data.rawContent2)
- .Add("success", data.success)
- .Add("message", data.message)
- .Add("reason", data.reason)
- .Add("content", data.content)
- .Add("couponAmount", data.couponAmount)
- .Add("itemId", data.itemId)
- .Add("itemName", data.itemName)
- .Add("pic", data.pic)
- .Add("promotionPrice", data.promotionPrice)
- .Add("taoToken", data.taoToken)
- .Add("shortLinkurl", data.shortLinkurl)
- .Add("deeplink_url", data.deeplink_url)
- .Add("num_iid", data.num_iid)
- .Add("elapsedTime", data.elapsedTime)
- .Add("subCode", data.subCode)
- .Add("ip", data.ip)
- .Add("oaid", data.oaid)
- .Add("create_time", data.create_time)
- .Create(DBContext.InsertType.NORMAL, transaction);
- }
- private static int save_tk_parse_logs(TkDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
- {
- return new DBContext.Table(connection, tablename)
- .Add("end_point", data.end_point)
- .Add("channel", (int)data.channel)
- .Add("accountId", data.accountId)
- .Add("accountName", data.accountName)
- .Add("rawContent", data.rawContent)
- .Add("success", data.success)
- .Add("message", data.message)
- .Add("reason", data.reason)
- .Add("content", data.content)
- .Add("itemId", data.itemId)
- .Add("itemName", data.itemName)
- .Add("pic", data.pic)
- .Add("couponAmount", data.couponAmount)
- .Add("promotionPrice", data.promotionPrice)
- .Add("taoToken", data.taoToken)
- .Add("shortLinkurl", data.shortLinkurl)
- .Add("deeplink_url", data.deeplink_url)
- .Add("num_iid", data.num_iid)
- .Add("elapsedTime", data.elapsedTime)
- .Add("elapsedTime2", data.elapsedTime2)
- .Add("elapsedTime3", data.elapsedTime3)
- .Add("subCode", data.subCode)
- .Add("ip", data.ip)
- .Add("oaid", data.oaid)
- .Add("create_time", data.create_time)
- .Create(DBContext.InsertType.NORMAL, transaction);
- }
- public static int BatchInsertLogDB(int limit, CSRedisClient redis)
- {
- int total = 0;
- using var connection = DBContext.GetOpenConnection();
- connection.Open();
- using var transaction = connection.BeginTransaction();
- string cacheKey = ":lock_key:start_comparison_tk";
- bool start_comparison_tk = RedisHelper.Get<int>(cacheKey) > 0;
- try
- {
- for (int i = 0; i < limit; i++)
- {
- var data = redis.LPop<TkDataDTO>(queue_tb_key);
- if (data == null) break;
- if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
- "127.0.0.1".Equals(data.ip) || data.elapsedTime > 1000)
- {
- save_tk_log(data, "tk_logs_test", connection, transaction);
- }
- else
- {
- data.id = save_tk_log(data, "tk_logs", connection, transaction);
- if (data.success)
- {
- save_tk_log(data, "tk_success_logs", connection, transaction);
- }
- //if (data.success || data.message.Contains("该链接不支持转化,请更换链接尝试"))
- //{
- // if (start_comparison_tk)
- // {
- // save_tk_log(data, "comparison_tk_logs", connection, transaction);
- // }
- //}
- if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
- }
- total++;
- }
- for (int i = 0; i < limit; i++)
- {
- var data = redis.LPop<JdDataDTO>(queue_jd_key);
- if (data == null) break;
- new DBContext.Table(connection, "tk_logs")
- .Add("end_point", data.end_point)
- .Add("channel", (int)data.channel)
- .Add("accountId", data.accountId)
- .Add("accountName", data.accountName)
- .Add("rawContent", data.rawContent)
- .Add("rawContent2", data.rawContent2)
- .Add("success", data.success)
- .Add("message", data.message)
- .Add("reason", data.reason)
- .Add("shortLinkurl", data.shortLinkurl)
- .Add("deeplink_url", data.deeplink_url)
- .Add("elapsedTime", data.elapsedTime)
- .Add("ip", data.ip)
- .Add("oaid", data.oaid)
- .Add("create_time", data.create_time)
- .Create(DBContext.InsertType.NORMAL, transaction);
- total++;
- }
- for (int i = 0; i < limit; i++)
- {
- var data = redis.LPop<TkDataDTO>(queue_parse_tb_key);
- if (data == null) break;
- //switch (data.oaid)
- //{
- // case "test-comparison_tk_logs":
- // save_tk_parse_logs(data, "comparison_tk_parse_logs", connection, transaction);
- // break;
- // case "test-comparison_tk_logs_raw":
- // save_tk_parse_logs(data, "comparison_tk_parse_logs_raw", connection, transaction);
- // break;
- // default:
- // break;
- //}
- if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
- "127.0.0.1".Equals(data.ip) || data.elapsedTime > 1000)
- {
- save_tk_parse_logs(data, "tk_parse_logs_test", connection, transaction);
- }
- else
- {
- data.id = save_tk_parse_logs(data, "tk_parse_logs", connection, transaction);
- if (data.success)
- {
- save_tk_parse_logs(data, "tk_success_parse_logs", connection, transaction);
- }
- if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
- }
- if (data.reason.Contains("初步筛选2") && !data.rawContent.Contains("I:/kWqN5t623Hx"))
- {
- save_tk_parse_logs(data, "tk_parse_logs_test2", connection, transaction);
- }
- if (data.reason.Contains("初步筛选1.5"))
- {
- save_tk_parse_logs(data, "tk_parse_logs_multi_token", connection, transaction);
- }
- if (data.reason.Contains("霸下验证码"))
- {
- save_tk_parse_logs(data, "tk_parse_logs_captcha", connection, transaction);
- }
- total++;
- }
- for (int i = 0; i < limit; i++)
- {
- var data = redis.LPop<JdDataDTO>(queue_parse_jd_key);
- if (data == null) break;
- new DBContext.Table(connection, "jd_parse_logs")
- .Add("end_point", data.end_point)
- .Add("channel", (int)data.channel)
- .Add("accountId", data.accountId)
- .Add("accountName", data.accountName)
- .Add("rawContent", data.rawContent)
- .Add("success", data.success)
- .Add("message", data.message)
- .Add("reason", data.reason)
- .Add("content", data.content)
- .Add("itemId", data.itemId)
- .Add("itemName", data.itemName)
- .Add("pic", data.pic)
- .Add("couponAmount", data.couponAmount)
- .Add("promotionPrice", data.promotionPrice)
- .Add("taoToken", data.taoToken)
- .Add("shortLinkurl", data.shortLinkurl)
- .Add("deeplink_url", data.deeplink_url)
- .Add("elapsedTime", data.elapsedTime)
- .Add("subCode", data.subCode)
- .Add("ip", data.ip)
- .Add("oaid", data.oaid)
- .Add("create_time", data.create_time)
- .Create(DBContext.InsertType.NORMAL, transaction);
- total++;
- }
- for (int i = 0; i < limit; i++)
- {
- var data = redis.LPop<DyDataDTO>(queue_parse_dy_key);
- if (data == null) break;
- new DBContext.Table(connection, "tk_parse_logs")
- .Add("end_point", data.end_point)
- .Add("channel", (int)data.channel)
- .Add("accountId", data.accountId)
- .Add("accountName", data.accountName)
- .Add("rawContent", data.rawContent)
- .Add("success", data.success)
- .Add("message", data.message)
- .Add("reason", data.reason)
- .Add("content", data.content)
- .Add("itemId", data.itemId)
- .Add("itemName", data.itemName)
- .Add("pic", data.pic)
- .Add("couponAmount", data.couponAmount)
- .Add("promotionPrice", data.promotionPrice)
- .Add("taoToken", data.taoToken)
- .Add("shortLinkurl", data.shortLinkurl)
- .Add("deeplink_url", data.deeplink_url)
- .Add("elapsedTime", data.elapsedTime)
- .Add("subCode", data.subCode)
- .Add("ip", data.ip)
- .Add("oaid", data.oaid)
- .Add("create_time", data.create_time)
- .Create(DBContext.InsertType.NORMAL, transaction);
- total++;
- }
- for (int i = 0; i < limit; i++)
- {
- var data = redis.LPop<ToolParseDataDTO>(queue_parse_tool_key);
- if (data == null) break;
- new DBContext.Table(connection, "tool_parse_logs")
- .Add("end_point", data.end_point)
- .Add("channel", (int)data.channel)
- .Add("rawContent", data.rawContent)
- .Add("success", data.success)
- .Add("message", data.message)
- .Add("reason", data.reason)
- .Add("content", data.content)
- .Add("taoToken", data.taoToken)
- .Add("shortLinkurl", data.shortLinkurl)
- .Add("deeplink_url", data.deeplink_url)
- .Add("elapsedTime", data.elapsedTime)
- .Add("ip", data.ip)
- .Add("oaid", data.oaid)
- .Add("create_time", data.create_time)
- .Create(DBContext.InsertType.NORMAL, transaction);
- total++;
- }
- for (int i = 0; i < limit; i++)
- {
- var data = redis.LPop<UnionCouponDTO>(queue_coupon_key);
- if (data == null) break;
- connection.Insert(data);
- total++;
- }
- for (int i = 0; i < limit; i++)
- {
- var data = redis.LPop<PromotionQueryDTO>(promotion_img_key);
- if (data == null) break;
- connection.Insert(data);
- total++;
- }
- transaction.Commit();
- }
- catch (Exception ex)
- {
- transaction.Rollback();
- _ = new LoggerLibrary("database_error", "parse_log")
- .Info(ex.Message, ex.StackTrace)
- .SaveAsync();
- NotifyCore.Notify(new NifyMessage
- {
- message = $"【写入日志异常】\n{ex.Message}\n{ex.StackTrace}",
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- }
- finally
- {
- connection.Close();
- }
- return total;
- }
- public static async Task PromotionImgLogAsync(PromotionQueryDTO response)
- {
- try
- {
- var ts = DateTime.Now - response.create_time;
- response.elapsedTime = (int)ts.TotalMilliseconds;
- _ = RedisHelper.RPushAsync(promotion_img_key, response);
- //using var connection = DBContext.GetOpenConnection();
- //connection.Insert(response);
- savePromotionCache(response.accountId, response.accountName, response.success, response.message, response.reason);
- }
- catch (Exception ex) { }
- }
- public static async Task LogAsync(JdDataDTO response)
- {
- try
- {
- var ts = DateTime.Now - response.create_time;
- response.elapsedTime = (int)ts.TotalMilliseconds;
- _ = RedisHelper.RPushAsync(queue_jd_key, response);
- saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
- }
- catch (Exception ex) { }
- }
- public static async Task LogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
- {
- try
- {
- var ts = DateTime.Now - response.create_time;
- response.elapsedTime = (int)ts.TotalMilliseconds;
- _ = RedisHelper.RPushAsync(queue_tb_key, response);
- saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
- if (!response.success && "nologin".Equals(response.message))
- {
- switch (response.channel)
- {
- case TkChannelEnum.tb:
- await Task.Run(() =>
- {
- if (alimamaPlus != null)
- {
- (bool success, string message) = alimamaPlus.RenewCookie();
- if (success) return;
- }
- TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
- });
- break;
- }
- }
- if ("没有匹配账号".Equals(response.reason))
- {
- TkPoolCore.AccountExhausted();
- }
- }
- catch (Exception ex)
- {
- _ = new LoggerLibrary("unionParse", "database_error")
- .Info(response.rawContent, response.rawContent2)
- .Info(response.Convert2Json())
- .Info(ex.Message, ex.StackTrace)
- .SaveAsync();
- }
- }
- public static async Task ParseLogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
- {
- #if DEBUG
- //return;
- #endif
- try
- {
- var ts = DateTime.Now - response.create_time;
- response.elapsedTime = (int)ts.TotalMilliseconds;
- _ = RedisHelper.RPushAsync(queue_parse_tb_key, response);
- saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
- if (!string.IsNullOrEmpty(response.itemId)) TkOrderTrackingCore.SaveLinkSummary(response);
- if (!response.success && "nologin".Equals(response.message))
- {
- switch (response.channel)
- {
- case TkChannelEnum.tb:
- await Task.Run(() =>
- {
- if (alimamaPlus != null)
- {
- (bool success, string message) = alimamaPlus.RenewCookie();
- if (success) return;
- }
- TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}");
- }); break;
- }
- }
- }
- catch (Exception ex)
- {
- _ = new LoggerLibrary("unionParse", "database_error")
- .Info(response.rawContent)
- .Info(response.Convert2Json())
- .Info(ex.Message, ex.StackTrace)
- .SaveAsync();
- }
- }
- public static async Task CouponLogAsync(UnionCouponDTO response, AlimamaPlus? alimamaPlus = null)
- {
- try
- {
- var ts = DateTime.Now - response.create_time;
- response.elapsedTime = (int)ts.TotalMilliseconds;
- _ = RedisHelper.RPushAsync(queue_coupon_key, response);
- saveCouponCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
- if (!response.success && "nologin".Equals(response.message))
- {
- switch (response.channel)
- {
- case TkChannelEnum.tb:
- await Task.Run(() =>
- {
- if (alimamaPlus != null)
- {
- (bool success, string message) = alimamaPlus.RenewCookie();
- if (success) return;
- }
- TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}");
- }); break;
- }
- }
- }
- catch (Exception ex)
- {
- _ = new LoggerLibrary("unionCoupon", "database_error")
- .Info(response.rawContent)
- .Info(response.Convert2Json())
- .Info(ex.Message, ex.StackTrace)
- .SaveAsync();
- }
- }
- public static async Task ParseLogAsync(JdDataDTO response)
- {
- try
- {
- var ts = DateTime.Now - response.create_time;
- response.elapsedTime = (int)ts.TotalMilliseconds;
- _ = RedisHelper.RPushAsync(queue_parse_jd_key, response);
- saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
- }
- catch (Exception ex) { }
- }
- public static async Task ParseLogAsync(DyDataDTO response)
- {
- try
- {
- var ts = DateTime.Now - response.create_time;
- response.elapsedTime = (int)ts.TotalMilliseconds;
- _ = RedisHelper.RPushAsync(queue_parse_dy_key, response);
- saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
- }
- catch (Exception ex) { }
- }
- public static async Task ParseLogAsync(ToolParseDataDTO response)
- {
- try
- {
- var ts = DateTime.Now - response.create_time;
- response.elapsedTime = (int)ts.TotalMilliseconds;
- _ = RedisHelper.RPushAsync(queue_parse_tool_key, response);
- saveParseCache(response.channel.ToString(), 0, "tool", response.success, response.message, response.reason);
- }
- catch (Exception ex) { }
- }
- private static void saveCache(string channel, int accountId, string accountName, bool success, string message, string reason)
- {
- saveAccountCache("all", success, message, reason);
- saveAccountCache($"{channel}", success, message, reason);
- saveAccountCache($"{accountName}", success, message, reason);
- if (accountId != 0)
- {
- //todo 放着跑两天,要将读取的地方改成读取accountid
- saveAccountCache($"{channel}_{accountId}", success, message, reason);
- }
- }
- private static void saveAccountCache(string accountName, bool success, string message, string reason)
- {
- RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMddHH}");
- string result = success ? "success" : "fail";
- RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
- if (!string.IsNullOrEmpty(message))
- {
- RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
- RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
- RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
- RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
- }
- if (!string.IsNullOrEmpty(reason))
- {
- RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
- RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
- RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
- RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
- }
- }
- private static void saveParseCache(string channel, int accountId, string accountName, bool success, string message, string reason)
- {
- saveParseAccountCache("all", success, message, reason);
- saveParseAccountCache($"{channel}", success, message, reason);
- saveParseAccountCache($"{accountName}", success, message, reason);
- if (accountId != 0)
- {
- //todo 放着跑两天,要将读取的地方改成读取accountid
- saveParseAccountCache($"{channel}_{accountId}", success, message, reason);
- }
- }
- private static void saveParseAccountCache(string accountName, bool success, string message, string reason)
- {
- RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
- string result = success ? "success" : "fail";
- RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
- if (!string.IsNullOrEmpty(message))
- {
- RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
- RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
- RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
- RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
- }
- if (!string.IsNullOrEmpty(reason))
- {
- RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
- RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
- RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
- RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
- }
- }
- private static void savePromotionCache(int accountId, string accountName, bool success, string message, string reason)
- {
- savePromotionAccountCache("all", success, message, reason);
- savePromotionAccountCache($"{accountId}", success, message, reason);
- }
- private static void savePromotionAccountCache(string accountName, bool success, string message, string reason)
- {
- RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
- string result = success ? "success" : "fail";
- RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
- if (!string.IsNullOrEmpty(message))
- {
- RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
- RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
- RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
- RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
- }
- if (!string.IsNullOrEmpty(reason))
- {
- RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
- RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
- RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
- RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
- }
- }
- private static void saveCouponCache(string channel, int accountId, string accountName, bool success, string message, string reason)
- {
- saveAccountCouponCache("all", success, message, reason);
- saveAccountCouponCache($"{channel}", success, message, reason);
- if (accountId != 0)
- {
- saveAccountCouponCache($"{channel}_{accountId}", success, message, reason);
- }
- }
- private static void saveAccountCouponCache(string accountName, bool success, string message, string reason)
- {
- RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
- string result = success ? "success" : "fail";
- RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
- if (!string.IsNullOrEmpty(message))
- {
- RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
- RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
- RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
- RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
- }
- if (!string.IsNullOrEmpty(reason))
- {
- RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
- RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
- RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
- RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
- }
- }
- public static int GetTotal(string keyname, bool all_node = true)
- {
- var result = EndPointCore.ProcessEndPointNodes<int>(node =>
- {
- if (!node.is_public_api) return 0;
- #if DEBUG
- switch (node.name)
- {
- case "bj":
- node.redis_server = "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
- break;
- case "gz":
- node.redis_server = "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
- break;
- }
- #endif
- var redis = RedisClientManager.GetRedisClient(node.redis_server);
- return redis.Get<int>(keyname);
- });
- return result.Sum();
- }
- public static string[] GetTotalKeys(string keyname, bool all_node = true)
- {
- var result = EndPointCore.ProcessEndPointNodes<string[]>(node =>
- {
- if (!node.is_public_api) return [];
- var redis = RedisClientManager.GetRedisClient(node.redis_server);
- string[] message_keys = redis.SMembers(keyname);
- return message_keys;
- });
- string[] message_keys = [];
- foreach (var arr in result)
- {
- message_keys = message_keys.Union(arr).ToArray();
- }
- return message_keys;
- }
- //if (item.total_count > 0) continue;
- //item.total_count = RedisHelper.Get<int>($":total:all:{item.report_date:yyyyMMdd}");
- //if (item.total_count == 0) continue;
- //item.success_count = RedisHelper.Get<int>($":total:all:success:{item.report_date:yyyyMMdd}");
- //item.abandon_count = RedisHelper.Get<int>($":total:all:放弃转链:{item.report_date:yyyyMMdd}");
- }
- }
|