|
@@ -10,6 +10,8 @@ using Dataoke;
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
using System.Xml.Linq;
|
|
using System.Xml.Linq;
|
|
|
using Mysqlx.Crud;
|
|
using Mysqlx.Crud;
|
|
|
|
|
+using ZstdSharp.Unsafe;
|
|
|
|
|
+using YunhuiKit;
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace molilian.core
|
|
namespace molilian.core
|
|
@@ -35,35 +37,57 @@ namespace molilian.core
|
|
|
private static readonly object _lockObj = new();
|
|
private static readonly object _lockObj = new();
|
|
|
private static IEnumerable<JdPoolDTO> _cached;
|
|
private static IEnumerable<JdPoolDTO> _cached;
|
|
|
private static IEnumerable<JdPoolDTO> _all_cached;
|
|
private static IEnumerable<JdPoolDTO> _all_cached;
|
|
|
- public static JdPoolDTO? GetOne()
|
|
|
|
|
|
|
+ public static async Task<JdPoolDTO?> GetOneAsync()
|
|
|
{
|
|
{
|
|
|
- var list = List();
|
|
|
|
|
|
|
+ var list = await ListAsync();
|
|
|
if (!list.Any()) return null;
|
|
if (!list.Any()) return null;
|
|
|
return list.OrderBy(l => Guid.NewGuid()).FirstOrDefault();
|
|
return list.OrderBy(l => Guid.NewGuid()).FirstOrDefault();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static JdPoolDTO? GetSpecialOne(int accountid)
|
|
|
|
|
|
|
+ public static async Task<JdPoolDTO?> GetSpecialOneAsync(int accountid)
|
|
|
{
|
|
{
|
|
|
- var list = AllList();
|
|
|
|
|
|
|
+ var list = await AllListAsync();
|
|
|
if (!list.Any()) return null;
|
|
if (!list.Any()) return null;
|
|
|
return list.Where(e => e.id == accountid).OrderBy(l => Guid.NewGuid()).FirstOrDefault();
|
|
return list.Where(e => e.id == accountid).OrderBy(l => Guid.NewGuid()).FirstOrDefault();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public static JdPoolDTO? GetOne(int id, JdAction action)
|
|
|
|
|
|
|
+ public static async Task<JdPoolDTO?> GetOneAsync(int id, JdAction action)
|
|
|
{
|
|
{
|
|
|
- var list = List();
|
|
|
|
|
|
|
+ var list = await ListAsync();
|
|
|
if (!list.Any()) return null;
|
|
if (!list.Any()) return null;
|
|
|
- return list.Where(e => e.id == id && IsNotExceedDailyIncomeLimit(e, action)).OrderBy(l => Guid.NewGuid()).FirstOrDefault();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var eligibleItems = new List<JdPoolDTO>();
|
|
|
|
|
+ foreach (var item in list.Where(e => e.id == id))
|
|
|
|
|
+ {
|
|
|
|
|
+ if (await IsNotExceedDailyIncomeLimitAsync(item, action))
|
|
|
|
|
+ {
|
|
|
|
|
+ eligibleItems.Add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return eligibleItems.OrderBy(l => Guid.NewGuid()).FirstOrDefault();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static JdPoolDTO? GetOne(JdAction action)
|
|
|
|
|
|
|
+ public static async Task<JdPoolDTO?> GetOneAsync(JdAction action)
|
|
|
{
|
|
{
|
|
|
- var list = List();
|
|
|
|
|
|
|
+ var list = await ListAsync();
|
|
|
if (!list.Any()) return null;
|
|
if (!list.Any()) return null;
|
|
|
- return list.Where(e => IsNotExceedDailyIncomeLimit(e, action)).OrderBy(l => Guid.NewGuid()).FirstOrDefault();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var eligibleItems = new List<JdPoolDTO>();
|
|
|
|
|
+ foreach (var item in list)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (await IsNotExceedDailyIncomeLimitAsync(item, action))
|
|
|
|
|
+ {
|
|
|
|
|
+ eligibleItems.Add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return eligibleItems.OrderBy(l => Guid.NewGuid()).FirstOrDefault();
|
|
|
}
|
|
}
|
|
|
- private static bool IsNotExceedDailyIncomeLimit(JdPoolDTO item, JdAction action)
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private static async Task<bool> IsNotExceedDailyIncomeLimitAsync(JdPoolDTO item, JdAction action)
|
|
|
{
|
|
{
|
|
|
if (!string.IsNullOrEmpty(_end_point) && !string.IsNullOrEmpty(item.end_point))
|
|
if (!string.IsNullOrEmpty(_end_point) && !string.IsNullOrEmpty(item.end_point))
|
|
|
{
|
|
{
|
|
@@ -98,11 +122,11 @@ namespace molilian.core
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static IEnumerable<JdPoolDTO> AllList(bool force = false)
|
|
|
|
|
|
|
+ public static async Task<IEnumerable<JdPoolDTO>> AllListAsync(bool force = false)
|
|
|
{
|
|
{
|
|
|
if (!force && _all_cached != default) return _all_cached;
|
|
if (!force && _all_cached != default) return _all_cached;
|
|
|
string cache_key = $"cache:all_jd_pool";
|
|
string cache_key = $"cache:all_jd_pool";
|
|
|
- var list = RedisHelper.Get<IEnumerable<JdPoolDTO>>(cache_key);
|
|
|
|
|
|
|
+ var list = await RedisKit.GetAsync<IEnumerable<JdPoolDTO>>(cache_key);
|
|
|
if (force || list == default)
|
|
if (force || list == default)
|
|
|
{
|
|
{
|
|
|
lock (_lockObj)
|
|
lock (_lockObj)
|
|
@@ -110,18 +134,18 @@ namespace molilian.core
|
|
|
list = new DBContext.Table("jd_pool").Select<JdPoolDTO>();
|
|
list = new DBContext.Table("jd_pool").Select<JdPoolDTO>();
|
|
|
if (list == null) return default;
|
|
if (list == null) return default;
|
|
|
|
|
|
|
|
- RedisHelper.Set(cache_key, list, 30 * 86400);
|
|
|
|
|
|
|
+ _ = RedisKit.SetAsync(cache_key, list, 30 * 86400);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
_all_cached = list;
|
|
_all_cached = list;
|
|
|
return list;
|
|
return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static IEnumerable<JdPoolDTO> List(bool force = false)
|
|
|
|
|
|
|
+ public static async Task<IEnumerable<JdPoolDTO>> ListAsync(bool force = false)
|
|
|
{
|
|
{
|
|
|
if (!force && _cached != null) return _cached;
|
|
if (!force && _cached != null) return _cached;
|
|
|
string cache_key = $"cache:jd_pool";
|
|
string cache_key = $"cache:jd_pool";
|
|
|
- var list = RedisHelper.Get<IEnumerable<JdPoolDTO>>(cache_key);
|
|
|
|
|
|
|
+ var list = await RedisKit.GetAsync<IEnumerable<JdPoolDTO>>(cache_key);
|
|
|
if (force || list == null)
|
|
if (force || list == null)
|
|
|
{
|
|
{
|
|
|
lock (_lockObj)
|
|
lock (_lockObj)
|
|
@@ -133,10 +157,10 @@ namespace molilian.core
|
|
|
|
|
|
|
|
foreach (var item in list)
|
|
foreach (var item in list)
|
|
|
{
|
|
{
|
|
|
- RiskControlCore.SetCallsAsync(TkChannelEnum.jd, item.id, DateTime.Now.ToString("yyyyMMddHH"), item.current_hourly_calls);
|
|
|
|
|
- RiskControlCore.SetCallsAsync(TkChannelEnum.jd, item.id, DateTime.Now.ToString("yyyyMMdd"), item.current_daily_calls);
|
|
|
|
|
|
|
+ _ = RiskControlCore.SetCallsAsync(TkChannelEnum.jd, item.id, DateTime.Now.ToString("yyyyMMddHH"), item.current_hourly_calls);
|
|
|
|
|
+ _ = RiskControlCore.SetCallsAsync(TkChannelEnum.jd, item.id, DateTime.Now.ToString("yyyyMMdd"), item.current_daily_calls);
|
|
|
}
|
|
}
|
|
|
- RedisHelper.Set(cache_key, list, 30 * 86400);
|
|
|
|
|
|
|
+ _ = RedisKit.SetAsync(cache_key, list, 30 * 86400);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
_cached = list;
|
|
_cached = list;
|
|
@@ -147,8 +171,8 @@ namespace molilian.core
|
|
|
{
|
|
{
|
|
|
_all_cached = [];
|
|
_all_cached = [];
|
|
|
_cached = [];
|
|
_cached = [];
|
|
|
- _ = List(true);
|
|
|
|
|
- _ = AllList();
|
|
|
|
|
|
|
+ _ = ListAsync(true);
|
|
|
|
|
+ _ = AllListAsync();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static int Update(JdPoolDTO account)
|
|
public static int Update(JdPoolDTO account)
|
|
@@ -199,7 +223,7 @@ namespace molilian.core
|
|
|
if (!string.IsNullOrEmpty(h5st)) update.Add("h5st", h5st);
|
|
if (!string.IsNullOrEmpty(h5st)) update.Add("h5st", h5st);
|
|
|
|
|
|
|
|
update.Update();
|
|
update.Update();
|
|
|
- if (status) _ = List(true);
|
|
|
|
|
|
|
+ if (status) _ = ListAsync(true);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -223,17 +247,17 @@ namespace molilian.core
|
|
|
message = $"【京东{accountId}:{company}】cookie 上线",
|
|
message = $"【京东{accountId}:{company}】cookie 上线",
|
|
|
tags = ["green_circle"]
|
|
tags = ["green_circle"]
|
|
|
});
|
|
});
|
|
|
- EndPointCore.NotifyReload(true);
|
|
|
|
|
|
|
+ _ = EndPointCore.NotifyReload(true);
|
|
|
//NotifyCore.AnPushNotify("上线", $"【淘宝联盟:{dnk}】cookie 上报更新");
|
|
//NotifyCore.AnPushNotify("上线", $"【淘宝联盟:{dnk}】cookie 上报更新");
|
|
|
return accountId;
|
|
return accountId;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public static void Disabled(int accountId, string name, string content)
|
|
|
|
|
|
|
+ public static async Task DisabledAsync(int accountId, string name, string content)
|
|
|
{
|
|
{
|
|
|
string cache_key = $"cache:jd_pool:{name}:disabled";
|
|
string cache_key = $"cache:jd_pool:{name}:disabled";
|
|
|
- long count = RedisHelper.IncrBy(cache_key);
|
|
|
|
|
- RedisHelper.Expire(cache_key, 10);
|
|
|
|
|
|
|
+ long count = await RedisKit.IncrByAsync(cache_key);
|
|
|
|
|
+ _ = RedisKit.ExpireAsync(cache_key, 10);
|
|
|
if (count > 1) return;
|
|
if (count > 1) return;
|
|
|
|
|
|
|
|
var update = new DBContext.Table("jd_pool").Add("status", 0);
|
|
var update = new DBContext.Table("jd_pool").Add("status", 0);
|
|
@@ -245,9 +269,7 @@ namespace molilian.core
|
|
|
{
|
|
{
|
|
|
update.Where("name=@name", new { name }).Update();
|
|
update.Where("name=@name", new { name }).Update();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- _ = List(true);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ _ = ListAsync(true);
|
|
|
NotifyCore.Notify(new NifyMessage
|
|
NotifyCore.Notify(new NifyMessage
|
|
|
{
|
|
{
|
|
|
message = $"【京东联盟{accountId}:{name}】cookie 掉线\n\n{content}",
|
|
message = $"【京东联盟{accountId}:{name}】cookie 掉线\n\n{content}",
|
|
@@ -256,18 +278,18 @@ namespace molilian.core
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
//NotifyCore.AnPushNotify("掉线", $"【京东{accountId}:{name}】cookie 掉线");
|
|
//NotifyCore.AnPushNotify("掉线", $"【京东{accountId}:{name}】cookie 掉线");
|
|
|
- EndPointCore.NotifyReload(true);
|
|
|
|
|
|
|
+ _ = EndPointCore.NotifyReload(true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- internal static void AccountExhausted()
|
|
|
|
|
|
|
+ internal static async Task AccountExhaustedAsync()
|
|
|
{
|
|
{
|
|
|
string cache_key = $"cache:tk_pool:account:exhausted";
|
|
string cache_key = $"cache:tk_pool:account:exhausted";
|
|
|
- long count = RedisHelper.IncrBy(cache_key);
|
|
|
|
|
|
|
+ long count = await RedisKit.IncrByAsync(cache_key);
|
|
|
if (count > 1) return;
|
|
if (count > 1) return;
|
|
|
- RedisHelper.Expire(cache_key, 3600);
|
|
|
|
|
|
|
+ _ = RedisKit.ExpireAsync(cache_key, 3600);
|
|
|
NotifyCore.Notify(new NifyMessage
|
|
NotifyCore.Notify(new NifyMessage
|
|
|
{
|
|
{
|
|
|
message = $"【京东联盟】没有匹配账号",
|
|
message = $"【京东联盟】没有匹配账号",
|