AliyunController.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 TencentCloud.Soe.V20180724.Models;
  7. namespace molilian.api.Controllers
  8. {
  9. [ApiController]
  10. [MyAuthorize("admin")]
  11. [Route("api/[controller]/[action]")]
  12. public class AliyunController : ControllerBase
  13. {
  14. readonly IAuthorizationProvider provider = new AdminProvider();
  15. protected IHttpContextAccessor _accessor;
  16. public AliyunController(IHttpContextAccessor accessor)
  17. {
  18. _accessor = accessor;
  19. }
  20. [HttpPost]
  21. public ActionResult account_list([FromBody] JsonElement form)
  22. {
  23. var token = provider.Get(_accessor.HttpContext);
  24. int page = form.Read("current", 1);
  25. int size = form.Read("pageSize", 10);
  26. bool getTotal = form.Read("getTotal", true);
  27. string sort = form.Read<string>("sort");
  28. string order = form.Read<string>("order");
  29. string filter = string.Empty;
  30. var keyword = form.Read("keyword", string.Empty);
  31. if (!string.IsNullOrEmpty(keyword))
  32. {
  33. filter += $" AND (name like @keyword OR username like @keyword OR company like @keyword OR mobile like @keyword)";
  34. keyword = $"%{keyword}%";
  35. }
  36. filter = filter.StringTrimStart(" AND ");
  37. //排序
  38. string orderBy = "id DESC";
  39. if (!string.IsNullOrEmpty(order))
  40. {
  41. order = "descending".Equals(order) ? "DESC" : "ASC";
  42. orderBy = sort switch
  43. {
  44. _ => $"{sort} {order}",
  45. };
  46. }
  47. var result = new DBContext.Table("aliyun_pool")
  48. .Where(filter, new { keyword })
  49. .Page(size, page)
  50. .Order(orderBy)
  51. .PageList<dynamic>(getTotal);
  52. return new APIResult(new { data = result });
  53. }
  54. [HttpPost]
  55. public ActionResult ecs_list([FromBody] JsonElement form)
  56. {
  57. var token = provider.Get(_accessor.HttpContext);
  58. int page = form.Read("current", 1);
  59. int size = form.Read("pageSize", 10);
  60. bool getTotal = form.Read("getTotal", true);
  61. string sort = form.Read<string>("sort");
  62. string order = form.Read<string>("order");
  63. string filter = string.Empty;
  64. var log_date = form.PathReadArray<string>("query_date[]");
  65. var accountName = form.Read("accountName", string.Empty);
  66. int channel = form.Read("channel", -1);
  67. if (!string.IsNullOrEmpty(accountName))
  68. {
  69. filter += $" AND accountName=@accountName";
  70. }
  71. else
  72. {
  73. filter += $" AND accountName!='all'";
  74. }
  75. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  76. if (log_date.Count == 2)
  77. {
  78. if (DateTime.TryParse(log_date[0], out stime) && DateTime.TryParse(log_date[1], out etime))
  79. {
  80. etime = etime.AddDays(1).AddSeconds(-1);
  81. if (etime > DateTime.Now) etime = DateTime.Now;
  82. filter += $" AND log_date BETWEEN @stime AND @etime";
  83. }
  84. }
  85. if (channel != -1)
  86. {
  87. filter += $" AND channel=@channel";
  88. }
  89. filter = filter.StringTrimStart(" AND ");
  90. //排序
  91. string orderBy = "id DESC";
  92. if (!string.IsNullOrEmpty(order))
  93. {
  94. order = "descending".Equals(order) ? "DESC" : "ASC";
  95. orderBy = sort switch
  96. {
  97. _ => $"{sort} {order}",
  98. };
  99. }
  100. using var conn = CenterHub.GetOpenConnection();
  101. var result = new DBContext.Table(conn, "center_daily_logs")
  102. .Where(filter, new { channel, accountName, stime, etime })
  103. .Page(size, page)
  104. .Order(orderBy)
  105. .PageList<DailyLogsDTO>(getTotal);
  106. var accounts = JdPoolCore.List();
  107. var hide_ids = accounts.Where(e => e.is_hide).Select(e => e.id).ToList();
  108. result.List = result.List.Where(e => e.channel != 1 || !hide_ids.Contains(e.accountId));
  109. return new APIResult(new { data = result });
  110. }
  111. }
  112. }