| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using molilian.core;
- using dodohold.core;
- using Microsoft.AspNetCore.Mvc;
- using System.Text.Json;
- using static molilian.core.ChartDataCore;
- using Org.BouncyCastle.Asn1;
- namespace molilian.api.Controllers
- {
- [ApiController]
- [MyAuthorize("admin")]
- [Route("api/[controller]/[action]")]
- public class MessageController : ControllerBase
- {
- readonly IAuthorizationProvider provider = new AdminProvider();
- protected IHttpContextAccessor _accessor;
- public MessageController(IHttpContextAccessor accessor)
- {
- _accessor = accessor;
- }
- [HttpGet]
- public async Task<ActionResult> AccountWarning()
- {
- IEnumerable<TkPoolDTO> tb_list = await TkPoolCore.AllListAsync();
- List<string> typeKeys = new List<string>();
- List<string> riskStrategyKeys = new List<string>();
- Dictionary<string, List<int>> total = new();
- foreach (TkPoolDTO tb in tb_list)
- {
- if (!string.IsNullOrEmpty(tb.parse_type) && !typeKeys.Contains(tb.parse_type)) typeKeys.Add(tb.parse_type);
- if (!string.IsNullOrEmpty(tb.riskStrategy))
- {
- string key = $"{tb.riskStrategy}-{tb.launchScene}";
- if (!riskStrategyKeys.Contains(key)) riskStrategyKeys.Add(key);
- }
- }
- // 统计 typeKeys 的在线/离线状态
- foreach (string typeKey in typeKeys)
- {
- var typeAccounts = tb_list.Where(tb => tb.parse_type == typeKey);
- int totalCount = typeAccounts.Count();
- int onlineCount = typeAccounts.Count(tb => tb.status);
- total[typeKey] = new List<int> { totalCount, onlineCount };
- }
- // 统计 riskStrategyKeys 的在线/离线状态
- foreach (string riskStrategyKey in riskStrategyKeys)
- {
- // riskStrategyKey 格式为 "riskStrategy-launchScene"
- string[] parts = riskStrategyKey.Split('-');
- if (parts.Length >= 2)
- {
- string riskStrategy = parts[0];
- if (int.TryParse(parts[^1], out int launchScene))
- {
- var riskAccounts = tb_list.Where(tb =>
- tb.riskStrategy == riskStrategy &&
- tb.launchScene == launchScene);
- int totalCount = riskAccounts.Count();
- int onlineCount = riskAccounts.Count(tb => tb.status);
- total[riskStrategyKey] = [totalCount, onlineCount];
- }
- }
- }
- IEnumerable<JdPoolDTO> jd_list = await JdPoolCore.AllListAsync();
- List<string> jdTypeKeys = new List<string>();
- List<string> jdRiskStrategyKeys = new List<string>();
- Dictionary<string, List<int>> jdTotal = new();
- // 收集京东的 typeKeys 和 riskStrategyKeys
- foreach (JdPoolDTO jd in jd_list)
- {
- if (jd.id < 38) continue;
- if (!string.IsNullOrEmpty(jd.parse_type) && !jdTypeKeys.Contains(jd.parse_type)) jdTypeKeys.Add(jd.parse_type);
- if (!string.IsNullOrEmpty(jd.riskStrategy))
- {
- string key = $"{jd.riskStrategy}-{jd.launchScene}";
- if (!jdRiskStrategyKeys.Contains(key)) jdRiskStrategyKeys.Add(key);
- }
- }
- // 统计京东 typeKeys 的在线/离线状态
- foreach (string typeKey in jdTypeKeys)
- {
- var typeAccounts = jd_list.Where(jd => jd.parse_type == typeKey);
- int totalCount = typeAccounts.Count();
- int onlineCount = typeAccounts.Count(jd => jd.status);
- jdTotal[typeKey] = new List<int> { totalCount, onlineCount };
- }
- // 统计京东 riskStrategyKeys 的在线/离线状态
- foreach (string riskStrategyKey in jdRiskStrategyKeys)
- {
- // riskStrategyKey 格式为 "riskStrategy-launchScene"
- string[] parts = riskStrategyKey.Split('-');
- if (parts.Length >= 2)
- {
- string riskStrategy = parts[0];
- if (int.TryParse(parts[^1], out int launchScene))
- {
- var riskAccounts = jd_list.Where(jd =>
- jd.riskStrategy == riskStrategy &&
- jd.launchScene == launchScene);
- int totalCount = riskAccounts.Count();
- int onlineCount = riskAccounts.Count(jd => jd.status);
- jdTotal[riskStrategyKey] = [totalCount, onlineCount];
- }
- }
- }
- return new APIResult(new
- {
- data = new
- {
- tb = total,
- jd = jdTotal
- }
- });
- }
- [HttpPost]
- public async Task<ActionResult> list([FromBody] JsonElement form)
- {
- return new APIResult(new { data = string.Empty });
- }
- }
- }
|