com.base4j.mvc.base.param.Group Maven / Gradle / Ivy
The newest version!
package com.base4j.mvc.base.param;
import com.base4j.mybatis.base.QueryParams;
import com.base4j.mybatis.tool.NullUtil;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
public class Group implements Serializable {
private static final long serialVersionUID = 1853557890332197293L;
public void appendParamGroup(QueryParams queryParams) {
QueryParams.Criteria criteria = queryParams.or();
if (this.getLike() != null) {
for (Map.Entry like : this.getLike().entrySet()) {
String value = like.getValue().toString();
if (NullUtil.isNotEmpty(value)) {
criteria.andLike(like.getKey(), "%" + value + "%");
}
}
}
if (this.getNotLike() != null) {
for (Map.Entry notLike : this.getNotLike().entrySet()) {
String value = notLike.getValue().toString();
if (NullUtil.isNotEmpty(value)) {
criteria.andNotLike(notLike.getKey(), "%" + value + "%");
}
}
}
if (this.getIn() != null) {
for (Map.Entry> in : this.getIn().entrySet()) {
List value = in.getValue();
if (value != null && value.size() > 0) {
criteria.andIn(in.getKey(), value);
}
}
}
if (this.getNotIn() != null) {
for (Map.Entry> notIn : this.getNotIn().entrySet()) {
List value = notIn.getValue();
if (value != null && value.size() > 0) {
criteria.andNotIn(notIn.getKey(), value);
}
}
}
if (this.getBetween() != null) {
for (Map.Entry between : this.getBetween().entrySet()) {
Between value = between.getValue();
if (value != null && NullUtil.isNotEmpty(value.getBegin()) && NullUtil.isNotEmpty(value.getEnd())){
criteria.andBetween(between.getKey(), value.getBegin(), value.getEnd());
}
}
}
if (this.getNotBetween() != null) {
for (Map.Entry notBetween : this.getNotBetween().entrySet()) {
Between value = notBetween.getValue();
if (value != null && NullUtil.isNotEmpty(value.getBegin()) && NullUtil.isNotEmpty(value.getEnd())) {
criteria.andNotBetween(notBetween.getKey(), value.getBegin(), value.getEnd());
}
}
}
if (this.getEqualTo() != null) {
for (Map.Entry equalTo : this.getEqualTo().entrySet()) {
Object value = equalTo.getValue();
if (NullUtil.isNotEmpty(value)) {
criteria.andEqualTo(equalTo.getKey(), value);
}
}
}
if (this.getNotEqualTo() != null) {
for (Map.Entry notEqualTo : this.getNotEqualTo().entrySet()) {
Object value = notEqualTo.getValue();
if (NullUtil.isNotEmpty(value)) {
criteria.andNotEqualTo(notEqualTo.getKey(), value);
}
}
}
if (this.getCondition() != null) {
criteria.andCondition(this.getCondition());
}
if (this.getGreatThan() != null) {
for (Map.Entry greatThan : this.getGreatThan().entrySet()) {
Object value = greatThan.getValue();
if (NullUtil.isNotEmpty(value)) {
criteria.andGreaterThan(greatThan.getKey(), value);
}
}
}
if (this.getGreatThanOrEqualTo() != null) {
for (Map.Entry greatThanOrEqualTo : this.getGreatThanOrEqualTo().entrySet()) {
Object value = greatThanOrEqualTo.getValue();
if (NullUtil.isNotEmpty(value)) {
criteria.andNotEqualTo(greatThanOrEqualTo.getKey(), value);
}
}
}
if (this.getLessThan() != null) {
for (Map.Entry lessThan : this.getLessThan().entrySet()) {
Object value = lessThan.getValue();
if (NullUtil.isNotEmpty(value)) {
criteria.andNotEqualTo(lessThan.getKey(), value);
}
}
}
if (this.getLessThanOrEqualTo() != null) {
for (Map.Entry lessThanOrEqualTo : this.getLessThanOrEqualTo().entrySet()) {
Object value = lessThanOrEqualTo.getValue();
if (NullUtil.isNotEmpty(value)) {
criteria.andNotEqualTo(lessThanOrEqualTo.getKey(), value);
}
}
}
if (this.getSelect() != null && this.getSelect().split(",").length > 0) {
queryParams.selectProperties(this.getSelect().split(","));
}
if (this.getOrderBy() != null) {
for (Map.Entry orderBy : this.getOrderBy().entrySet()) {
QueryParams.OrderBy orderByOpe = queryParams.orderBy(orderBy.getKey());
String orderByValue = orderBy.getValue();
if (orderByValue != null && orderByValue.length() > 0) {
if ("desc".equals(orderByValue)) {
orderByOpe.desc();
} else {
orderByOpe.asc();
}
} else {
orderByOpe.asc();
}
}
}
}
private Map like;
private Map notLike;
private Map between;
private Map notBetween;
private Map> in;
private Map> notIn;
private Map equalTo;
private Map notEqualTo;
private Map greatThan;
private Map greatThanOrEqualTo;
private Map lessThan;
private Map lessThanOrEqualTo;
private String condition;
private String select;
private Map orderBy;
public Map getLike() {
return like;
}
public void setLike(Map like) {
this.like = like;
}
public Map getNotLike() {
return notLike;
}
public void setNotLike(Map notLike) {
this.notLike = notLike;
}
public Map getBetween() {
return between;
}
public void setBetween(Map between) {
this.between = between;
}
public Map getNotBetween() {
return notBetween;
}
public void setNotBetween(Map notBetween) {
this.notBetween = notBetween;
}
public Map> getIn() {
return in;
}
public void setIn(Map> in) {
this.in = in;
}
public Map> getNotIn() {
return notIn;
}
public void setNotIn(Map> notIn) {
this.notIn = notIn;
}
public Map getEqualTo() {
return equalTo;
}
public void setEqualTo(Map equalTo) {
this.equalTo = equalTo;
}
public Map getNotEqualTo() {
return notEqualTo;
}
public void setNotEqualTo(Map notEqualTo) {
this.notEqualTo = notEqualTo;
}
public Map getGreatThan() {
return greatThan;
}
public void setGreatThan(Map greatThan) {
this.greatThan = greatThan;
}
public Map getGreatThanOrEqualTo() {
return greatThanOrEqualTo;
}
public void setGreatThanOrEqualTo(Map greatThanOrEqualTo) {
this.greatThanOrEqualTo = greatThanOrEqualTo;
}
public Map getLessThan() {
return lessThan;
}
public void setLessThan(Map lessThan) {
this.lessThan = lessThan;
}
public Map getLessThanOrEqualTo() {
return lessThanOrEqualTo;
}
public void setLessThanOrEqualTo(Map lessThanOrEqualTo) {
this.lessThanOrEqualTo = lessThanOrEqualTo;
}
public String getCondition() {
return condition;
}
public void setCondition(String condition) {
this.condition = condition;
}
public String getSelect() {
return select;
}
public void setSelect(String select) {
this.select = select;
}
public Map getOrderBy() {
return orderBy;
}
public void setOrderBy(Map orderBy) {
this.orderBy = orderBy;
}
static class Between {
private Object begin;
private Object end;
public Object getBegin() {
return begin;
}
public void setBegin(Object begin) {
this.begin = begin;
}
public Object getEnd() {
return end;
}
public void setEnd(Object end) {
this.end = end;
}
}
}