| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using dodohold.core;
- using Dataoke;
- using Tea;
- using AlibabaCloud.SDK.BssOpenApi20171214.Models;
- using AlibabaCloud.SDK.Ecs20140526.Models;
- using AlibabaCloud.SDK.Vpc20160428.Models;
- using TencentCloud.Dbbrain.V20210527.Models;
- using Org.BouncyCastle.Bcpg.OpenPgp;
- using TencentCloud.Tke.V20180525.Models;
- using static molilian.core.TkPoolCore;
- using ZstdSharp.Unsafe;
- namespace molilian.core
- {
- public partial class AliyunPoolCore
- {
- private static readonly object _lockObj = new();
- private static IEnumerable<AliyunPoolDTO> _cached;
- public static AliyunPoolDTO? GetOne(int id)
- {
- var list = List();
- if (!list.Any()) return null;
- return list.Where(e => e.id == id).FirstOrDefault();
- }
- public static IEnumerable<AliyunPoolDTO> List(bool force = false)
- {
- if (!force && _cached != null) return _cached;
- string cache_key = $"cache:aliyun_pool";
- var list = RedisHelper.Get<IEnumerable<AliyunPoolDTO>>(cache_key);
- if (force || list == null)
- {
- lock (_lockObj)
- {
- list = new DBContext.Table("aliyun_pool")
- .Where("status=@status", new { status = 1 })
- .Select<AliyunPoolDTO>();
- list = new DBContext.Table("aliyun_pool")
- .Where("status=@status", new { status = 1 })
- .Select<AliyunPoolDTO>();
- if (list == null) return default;
- RedisHelper.Set(cache_key, list, 30 * 86400);
- }
- }
- _cached = list;
- return list;
- }
- public static void Refresh()
- {
- _ = List(true);
- }
- public static void UpdateDrawBalance(string name, decimal amout)
- {
- new DBContext.Table("aliyun_pool")
- .Add("balance", amout)
- .Add("last_time", DateTime.Now)
- .Where("name=@name", new { name })
- .Update();
- _ = List(true);
- }
- public void GetBlances()
- {
- var list = new DBContext.Table("aliyun_pool").Where(string.Empty, new { }).Select<AliyunPoolDTO>();
- foreach (var item in list)
- {
- if (string.IsNullOrEmpty(item.accessKeyId)) continue;
- decimal amout = 0;
- try
- {
- AliyunCore core = new AliyunCore(item.id);
- var response = core.QueryAccountBalance();
- var balance = response.Body.Data.AvailableAmount;
- if (decimal.TryParse(balance, out amout))
- {
- UpdateDrawBalance(item.name, amout);
- }
- }
- catch (Exception ex)
- {
- new LoggerLibrary("aliyun", "balance_error")
- .Info($"Account:{item.id}\tbalance:{amout}")
- .Info(ex.Message, ex.StackTrace)
- .SaveAsync();
- }
- }
- }
- }
- }
|