BaseBody.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.zhiyun.common.model;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.zhiyun.common.utils.StringUtils;
  4. import com.zhiyun.common.utils.sql.SqlUtil;
  5. import lombok.Data;
  6. /**
  7. * 分页数据
  8. *
  9. * @author ruoyi
  10. */
  11. @Data
  12. public class BaseBody {
  13. /**
  14. * 登录用户ID
  15. */
  16. private Long userId;
  17. /**
  18. * 当前记录起始索引
  19. */
  20. private Integer pageNum = 1;
  21. /**
  22. * 每页显示记录数
  23. */
  24. private Integer pageSize = 10;
  25. /**
  26. * 排序列
  27. */
  28. private String orderByColumn;
  29. /**
  30. * 排序的方向desc或者asc
  31. */
  32. private String sort = "asc";
  33. public String getOrderBy() {
  34. if (StringUtils.isEmpty(orderByColumn)) return "";
  35. return SqlUtil.escapeOrderBySql(StringUtils.toUnderScoreCase(orderByColumn) + " " + sort);
  36. }
  37. public void setSort(String sort) {
  38. if (StringUtils.isNotEmpty(sort)) {
  39. // 兼容前端排序类型
  40. if ("ascending".equals(sort)) {
  41. sort = "asc";
  42. } else if ("descending".equals(sort)) {
  43. sort = "desc";
  44. }
  45. this.sort = sort;
  46. }
  47. }
  48. public <T> Page<T> getPage() {
  49. return new Page<>(pageNum, pageSize);
  50. }
  51. public <T> Page<T> getPageNoOptimize() {
  52. Page<T> result = new Page<T>(pageNum, pageSize);
  53. result.setOptimizeCountSql(false);
  54. return result;
  55. }
  56. public <T> Page<T> getNotPage() {
  57. return new Page<>(0, -1);
  58. }
  59. }