commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.budwk.app.base.dao;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
/**
|
||||
* 条件构造辅助类。
|
||||
* 当前健步走移植代码需要按页面查询条件动态追加字段查询和排序,空字段不应参与 SQL 条件。
|
||||
*/
|
||||
public class CndPlus extends Cnd {
|
||||
private static final NutMap ORDER_MAP = NutMap.NEW().addv("ascending", "asc").addv("descending", "desc");
|
||||
|
||||
public static CndPlus create() {
|
||||
return new CndPlus();
|
||||
}
|
||||
|
||||
public CndPlus and(PageForm pageForm) {
|
||||
if (pageForm != null && StrUtil.isAllNotBlank(pageForm.getSearchName(), pageForm.getSearchKeyword())) {
|
||||
this.where().andLike(pageForm.getSearchName(), pageForm.getSearchKeyword());
|
||||
}
|
||||
if (pageForm != null && StrUtil.isAllNotBlank(pageForm.getPageOrderName(), pageForm.getPageOrderBy())) {
|
||||
this.orderBy(pageForm.getPageOrderName(), ORDER_MAP.getString(pageForm.getPageOrderBy()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅在字段名和值都有效时追加条件,避免可选筛选项为空时生成无效 SQL。
|
||||
*
|
||||
* @param name 字段名或表达式
|
||||
* @param op 比较操作符
|
||||
* @param value 比较值
|
||||
* @return 当前条件对象
|
||||
*/
|
||||
public CndPlus andEX(String name, String op, Object value) {
|
||||
if (StrUtil.isNotBlank(name) && !Lang.isEmpty(value)) {
|
||||
this.and(name, op, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user