CustomReportController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. using TencentCloud.Mrs.V20200910.Models;
  8. using System.Xml.Linq;
  9. using System.Security.Cryptography;
  10. using TencentCloud.Bi.V20220105.Models;
  11. using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
  12. using molilian.core.PushDataReport;
  13. using System.Threading;
  14. using OfficeOpenXml.DataValidation.Exceptions;
  15. using System.Text.RegularExpressions;
  16. namespace molilian.api.Controllers
  17. {
  18. [ApiController]
  19. [MyAuthorize("admin")]
  20. [Route("api/[controller]/[action]")]
  21. public class CustomReportController : ControllerBase
  22. {
  23. readonly IAuthorizationProvider provider = new AdminProvider();
  24. protected IHttpContextAccessor _accessor;
  25. public CustomReportController(IHttpContextAccessor accessor)
  26. {
  27. _accessor = accessor;
  28. }
  29. [HttpPost]
  30. public ActionResult list([FromBody] JsonElement form)
  31. {
  32. var token = provider.Get(_accessor.HttpContext);
  33. int page = form.Read("current", 1);
  34. int size = form.Read("pageSize", 10);
  35. bool getTotal = form.Read("getTotal", true);
  36. string sort = form.Read<string>("sort");
  37. string order = form.Read<string>("order");
  38. string filter = string.Empty;
  39. // 临时锁定所有口令推送数据
  40. //string filter = "type<>1";
  41. int type = form.Read("type", 0);
  42. if (type > 0) filter += $" AND type = @type";
  43. int status = form.Read("status", -1);
  44. if (status != -1) filter += $" AND status = @status";
  45. int is_settlement = form.Read("is_settlement", -1);
  46. if (is_settlement != -1) filter += $" AND is_settlement = @is_settlement";
  47. int platform = form.Read("platform", 0);
  48. if (platform > 0) filter += $" AND platform = @platform";
  49. var report_date = form.Read<DateTime>("report_date", DateTime.MinValue);
  50. if (report_date != DateTime.MinValue) filter += $" AND report_date = @report_date";
  51. filter = filter.StringTrimStart(" AND ");
  52. string orderBy = "id DESC";
  53. if (!string.IsNullOrEmpty(order))
  54. {
  55. order = "descending".Equals(order) ? "DESC" : "ASC";
  56. orderBy = sort switch
  57. {
  58. _ => $"{sort} {order}",
  59. };
  60. }
  61. var result = new DBContext.Table("push_data_report")
  62. .Where(filter, new { type, report_date, is_settlement, status, platform })
  63. .Page(size, page)
  64. .Order(orderBy)
  65. .PageList<dynamic>(getTotal);
  66. return new APIResult(new { data = result });
  67. }
  68. [HttpPost]
  69. public ActionResult GetSqlTemplates([FromBody] JsonElement form)
  70. {
  71. var token = provider.Get(_accessor.HttpContext);
  72. int page = form.Read("current", 1);
  73. int size = form.Read("pageSize", 10);
  74. bool getTotal = form.Read("getTotal", true);
  75. string sort = form.Read<string>("sort");
  76. string order = form.Read<string>("order");
  77. string category = form.Read<string>("category");
  78. string keyword = form.Read<string>("keyword");
  79. string filter = "is_active = 1";
  80. if (!string.IsNullOrEmpty(category))
  81. filter += " AND category = @category";
  82. if (!string.IsNullOrEmpty(keyword))
  83. filter += " AND (name LIKE @keyword OR description LIKE @keyword)";
  84. string orderBy = "id DESC";
  85. if (!string.IsNullOrEmpty(order))
  86. {
  87. order = "descending".Equals(order) ? "DESC" : "ASC";
  88. orderBy = sort switch
  89. {
  90. _ => $"{sort} {order}",
  91. };
  92. }
  93. var keywordParam = !string.IsNullOrEmpty(keyword) ? $"%{keyword}%" : "";
  94. var result = new DBContext.Table("sql_templates")
  95. .Where(filter, new { category, keyword = keywordParam })
  96. .Page(size, page)
  97. .Order(orderBy)
  98. .PageList<dynamic>(getTotal);
  99. return new APIResult(new { data = result });
  100. }
  101. }
  102. }