ludc
2024-07-10 4d571ecaabae01dc825f01ce92ff4a5023f56fb0
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.vci.ubcs.starter.web.pagemodel;
 
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springblade.core.mp.support.Query;
 
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 因为当前框架使用的是query来做分页,
 * 所以我这边参照以前的BaseQueryObject来修改的
 * @author ludc
 * @date 2023/5/23 13:00
 */
public class BladeQueryObject implements Serializable {
 
    @JSONField(
        serialize = false,
        deserialize = false
    )
    private static final long serialVersionUID = 5608634730007623041L;
    @JSONField
    private Map<String, Object> conditionMap = new HashMap();
    @JSONField
    private Integer page = 1;
    @JSONField
    private String sort;
    @JSONField
    private String order;
    @JSONField
    private int limit = 25;
 
    public BladeQueryObject() {
    }
 
    public BladeQueryObject(Map<String, Object> conditionMap) {
        this.setConditionMap(conditionMap);
    }
 
    public BladeQueryObject(int limit) {
        this.setLimit(limit);
    }
 
    public BladeQueryObject(Map<String, Object> conditionMap, int limit) {
        this.setConditionMap(conditionMap);
        this.setLimit(limit);
    }
 
    public Map<String, Object> getConditionMap() {
        return this.conditionMap;
    }
 
    public Map<String, Object> getConditionMapByNick(String nick) {
        if (this.conditionMap != null) {
            Map<String, Object> conditionMapHasNick = new HashMap();
            this.conditionMap.forEach((k, v) -> {
                if (!k.contains(".")) {
                    conditionMapHasNick.put(nick + "." + k, v);
                } else {
                    conditionMapHasNick.put(k, v);
                }
 
            });
            return conditionMapHasNick;
        } else {
            return null;
        }
    }
 
    public void setConditionMap(Map<String, Object> conditionMap) {
        this.conditionMap = conditionMap;
    }
 
    public int getPage() {
        return this.page;
    }
 
    public void setPage(int page) {
        this.page = page;
    }
 
    public String getSort() {
        return this.sort;
    }
 
    public void setSort(String sort) {
        this.sort = sort;
    }
 
    public String getOrder() {
        return this.order;
    }
 
    public void setOrder(String order) {
        this.order = order;
    }
 
    public int getLimit() {
        return this.limit;
    }
 
    public void setLimit(int limit) {
        this.limit = limit;
    }
 
    @JSONField(
        serialize = false,
        deserialize = false
    )
    public Query getQuery() {
        Query query = new Query();
        query.setCurrent(this.getPage());
        query.setSize(this.getLimit());
        query.setAscs(this.getSort());
        //query.setOrder(this.getOrder());
        return query;
    }
 
    public BladeQueryObject addSort(String sort, String order) {
        this.setSort(StringUtils.isBlank(this.getSort()) ? sort : this.getSort() + "," + sort);
        this.setOrder(StringUtils.isBlank(this.getOrder()) ? order : this.getOrder() + "," + order);
        return this;
    }
 
    public BladeQueryObject addCondition(String key, String value) {
        if (this.getConditionMap() == null) {
            this.conditionMap = new HashMap();
        }
 
        this.conditionMap.put(key, value);
        return this;
    }
 
    public BladeQueryObject page(Query query) {
        this.setSort(query.getDescs());
        this.setSort(query.getAscs());
        //this.setOrder(query.getOrder());
        this.setPage(query.getCurrent());
        this.setLimit(query.getSize());
        return this;
    }
 
    @JSONField(
        serialize = false,
        deserialize = false
    )
    public Map<String, Object> getFeignRequestMap() {
        Map<String, Object> feignRequestMap = new HashMap();
        if (this.conditionMap != null) {
            this.getConditionMap().forEach((k, v) -> {
                feignRequestMap.put("conditionMap[\"" + k + "\"]", v);
            });
        }
 
        feignRequestMap.put("page", this.getPage() + "");
        feignRequestMap.put("limit", this.getLimit() + "");
        feignRequestMap.put("sort", this.getSort());
        feignRequestMap.put("order", this.getOrder());
        return feignRequestMap;
    }
 
    @Override
    public String toString() {
        return "BladeQueryObject{conditionMap=" + this.conditionMap + ", page=" + this.page + ", sort='" + this.sort + '\'' + ", order='" + this.order + '\'' + ", limit=" + this.limit + '}';
    }
 
}