MessageController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. IEnumerable<TkPoolDTO> tb_list = await TkPoolCore.AllListAsync();
  24. List<string> typeKeys = new List<string>();
  25. List<string> riskStrategyKeys = new List<string>();
  26. Dictionary<string, List<int>> total = new();
  27. foreach (TkPoolDTO tb in tb_list)
  28. {
  29. if (!string.IsNullOrEmpty(tb.parse_type) && !typeKeys.Contains(tb.parse_type)) typeKeys.Add(tb.parse_type);
  30. if (!string.IsNullOrEmpty(tb.riskStrategy))
  31. {
  32. string key = $"{tb.riskStrategy}-{tb.launchScene}";
  33. if (!riskStrategyKeys.Contains(key)) riskStrategyKeys.Add(key);
  34. }
  35. }
  36. // 统计 typeKeys 的在线/离线状态
  37. foreach (string typeKey in typeKeys)
  38. {
  39. var typeAccounts = tb_list.Where(tb => tb.parse_type == typeKey);
  40. int totalCount = typeAccounts.Count();
  41. int onlineCount = typeAccounts.Count(tb => tb.status);
  42. total[typeKey] = new List<int> { totalCount, onlineCount };
  43. }
  44. // 统计 riskStrategyKeys 的在线/离线状态
  45. foreach (string riskStrategyKey in riskStrategyKeys)
  46. {
  47. // riskStrategyKey 格式为 "riskStrategy-launchScene"
  48. string[] parts = riskStrategyKey.Split('-');
  49. if (parts.Length >= 2)
  50. {
  51. string riskStrategy = parts[0];
  52. if (int.TryParse(parts[^1], out int launchScene))
  53. {
  54. var riskAccounts = tb_list.Where(tb =>
  55. tb.riskStrategy == riskStrategy &&
  56. tb.launchScene == launchScene);
  57. int totalCount = riskAccounts.Count();
  58. int onlineCount = riskAccounts.Count(tb => tb.status);
  59. total[riskStrategyKey] = [totalCount, onlineCount];
  60. }
  61. }
  62. }
  63. IEnumerable<JdPoolDTO> jd_list = await JdPoolCore.AllListAsync();
  64. List<string> jdTypeKeys = new List<string>();
  65. List<string> jdRiskStrategyKeys = new List<string>();
  66. Dictionary<string, List<int>> jdTotal = new();
  67. // 收集京东的 typeKeys 和 riskStrategyKeys
  68. foreach (JdPoolDTO jd in jd_list)
  69. {
  70. if (jd.id < 38) continue;
  71. if (!string.IsNullOrEmpty(jd.parse_type) && !jdTypeKeys.Contains(jd.parse_type)) jdTypeKeys.Add(jd.parse_type);
  72. if (!string.IsNullOrEmpty(jd.riskStrategy))
  73. {
  74. string key = $"{jd.riskStrategy}-{jd.launchScene}";
  75. if (!jdRiskStrategyKeys.Contains(key)) jdRiskStrategyKeys.Add(key);
  76. }
  77. }
  78. // 统计京东 typeKeys 的在线/离线状态
  79. foreach (string typeKey in jdTypeKeys)
  80. {
  81. var typeAccounts = jd_list.Where(jd => jd.parse_type == typeKey);
  82. int totalCount = typeAccounts.Count();
  83. int onlineCount = typeAccounts.Count(jd => jd.status);
  84. jdTotal[typeKey] = new List<int> { totalCount, onlineCount };
  85. }
  86. // 统计京东 riskStrategyKeys 的在线/离线状态
  87. foreach (string riskStrategyKey in jdRiskStrategyKeys)
  88. {
  89. // riskStrategyKey 格式为 "riskStrategy-launchScene"
  90. string[] parts = riskStrategyKey.Split('-');
  91. if (parts.Length >= 2)
  92. {
  93. string riskStrategy = parts[0];
  94. if (int.TryParse(parts[^1], out int launchScene))
  95. {
  96. var riskAccounts = jd_list.Where(jd =>
  97. jd.riskStrategy == riskStrategy &&
  98. jd.launchScene == launchScene);
  99. int totalCount = riskAccounts.Count();
  100. int onlineCount = riskAccounts.Count(jd => jd.status);
  101. jdTotal[riskStrategyKey] = [totalCount, onlineCount];
  102. }
  103. }
  104. }
  105. return new APIResult(new
  106. {
  107. data = new
  108. {
  109. tb = total,
  110. jd = jdTotal
  111. }
  112. });
  113. }
  114. [HttpPost]
  115. public async Task<ActionResult> list([FromBody] JsonElement form)
  116. {
  117. return new APIResult(new { data = string.Empty });
  118. }
  119. }
  120. }