| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630 |
- 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;
- using COSXML.Network;
- using System.Security.Policy;
- using System.Diagnostics;
- namespace molilian.core
- {
- public partial class TkLogCore
- {
- public static bool save_dailys_log = false;
- public static string _test_oaid = "3B191CFA4C6B48F9BA459E915B57743BEC7D424979CC9C51BCAD0C245B1C7BA2";
- static TkLogCore()
- {
- int flag = RedisHelper.Get<int>("turn:save_dailys_log");
- if (flag == 1) save_dailys_log = true;
- }
- private static readonly SemaphoreSlim semaphore = new SemaphoreSlim(10, 10);
- public static async Task<int> BatchInsertLogDBAsync(int limit)
- {
- await semaphore.WaitAsync(); // 等待获取锁
- try
- {
- var result = await Task.Run(() =>
- {
- return EndPointCore.ProcessEndPointNodes<int>(node =>
- {
- if (!node.is_public_api) return 0;
- if (CenterHub.IsCenter)
- {
- if (node.is_coupon_api) return 0;
- }
- else
- {
- if (!node.is_coupon_api) return 0;
- }
- if (string.IsNullOrEmpty(node.redis_server)) return 0;
- var redis = RedisClientManager.GetRedisClient(node.redis_server);
- return BatchInsertLogDB(limit, redis);
- });
- });
- return result.Sum();
- }
- finally
- {
- semaphore.Release(); // 释放锁,允许下一个任务执行
- }
- }
- public static int BatchInsertLogDB2(int limit, CSRedisClient redis)
- {
- int total = 0;
- using var connection = DBContext.GetOpenConnection();
- connection.Open();
- using var transaction = connection.BeginTransaction();
- try
- {
- Stopwatch stopwatch = new Stopwatch(); // 创建一个计时器
- LoggerLibrary log = new LoggerLibrary("debug", "BatchInsertLogDB"); // 创建日志对象
- //第三方接口写入日志
- stopwatch.Start();
- int taskTotal = task_insert_tk_logs(limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_tk_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_parse_tb_logs(connection, transaction, limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_parse_tb_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_parse_jd_logs(connection, transaction, limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_parse_jd_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_parse_pdd_logs(connection, transaction, limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_parse_pdd_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_parse_dy_logs(connection, transaction, limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_parse_dy_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_parse_tool_logs(connection, transaction, limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_parse_tool_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_parse_deeplink_logs(limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_parse_deeplink_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_parse_coupon_logs(connection, transaction, limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_parse_coupon_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_parse_cps_logs(connection, transaction, limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_parse_cps_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_promotion_img_logs(connection, transaction, limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_promotion_img_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- stopwatch.Start();
- taskTotal = task_insert_parse_ks_logs(connection, transaction, limit, redis);
- total += taskTotal;
- stopwatch.Stop();
- log.Info($"task_insert_parse_ks_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- stopwatch.Reset();
- 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 int BatchInsertLogDB(int limit, CSRedisClient redis)
- {
- int total = 0;
- //using var connection = DBContext.GetOpenConnection();
- //connection.Open();
- //using var transaction = connection.BeginTransaction();
- using IDbTransaction transaction = null;
- using IDbConnection connection = null;
- try
- {
- Stopwatch stopwatch = new Stopwatch(); // 创建一个计时器
- LoggerLibrary log = new LoggerLibrary("debug", "BatchInsertLogDB"); // 创建日志对象
- var tasks = new List<Task<int>>
- {
- Task.Run(() => RunTaskWithLogging(() => task_insert_tk_logs(limit, redis), "task_insert_tk_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_tb_logs(connection, transaction, limit, redis), "task_insert_parse_tb_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_jd_logs(connection, transaction, limit, redis), "task_insert_parse_jd_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_pdd_logs(connection, transaction, limit, redis), "task_insert_parse_pdd_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_dy_logs(connection, transaction, limit, redis), "task_insert_parse_dy_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_tool_logs(connection, transaction, limit, redis), "task_insert_parse_tool_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_deeplink_logs(limit, redis), "task_insert_parse_deeplink_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_coupon_logs(connection, transaction, limit, redis), "task_insert_parse_coupon_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_cps_logs(connection, transaction, limit, redis), "task_insert_parse_cps_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_promotion_img_logs(connection, transaction, limit, redis), "task_insert_promotion_img_logs", log)),
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_ks_logs(connection, transaction, limit, redis), "task_insert_parse_ks_logs", log))
- };
- // 等待所有任务完成
- Task.WhenAll(tasks).Wait();
- // 计算所有任务的结果总和
- total = tasks.Select(t => t.Result).Sum();
- //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;
- }
- // 新增一个辅助方法来处理日志记录和任务执行
- private static int RunTaskWithLogging(Func<int> taskFunc, string taskName, LoggerLibrary log)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- int taskTotal = taskFunc();
- stopwatch.Stop();
- log.Info($"{taskName} 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
- log.SaveAsync();
- return taskTotal;
- }
- public static int BatchInsertLogDB(int limit)
- {
- var result = EndPointCore.ProcessEndPointNodes<int>(node =>
- {
- if (!node.is_public_api) return 0;
- if (CenterHub.IsCenter)
- {
- if (node.is_coupon_api) return 0;
- }
- else
- {
- if (!node.is_coupon_api) return 0;
- }
- if (string.IsNullOrEmpty(node.redis_server)) return 0;
- var redis = RedisClientManager.GetRedisClient(node.redis_server);
- return BatchInsertLogDB(limit, redis);
- });
- return result.Sum();
- }
- 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}");
- RedisHelper.IncrBy($":total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":total:{accountName}:message:{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}");
- RedisHelper.IncrBy($":total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
- }
- }
- private static async Task saveUnionCouponParseCacheAsync(TkDataDTO data)
- {
- string cacheKey = $":cache:parse:{data.ip}_{data.oaid}_{data.itemId}";
- await EndPointCore.ProcessEndPointNodesAsync(node =>
- {
- if (!node.is_coupon_api) return Task.CompletedTask;
- if (string.IsNullOrEmpty(node.redis_server)) return Task.CompletedTask;
- var redis = RedisClientManager.GetRedisClient(node.redis_server);
- redis.Set(cacheKey, 1, 2 * 86400);
- return Task.CompletedTask;
- });
- }
- private static void saveClientRequestTotal(TkChannelEnum channel, string ip, string oaid)
- {
- string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
- RedisHelper.IncrBy(cacheKey);
- RedisHelper.Expire(cacheKey, 86400);
- if (!string.IsNullOrEmpty(oaid))
- {
- cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
- RedisHelper.IncrBy(cacheKey);
- RedisHelper.Expire(cacheKey, 86400);
- }
- }
- private static void saveClientRequestTotal(string channel, string ip, string oaid)
- {
- string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
- RedisHelper.IncrBy(cacheKey);
- RedisHelper.Expire(cacheKey, 86400);
- if (!string.IsNullOrEmpty(oaid))
- {
- cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
- RedisHelper.IncrBy(cacheKey);
- RedisHelper.Expire(cacheKey, 86400);
- }
- }
- public static int getClientRequestTotalByOAID(TkChannelEnum channel, string oaid)
- {
- if (string.IsNullOrEmpty(oaid)) return 0;
- string cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
- return RedisHelper.Get<int>(cacheKey);
- }
- public static int getClientRequestTotalByIp(TkChannelEnum channel, string ip)
- {
- if (string.IsNullOrEmpty(ip)) return 0;
- string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
- return RedisHelper.Get<int>(cacheKey);
- }
- public static int getClientRequestTotalByOAID(string channel, string oaid)
- {
- if (string.IsNullOrEmpty(oaid)) return 0;
- string cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
- return RedisHelper.Get<int>(cacheKey);
- }
- public static int getClientRequestTotalByIp(string channel, string ip)
- {
- if (string.IsNullOrEmpty(ip)) return 0;
- string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
- return RedisHelper.Get<int>(cacheKey);
- }
- private static void saveClientRequestTotal(CpsChannelEnum channel, string ip, string oaid)
- {
- string cacheKey = $":cache:cps_{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
- RedisHelper.IncrBy(cacheKey);
- RedisHelper.Expire(cacheKey, 86400);
- if (!string.IsNullOrEmpty(oaid))
- {
- cacheKey = $":cache:cps_{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
- RedisHelper.IncrBy(cacheKey);
- RedisHelper.Expire(cacheKey, 86400);
- }
- }
- public static int getClientRequestTotalByOAID(CpsChannelEnum channel, string oaid)
- {
- if (string.IsNullOrEmpty(oaid)) return 0;
- string cacheKey = $":cache:cps_{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
- return RedisHelper.Get<int>(cacheKey);
- }
- public static int getClientRequestTotalByIp(CpsChannelEnum channel, string ip)
- {
- if (string.IsNullOrEmpty(ip)) return 0;
- string cacheKey = $":cache:cps_{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
- return RedisHelper.Get<int>(cacheKey);
- }
- private static void saveParseCache(string channel, int accountId, string accountName,
- bool success, string message, string reason, string deeplink)
- {
- string dp_flag = deeplink switch
- {
- "" => "none",
- "tbopen://m.taobao.com/tbopen/index.html" or
- "pinduoduo://com.xunmeng.pinduoduo/" or
- "snssdk1128://feed?refer=web" or
- "bdnetdisk://n/action.EXTERNAL_ACTIVITY" or
- "openapp.jdmobile://virtual?params=" or "openapp.jdmobile://" => "home",
- _ => success ? "success" : "fail",
- };
- //关于dp的缓存
- saveParseAccountCache($"dp_{dp_flag}:all", success, message, reason);
- saveParseAccountCache($"dp_{dp_flag}:{channel}", success, message, reason);
- saveParseAccountCache($"dp_{dp_flag}:{accountName}", success, message, reason);
- if (accountId != 0)
- {
- saveParseAccountCache($"dp_{dp_flag}:{channel}_{accountId}", success, message, 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}");
- RedisHelper.IncrBy($":parse_total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":parse_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":parse_total:{accountName}:message:{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}");
- RedisHelper.IncrBy($":parse_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
- RedisHelper.IncrBy($":parse_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
- RedisHelper.IncrBy($":parse_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
- }
- }
- public static int GetTotal(string keyname, bool all_node = true)
- {
- //:coupon_total:tb:20240706
- //:coupon_total:tb:success:20240706
- //:coupon_total:tb:放弃转链:20240706
- var result = EndPointCore.ProcessEndPointNodes<int>(node =>
- {
- if (!node.is_public_api) return 0;
- if (string.IsNullOrEmpty(node.redis_server)) return 0;
- if (!all_node)
- {
- if (CenterHub.IsCenter)
- {
- if (node.is_coupon_api) { return 0; }
- }
- else
- {
- if (!node.is_coupon_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;
- case "coupon1":
- node.redis_server = "c1api.molilian.com:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=coupon";
- break;
- default: return 0;
- }
- #endif
- var redis = RedisClientManager.GetRedisClient(node.redis_server);
- int count = redis.Get<int>(keyname);
- return count;
- });
- 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 [];
- if (string.IsNullOrEmpty(node.redis_server)) return [];
- if (!all_node)
- {
- if (CenterHub.IsCenter)
- {
- if (node.is_coupon_api) { return []; }
- }
- else
- {
- if (!node.is_coupon_api) { return []; }
- }
- }
- #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;
- case "coupon1":
- node.redis_server = "c1api.molilian.com:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=coupon";
- break;
- default: return [];
- }
- #endif
- 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;
- }
- }
- }
|