| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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 Dataoke;
- namespace molilian.core
- {
- public partial class JdPoolCore
- {
- private static readonly object _lockObj = new();
- private static IEnumerable<JdPoolDTO> _cached;
- public static JdPoolDTO? GetOne()
- {
- var list = List();
- if (!list.Any()) return null;
- return list.OrderBy(l => Guid.NewGuid()).FirstOrDefault();
- }
- public static IEnumerable<JdPoolDTO> List(bool force = false)
- {
- if (!force && _cached != null) return _cached;
- string cache_key = $"cache:jd_pool";
- var list = RedisHelper.Get<IEnumerable<JdPoolDTO>>(cache_key);
- if (force || list == null)
- {
- lock (_lockObj)
- {
- list = new DBContext.Table("jd_pool")
- .Where("status=@status", new { status = 1 })
- .Select<JdPoolDTO>();
- 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 Disabled(string name)
- {
- string cache_key = $"cache:jd_pool:{name}:disabled";
- long count = RedisHelper.IncrBy(cache_key);
- RedisHelper.Expire(cache_key, 10);
- if (count > 1) return;
- new DBContext.Table("jd_pool")
- .Add("status", 0)
- .Where("name=@name", new { name })
- .Update();
- _ = List(true);
- NotifyCore.Notify(new NifyMessage
- {
- message = $"【京东账号:{name}】禁用",
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- }
- }
- }
|