疯狂的狮子li
2021-05-14 6067cb17977c0a90099f5ae3dad403a9a1f16dd6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package com.ruoyi.common.core.page;
 
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import lombok.Data;
import lombok.experimental.Accessors;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
 
@Data
@Accessors(chain = true)
public class PagePlus<T,K> implements IPage<T> {
 
    protected List<T> records;
    protected List<K> recordsVo;
    protected long total;
    protected long size;
    protected long current;
    protected List<OrderItem> orders;
    protected boolean optimizeCountSql;
    protected boolean isSearchCount;
    protected boolean hitCount;
    protected String countId;
    protected Long maxLimit;
 
    public PagePlus() {
        this.records = Collections.emptyList();
        this.recordsVo = Collections.emptyList();
        this.total = 0L;
        this.size = 10L;
        this.current = 1L;
        this.orders = new ArrayList();
        this.optimizeCountSql = true;
        this.isSearchCount = true;
        this.hitCount = false;
    }
 
    public PagePlus(long current, long size) {
        this(current, size, 0L);
    }
 
    public PagePlus(long current, long size, long total) {
        this(current, size, total, true);
    }
 
    public PagePlus(long current, long size, boolean isSearchCount) {
        this(current, size, 0L, isSearchCount);
    }
 
    public PagePlus(long current, long size, long total, boolean isSearchCount) {
        this.records = Collections.emptyList();
        this.total = 0L;
        this.size = 10L;
        this.current = 1L;
        this.orders = new ArrayList();
        this.optimizeCountSql = true;
        this.isSearchCount = true;
        this.hitCount = false;
        if (current > 1L) {
            this.current = current;
        }
 
        this.size = size;
        this.total = total;
        this.isSearchCount = isSearchCount;
    }
 
    public boolean hasPrevious() {
        return this.current > 1L;
    }
 
    public boolean hasNext() {
        return this.current < this.getPages();
    }
 
    public void recordsToVo(Class<K> kClass) {
        this.recordsVo = this.records.stream()
                .map(any -> BeanUtil.toBean(any, kClass))
                .collect(Collectors.toList());
    }
 
    @Override
    public String countId() {
        return this.getCountId();
    }
 
    @Override
    public Long maxLimit() {
        return this.getMaxLimit();
    }
 
    public PagePlus<T, K> addOrder(OrderItem... items) {
        this.orders.addAll(Arrays.asList(items));
        return this;
    }
 
    public PagePlus<T, K> addOrder(List<OrderItem> items) {
        this.orders.addAll(items);
        return this;
    }
 
    @Override
    public List<OrderItem> orders() {
        return this.getOrders();
    }
 
    @Override
    public boolean optimizeCountSql() {
        return this.optimizeCountSql;
    }
 
    @Override
    public boolean isSearchCount() {
        return this.total < 0L ? false : this.isSearchCount;
    }
 
    public PagePlus<T, K> setSearchCount(boolean isSearchCount) {
        this.isSearchCount = isSearchCount;
        return this;
    }
 
}