|
|
@@ -29,7 +29,10 @@ namespace molilian.core
|
|
|
var links = LinksList();
|
|
|
if (!links.Any()) return null;
|
|
|
|
|
|
- return links.Where(e => IsEligible(e, channel)).OrderByDescending(e => e.priority_weight).FirstOrDefault();
|
|
|
+ return links.Where(e => IsEligible(e, channel))
|
|
|
+ .OrderByDescending(e => e.priority_weight)
|
|
|
+ .ThenBy(l => Guid.NewGuid())
|
|
|
+ .FirstOrDefault();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -42,6 +45,18 @@ namespace molilian.core
|
|
|
|
|
|
var now = DateTime.Now;
|
|
|
if (item.start_time > now || now > item.end_time) return false;
|
|
|
+
|
|
|
+
|
|
|
+ if (item.daily_calls_limit > 0)
|
|
|
+ {
|
|
|
+ int daily_num = RiskControlCore.GetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMdd"));
|
|
|
+ if (daily_num >= item.daily_calls_limit) return false;
|
|
|
+ }
|
|
|
+ if (item.hourly_calls_limit > 0)
|
|
|
+ {
|
|
|
+ int hourly_num = RiskControlCore.GetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMddHH"));
|
|
|
+ if (hourly_num >= item.hourly_calls_limit) return false;
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -76,9 +91,16 @@ namespace molilian.core
|
|
|
public static IEnumerable<CpsLinksDTO> LinksList(bool force = false)
|
|
|
{
|
|
|
#if DEBUG
|
|
|
- return new DBContext.Table("cps_links")
|
|
|
+ var list = new DBContext.Table("cps_links")
|
|
|
.Where("status=@status", new { status = 1 })
|
|
|
.Select<CpsLinksDTO>();
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ RiskControlCore.SetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMddHH"), item.current_hourly_calls);
|
|
|
+ RiskControlCore.SetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMdd"), item.current_daily_calls);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+
|
|
|
#else
|
|
|
if (!force && _links_cached != null) return _links_cached;
|
|
|
|
|
|
@@ -92,6 +114,11 @@ namespace molilian.core
|
|
|
.Where("status=@status", new { status = 1 })
|
|
|
.Select<CpsLinksDTO>();
|
|
|
if (list == null) return default;
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ RiskControlCore.SetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMddHH"), item.current_hourly_calls);
|
|
|
+ RiskControlCore.SetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMdd"), item.current_daily_calls);
|
|
|
+ }
|
|
|
RedisHelper.Set(cache_key, list, 30 * 86400);
|
|
|
}
|
|
|
}
|
|
|
@@ -99,6 +126,14 @@ namespace molilian.core
|
|
|
return list;
|
|
|
#endif
|
|
|
}
|
|
|
+ public static int Update(CpsLinksDTO account)
|
|
|
+ {
|
|
|
+ return new DBContext.Table("cps_links")
|
|
|
+ .Add("current_hourly_calls", account.current_hourly_calls)
|
|
|
+ .Add("current_daily_calls", account.current_daily_calls)
|
|
|
+ .Where("id=@id", new { account.id })
|
|
|
+ .Update();
|
|
|
+ }
|
|
|
|
|
|
public static void Refresh()
|
|
|
{
|