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 + '}';
|
}
|
|
}
|