|
|
@@ -34,7 +34,14 @@ namespace molilian.core
|
|
|
static string queue_coupon_key = "queue:coupon_logs";
|
|
|
static string promotion_img_key = "queue:promotion:img";
|
|
|
|
|
|
+ static string queue_cps_key = "queue:cps_logs";
|
|
|
+ public static bool save_dailys_log = false;
|
|
|
|
|
|
+ static TkLogCore()
|
|
|
+ {
|
|
|
+ int flag = RedisHelper.Get<int>("turn:save_dailys_log");
|
|
|
+ if (flag == 1) save_dailys_log = true;
|
|
|
+ }
|
|
|
public static int BatchInsertLogDB(int limit)
|
|
|
{
|
|
|
var result = EndPointCore.ProcessEndPointNodes<int>(node =>
|
|
|
@@ -223,6 +230,14 @@ namespace molilian.core
|
|
|
else
|
|
|
{
|
|
|
data.id = save_tk_parse_logs(data, "tk_parse_logs", connection, transaction);
|
|
|
+
|
|
|
+ //每日分表
|
|
|
+ if (save_dailys_log)
|
|
|
+ {
|
|
|
+ string daily_table = $"tk_parse_logs_{DateTime.Now:yyyyMMdd}";
|
|
|
+ save_tk_parse_logs(data, daily_table, connection, transaction);
|
|
|
+ }
|
|
|
+
|
|
|
if (data.elapsedTime > 1000)
|
|
|
{
|
|
|
save_tk_parse_logs(data, "tk_parse_logs_test", connection, transaction);
|
|
|
@@ -265,6 +280,13 @@ namespace molilian.core
|
|
|
else
|
|
|
{
|
|
|
save_jd_parse_logs(data, "jd_parse_logs", connection, transaction);
|
|
|
+
|
|
|
+ if (save_dailys_log)
|
|
|
+ {
|
|
|
+ string daily_table = $"jd_parse_logs_{DateTime.Now:yyyyMMdd}";
|
|
|
+ save_jd_parse_logs(data, daily_table, connection, transaction);
|
|
|
+ }
|
|
|
+
|
|
|
if (data.elapsedTime > 1000)
|
|
|
{
|
|
|
save_jd_parse_logs(data, "jd_parse_logs_test", connection, transaction);
|
|
|
@@ -353,6 +375,29 @@ namespace molilian.core
|
|
|
total++;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ for (int i = 0; i < limit; i++)
|
|
|
+ {
|
|
|
+ var data = redis.LPop<UnionCpsDTO>(queue_cps_key);
|
|
|
+ if (data == null) break;
|
|
|
+
|
|
|
+ if (data.ip.Contains("127.0.0"))
|
|
|
+ {
|
|
|
+ var test_data = data.Convert2Json().Convert2Object<TestUnionCpsDTO>();
|
|
|
+ connection.Insert(test_data);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ connection.Insert(data);
|
|
|
+ if (data.success)
|
|
|
+ {
|
|
|
+ var success_data = data.Convert2Json().Convert2Object<SuccessUnionCpsDTO>();
|
|
|
+ connection.Insert(success_data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ total++;
|
|
|
+ }
|
|
|
+
|
|
|
for (int i = 0; i < limit; i++)
|
|
|
{
|
|
|
var data = redis.LPop<PromotionQueryDTO>(promotion_img_key);
|
|
|
@@ -548,6 +593,30 @@ namespace molilian.core
|
|
|
.SaveAsync();
|
|
|
}
|
|
|
}
|
|
|
+ public static async Task CpsLogAsync(UnionCpsDTO response, AlimamaPlus? alimamaPlus = null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var ts = DateTime.Now - response.create_time;
|
|
|
+ response.elapsedTime = (int)ts.TotalMilliseconds;
|
|
|
+ _ = RedisHelper.RPushAsync(queue_cps_key, response);
|
|
|
+
|
|
|
+ if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
|
|
|
+
|
|
|
+ if (!response.ip.Contains("127.0.0"))
|
|
|
+ {
|
|
|
+ saveCpsCache(response.channel.ToString(), response.accountId, response.success, response.message, response.reason);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _ = new LoggerLibrary("unionCps", "database_error")
|
|
|
+ .Info(response.rawContent)
|
|
|
+ .Info(response.Convert2Json())
|
|
|
+ .Info(ex.Message, ex.StackTrace)
|
|
|
+ .SaveAsync();
|
|
|
+ }
|
|
|
+ }
|
|
|
public static async Task ParseLogAsync(JdDataDTO response)
|
|
|
{
|
|
|
try
|
|
|
@@ -729,6 +798,37 @@ namespace molilian.core
|
|
|
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)
|
|
|
{
|
|
|
saveParseAccountCache("all", success, message, reason);
|
|
|
@@ -886,6 +986,61 @@ namespace molilian.core
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ private static void saveCpsCache(string channel, int accountId, bool success, string message, string reason)
|
|
|
+ {
|
|
|
+ saveAccountCpsCache("all", success, message, reason);
|
|
|
+ saveAccountCpsCache($"{channel}", success, message, reason);
|
|
|
+ if (accountId != 0)
|
|
|
+ {
|
|
|
+ saveAccountCpsCache($"{channel}_{accountId}", success, message, reason);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void saveAccountCpsCache(string flagName, bool success, string message, string reason)
|
|
|
+ {
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMM}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMMdd}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMMddHH}");
|
|
|
+
|
|
|
+
|
|
|
+ string result = success ? "success" : "fail";
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMM}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMMdd}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMMddHH}");
|
|
|
+
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(message))
|
|
|
+ {
|
|
|
+ RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMM}", message);
|
|
|
+ RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMMdd}", message);
|
|
|
+ RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMMddHH}", message);
|
|
|
+
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMM}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMMdd}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMMddHH}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMM}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMMdd}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(reason))
|
|
|
+ {
|
|
|
+ RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMM}", reason);
|
|
|
+ RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMMdd}", reason);
|
|
|
+ RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
|
|
|
+
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMM}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMMdd}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMMddHH}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMM}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
|
|
|
+ RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public static int GetTotal(string keyname, bool all_node = true)
|
|
|
{
|
|
|
//:coupon_total:tb:20240706
|