content: package com.alibaba.cola.dto;
  
  /**
   * Page Query Param
   *
   * @author jacky
   */
  public abstract class PageQuery extends Query {
      private static final long serialVersionUID = 1L;
  
      public static final String ASC = "ASC";
  
      public static final String DESC = "DESC";
  
      private static final int DEFAULT_PAGE_SIZE = 10;
  
      private int pageSize = DEFAULT_PAGE_SIZE;
  
      private int pageIndex = 1;
  
      private String orderBy;
  
      private String orderDirection = DESC;
  
      private String groupBy;
  
      private boolean needTotalCount = true;
  
      public int getPageIndex() {
          if (pageIndex < 1) {
              return 1;
          }
          return pageIndex;
      }
  
      public PageQuery setPageIndex(int pageIndex) {
          this.pageIndex = pageIndex;
          return this;
      }
  
      public int getPageSize() {
          if (pageSize < 1) {
              pageSize = DEFAULT_PAGE_SIZE;
          }
          return pageSize;
      }
  
      public PageQuery setPageSize(int pageSize) {
          if (pageSize < 1) {
              pageSize = DEFAULT_PAGE_SIZE;
          }
          this.pageSize = pageSize;
          return this;
      }
  
      public int getOffset() {
          return (getPageIndex() - 1) * getPageSize();
      }
  
      public String getOrderBy() {
          return orderBy;
      }
  
      public PageQuery setOrderBy(String orderBy) {
          this.orderBy = orderBy;
          return this;
      }
  
      public String getOrderDirection() {
          return orderDirection;
      }
  
      public PageQuery setOrderDirection(String orderDirection) {
          if (ASC.equalsIgnoreCase(orderDirection) || DESC.equalsIgnoreCase(orderDirection)) {
              this.orderDirection = orderDirection;
          }
          return this;
      }
  
      public String getGroupBy() {
          return groupBy;
      }
  
      public void setGroupBy(String groupBy) {
          this.groupBy = groupBy;
      }
  
      public boolean isNeedTotalCount() {
          return needTotalCount;
      }
  
      public void setNeedTotalCount(boolean needTotalCount) {
          this.needTotalCount = needTotalCount;
      }
  
  }
  