ReportController.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Org.BouncyCastle.Ocsp;
  5. using System.Text.Json;
  6. using System.Runtime.InteropServices;
  7. using TencentCloud.Scf.V20180416.Models;
  8. using Quartz.Impl.AdoJobStore.Common;
  9. using TencentCloud.Gaap.V20180529.Models;
  10. using System.Net;
  11. using TencentCloud.Ie.V20200304.Models;
  12. using TencentCloud.Soe.V20180724.Models;
  13. namespace molilian.api.Controllers
  14. {
  15. [ApiController]
  16. [MyAuthorize("admin")]
  17. [Route("api/[controller]/[action]")]
  18. public class ReportController : ControllerBase
  19. {
  20. readonly IAuthorizationProvider provider = new AdminProvider();
  21. protected IHttpContextAccessor _accessor;
  22. public ReportController(IHttpContextAccessor accessor)
  23. {
  24. _accessor = accessor;
  25. }
  26. [HttpPost]
  27. public ActionResult daily_list([FromBody] JsonElement form)
  28. {
  29. var token = provider.Get(_accessor.HttpContext);
  30. int page = form.Read("current", 1);
  31. int size = form.Read("pageSize", 10);
  32. bool getTotal = form.Read("getTotal", true);
  33. string sort = form.Read<string>("sort");
  34. string order = form.Read<string>("order");
  35. string filter = string.Empty;
  36. var log_date = form.PathReadArray<string>("query_date[]");
  37. var accountName = form.Read("accountName", string.Empty);
  38. int channel = form.Read("channel", -1);
  39. if (!string.IsNullOrEmpty(accountName))
  40. {
  41. filter += $" AND accountName=@accountName";
  42. }
  43. else
  44. {
  45. filter += $" AND accountName!='all'";
  46. }
  47. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  48. if (log_date.Count == 2)
  49. {
  50. if (DateTime.TryParse(log_date[0], out stime) && DateTime.TryParse(log_date[1], out etime))
  51. {
  52. etime = etime.AddDays(1).AddSeconds(-1);
  53. if (etime > DateTime.Now) etime = DateTime.Now;
  54. filter += $" AND log_date BETWEEN @stime AND @etime";
  55. }
  56. }
  57. if (channel != -1)
  58. {
  59. filter += $" AND channel=@channel";
  60. }
  61. filter = filter.StringTrimStart(" AND ");
  62. //排序
  63. string orderBy = "id DESC";
  64. if (!string.IsNullOrEmpty(order))
  65. {
  66. order = "descending".Equals(order) ? "DESC" : "ASC";
  67. orderBy = sort switch
  68. {
  69. _ => $"{sort} {order}",
  70. };
  71. }
  72. using var conn = DBContext.GetOpenConnection();
  73. var result = new DBContext.Table(conn, "daily_logs")
  74. .Where(filter, new { channel, accountName, stime, etime })
  75. .Page(size, page)
  76. .Order(orderBy)
  77. .PageList<DailyLogsDTO>(getTotal);
  78. return new APIResult(new { data = result });
  79. }
  80. }
  81. }