package org.hsweb.web.bean.common;

import java.io.Serializable;

/**
 * Created by 浩 on 2016-01-16 0016.
 */
public class QueryParam extends SqlParam<QueryParam> implements Serializable {
    private static final long serialVersionUID = 7941767360194797891L;

    /**
     * 是否进行分页，默认为true
     */
    private boolean paging = true;

    /**
     * 第几页 从0开始
     */
    private int pageIndex = 0;

    /**
     * 每页显示记录条数
     */
    private int pageSize = 25;

    /**
     * 排序字段
     */
    private String sortField;

    /**
     * 排序方式 DESC 反序 ASC 正序
     */
    private String sortOrder;


    public QueryParam orderBy(String sortField) {
        orderBy(sortField, true);
        return this;
    }

    public QueryParam orderBy(String sortField, boolean asc) {
        setSortField(sortField);
        setSortOrder(asc ? "asc" : "desc");
        return this;
    }

    public QueryParam doPaging(int pageIndex) {
        this.pageIndex = pageIndex;
        this.paging = true;
        return this;
    }

    public QueryParam doPaging(int pageIndex, int pageSize) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.paging = true;
        return this;
    }

    public QueryParam rePaging(int total) {
        paging = true;
        // 当前页没有数据后跳转到最后一页
        if (this.getPageIndex() != 0 && (pageIndex * pageSize) >= total) {
            int tmp = total / this.getPageSize();
            pageIndex = total % this.getPageSize() == 0 ? tmp - 1 : tmp;
        }
        return this;
    }

    public boolean isPaging() {
        return paging;
    }

    public void setPaging(boolean paging) {
        this.paging = paging;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getSortField() {
        return sortField;
    }

    public void setSortField(String sortField) {
        this.sortField = sortField;
    }

    public String getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(String sortOrder) {
        if (!sortOrder.equalsIgnoreCase("asc"))
            sortOrder = "desc";
        this.sortOrder = sortOrder;
    }

}

@@ -57,16 +57,102 @@
 lizable;
+%0Aimport java.util.LinkedHashSet;%0Aimport java.util.Set;%0Aimport java.util.regex.Pattern;
 %0A%0A/**%0A *
@@ -578,30 +578,35 @@
     private 
+Set%3C
 String
+%3E
  sortField;%0A
@@ -603,16 +603,40 @@
 ortField
+ = new LinkedHashSet%3C%3E()
 ;%0A%0A    /
@@ -701,16 +701,24 @@
 ortOrder
+ = %22asc%22
 ;%0A%0A%0A    
@@ -896,28 +896,30 @@
         
-setS
+this.s
 ortField
 (sortFie
@@ -910,16 +910,20 @@
 ortField
+.add
 (sortFie
@@ -2102,37 +2102,329 @@
 %0A    %7D%0A%0A    
-public 
+static String reg = %22(?:')%7C(?:--)%7C(/%5C%5C*(?:.%7C%5B%5C%5Cn%5C%5Cr%5D)*?%5C%5C*/)%7C%22%0A            + %22(%5C%5Cb(select%7Cupdate%7Cand%7Cor%7Cdelete%7Cinsert%7Ctrancate%7Cchar%7Cinto%7Csubstr%7Cascii%7Cdeclare%7Cexec%7Ccount%7Cmaster%7Cinto%7Cdrop%7Cexecute)%5C%5Cb)%22;%0A%0A    static Pattern sqlPattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE);%0A%0A    public Set%3C
 String
+%3E
  getSortFiel
@@ -2491,22 +2491,27 @@
 rtField(
+Set%3C
 String
+%3E
  sortFie
@@ -2688,17 +2688,16 @@
     if (
-!
 sortOrde
@@ -2702,29 +2702,52 @@
 der.
-equalsIgnoreCase(%22asc
+contains(%22desc%22) %7C%7C sortOrder.contains(%22DESC
 %22))%0A

修改排序字段为set类型。