MessageController.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.ListAsync();
  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.ListAsync();
  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 (!string.IsNullOrEmpty(jd.parse_type) && !jdTypeKeys.Contains(jd.parse_type)) jdTypeKeys.Add(jd.parse_type);
  71. if (!string.IsNullOrEmpty(jd.riskStrategy))
  72. {
  73. string key = $"{jd.riskStrategy}-{jd.launchScene}";
  74. if (!jdRiskStrategyKeys.Contains(key)) jdRiskStrategyKeys.Add(key);
  75. }
  76. }
  77. // 统计京东 typeKeys 的在线/离线状态
  78. foreach (string typeKey in jdTypeKeys)
  79. {
  80. var typeAccounts = jd_list.Where(jd => jd.parse_type == typeKey);
  81. int totalCount = typeAccounts.Count();
  82. int onlineCount = typeAccounts.Count(jd => jd.status);
  83. jdTotal[typeKey] = new List<int> { totalCount, onlineCount };
  84. }
  85. // 统计京东 riskStrategyKeys 的在线/离线状态
  86. foreach (string riskStrategyKey in jdRiskStrategyKeys)
  87. {
  88. // riskStrategyKey 格式为 "riskStrategy-launchScene"
  89. string[] parts = riskStrategyKey.Split('-');
  90. if (parts.Length == 2)
  91. {
  92. string riskStrategy = parts[0];
  93. if (int.TryParse(parts[1], out int launchScene))
  94. {
  95. var riskAccounts = jd_list.Where(jd =>
  96. jd.riskStrategy == riskStrategy &&
  97. jd.launchScene == launchScene);
  98. int totalCount = riskAccounts.Count();
  99. int onlineCount = riskAccounts.Count(jd => jd.status);
  100. jdTotal[riskStrategyKey] = [totalCount, onlineCount];
  101. }
  102. }
  103. }
  104. return new APIResult(new
  105. {
  106. data = new
  107. {
  108. tb = total,
  109. jd = jdTotal
  110. }
  111. });
  112. }
  113. [HttpPost]
  114. public async Task<ActionResult> list([FromBody] JsonElement form)
  115. {
  116. return new APIResult(new { data = string.Empty });
  117. }
  118. }
  119. }