ReportController.cs 4.5 KB

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