MessageController.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System.Text.Json;
  5. using static molilian.core.ChartDataCore;
  6. using Org.BouncyCastle.Asn1;
  7. namespace molilian.api.Controllers
  8. {
  9. [ApiController]
  10. [MyAuthorize("admin")]
  11. [Route("api/[controller]/[action]")]
  12. public class MessageController : ControllerBase
  13. {
  14. readonly IAuthorizationProvider provider = new AdminProvider();
  15. protected IHttpContextAccessor _accessor;
  16. public MessageController(IHttpContextAccessor accessor)
  17. {
  18. _accessor = accessor;
  19. }
  20. [HttpGet]
  21. public async Task<ActionResult> AccountWarning()
  22. {
  23. var config = TkConfigCore.Get();
  24. IEnumerable<TkPoolDTO> tb_list = await TkPoolCore.AllListAsync();
  25. List<string> typeKeys = new List<string>();
  26. List<string> riskStrategyKeys = new List<string>();
  27. Dictionary<string, List<int>> total = new();
  28. foreach (TkPoolDTO tb in tb_list)
  29. {
  30. if (!string.IsNullOrEmpty(tb.parse_type) && !typeKeys.Contains(tb.parse_type)) typeKeys.Add(tb.parse_type);
  31. if (!string.IsNullOrEmpty(tb.riskStrategy))
  32. {
  33. string key = $"{tb.riskStrategy}-{tb.launchScene}";
  34. if (!riskStrategyKeys.Contains(key)) riskStrategyKeys.Add(key);
  35. }
  36. }
  37. // 统计 typeKeys 的在线/离线状态
  38. foreach (string typeKey in typeKeys)
  39. {
  40. var typeAccounts = tb_list.Where(tb => tb.parse_type == typeKey);
  41. int totalCount = typeAccounts.Count();
  42. int onlineCount = typeAccounts.Count(tb => tb.status);
  43. total[typeKey] = new List<int> { totalCount, onlineCount };
  44. }
  45. // 统计 riskStrategyKeys 的在线/离线状态
  46. foreach (string riskStrategyKey in riskStrategyKeys)
  47. {
  48. // riskStrategyKey 格式为 "riskStrategy-launchScene"
  49. string[] parts = riskStrategyKey.Split('-');
  50. if (parts.Length >= 2)
  51. {
  52. string riskStrategy = parts[0];
  53. if (int.TryParse(parts[^1], out int launchScene))
  54. {
  55. var riskAccounts = tb_list.Where(tb =>
  56. tb.riskStrategy == riskStrategy &&
  57. tb.launchScene == launchScene);
  58. int totalCount = riskAccounts.Count();
  59. int onlineCount = riskAccounts.Count(tb => tb.status);
  60. total[riskStrategyKey] = [totalCount, onlineCount];
  61. }
  62. }
  63. }
  64. total = AccountWarningConfigCore.FilterStats("tb", total, config?.account_warning_ignore_groups);
  65. IEnumerable<JdPoolDTO> jd_list = await JdPoolCore.AllListAsync();
  66. List<string> jdTypeKeys = new List<string>();
  67. List<string> jdRiskStrategyKeys = new List<string>();
  68. Dictionary<string, List<int>> jdTotal = new();
  69. // 收集京东的 typeKeys 和 riskStrategyKeys
  70. foreach (JdPoolDTO jd in jd_list)
  71. {
  72. if (jd.id < 38) continue;
  73. if (!string.IsNullOrEmpty(jd.parse_type) && !jdTypeKeys.Contains(jd.parse_type)) jdTypeKeys.Add(jd.parse_type);
  74. if (!string.IsNullOrEmpty(jd.riskStrategy))
  75. {
  76. string key = $"{jd.riskStrategy}-{jd.launchScene}";
  77. if (!jdRiskStrategyKeys.Contains(key)) jdRiskStrategyKeys.Add(key);
  78. }
  79. }
  80. // 统计京东 typeKeys 的在线/离线状态
  81. foreach (string typeKey in jdTypeKeys)
  82. {
  83. var typeAccounts = jd_list.Where(jd => jd.parse_type == typeKey);
  84. int totalCount = typeAccounts.Count();
  85. int onlineCount = typeAccounts.Count(jd => jd.status);
  86. jdTotal[typeKey] = new List<int> { totalCount, onlineCount };
  87. }
  88. // 统计京东 riskStrategyKeys 的在线/离线状态
  89. foreach (string riskStrategyKey in jdRiskStrategyKeys)
  90. {
  91. // riskStrategyKey 格式为 "riskStrategy-launchScene"
  92. string[] parts = riskStrategyKey.Split('-');
  93. if (parts.Length >= 2)
  94. {
  95. string riskStrategy = parts[0];
  96. if (int.TryParse(parts[^1], out int launchScene))
  97. {
  98. var riskAccounts = jd_list.Where(jd =>
  99. jd.riskStrategy == riskStrategy &&
  100. jd.launchScene == launchScene);
  101. int totalCount = riskAccounts.Count();
  102. int onlineCount = riskAccounts.Count(jd => jd.status);
  103. jdTotal[riskStrategyKey] = [totalCount, onlineCount];
  104. }
  105. }
  106. }
  107. jdTotal = AccountWarningConfigCore.FilterStats("jd", jdTotal, config?.account_warning_ignore_groups);
  108. return new APIResult(new
  109. {
  110. data = new
  111. {
  112. tb = total,
  113. jd = jdTotal
  114. }
  115. });
  116. }
  117. [HttpPost]
  118. public async Task<ActionResult> list([FromBody] JsonElement form)
  119. {
  120. return new APIResult(new { data = string.Empty });
  121. }
  122. }
  123. }