Feat:添加默认的查询实体

This commit is contained in:
wangyu 2020-11-09 23:03:14 +08:00
parent f0e45972d6
commit c3338024f1
2 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package com.flyfish.framework.enums;
/**
* 带有名称字段的枚举
*
* @author wangyu
*/
public interface NamedEnum {
String getName();
}

View File

@ -0,0 +1,74 @@
package com.flyfish.framework.domain.base;
import com.flyfish.framework.builder.CriteriaBuilder;
import com.flyfish.framework.domain.base.BaseQo;
import com.flyfish.framework.domain.base.Domain;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.util.StringUtils;
import java.util.Collection;
/**
* 基于名字模糊匹配的查询实体
*/
@Getter
@Setter
public abstract class NameLikeQo<T extends Domain> extends BaseQo<T> {
protected String name;
protected String code;
protected String createTimeStart;
protected String createTimeEnd;
protected String modifyTimeStart;
protected String modifyTimeEnd;
protected String creatorId;
protected String modifierId;
protected Boolean enable;
protected Collection<String> ids;
protected String excludeId;
/**
* 排序参数
*/
private String sort;
/**
* 去重字段
*/
private String distinct;
@Override
public CriteriaBuilder<T> criteriaBuilder() {
return CriteriaBuilder.accept(this)
.with("name", CriteriaBuilder.Builders.LIKE)
.with("enable", "code", "creatorId", "modifierId")
.with("ids", "id", CriteriaBuilder.Builders.IN)
.with("excludeId", "id", Criteria::ne)
.with("createTimeStart", "createTime", CriteriaBuilder.Builders.DATE_GTE)
.with("createTimeEnd", "createTime", CriteriaBuilder.Builders.DATE_LTE)
.with("modifyTimeStart", "modifyTime", CriteriaBuilder.Builders.DATE_GTE)
.with("modifyTimeEnd", "modifyTime", CriteriaBuilder.Builders.DATE_LTE);
}
@Override
public Sort sorts() {
if (StringUtils.isEmpty(sort)) {
return super.sorts();
}
return Sort.by(Sort.Order.desc(sort));
}
}