1
0

refactor(service): 将查询条件解析逻辑封装到 QueryParser 中

This commit is contained in:
2026-01-07 13:02:47 +08:00
parent 657f9593ba
commit f439381e04
10 changed files with 478 additions and 303 deletions

View File

@@ -1,5 +1,8 @@
package com.lanyuanxiaoyao.service.template.common.controller;
import com.lanyuanxiaoyao.service.template.common.entity.GlobalResponse;
import com.lanyuanxiaoyao.service.template.common.entity.Query;
/**
* 查询控制器接口,用于定义统一的查询实体详情和列表的接口规范
* <p>

View File

@@ -1,5 +1,7 @@
package com.lanyuanxiaoyao.service.template.common.controller;
import com.lanyuanxiaoyao.service.template.common.entity.GlobalResponse;
/**
* 删除控制器接口,用于定义统一的删除实体对象的接口规范
* <p>

View File

@@ -1,5 +1,7 @@
package com.lanyuanxiaoyao.service.template.common.controller;
import com.lanyuanxiaoyao.service.template.common.entity.GlobalResponse;
/**
* 保存控制器接口,用于定义统一的保存实体对象的接口规范
* <p>

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.template.common.controller;
package com.lanyuanxiaoyao.service.template.common.entity;
import java.util.List;
import java.util.Map;

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.template.common.service;
package com.lanyuanxiaoyao.service.template.common.entity;
import java.util.stream.Stream;

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.template.common.controller;
package com.lanyuanxiaoyao.service.template.common.entity;
import java.util.List;
import java.util.Map;

View File

@@ -0,0 +1,125 @@
package com.lanyuanxiaoyao.service.template.common.service;
import com.lanyuanxiaoyao.service.template.common.entity.Query;
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
public abstract class QueryParser<O> {
protected abstract void nullEqual(Query.Queryable queryable);
protected abstract void notNullEqual(Query.Queryable queryable);
protected abstract void empty(Query.Queryable queryable);
protected abstract void notEmpty(Query.Queryable queryable);
protected abstract void equal(Query.Queryable queryable);
protected abstract void notEqual(Query.Queryable queryable);
protected abstract void like(Query.Queryable queryable);
protected abstract void notLike(Query.Queryable queryable);
protected abstract void contain(Query.Queryable queryable);
protected abstract void notContain(Query.Queryable queryable);
protected abstract void startWith(Query.Queryable queryable);
protected abstract void notStartWith(Query.Queryable queryable);
protected abstract void endWith(Query.Queryable queryable);
protected abstract void notEndWith(Query.Queryable queryable);
protected abstract void great(Query.Queryable queryable);
protected abstract void less(Query.Queryable queryable);
protected abstract void greatEqual(Query.Queryable queryable);
protected abstract void lessEqual(Query.Queryable queryable);
protected abstract void inside(Query.Queryable queryable);
protected abstract void notInside(Query.Queryable queryable);
protected abstract void between(Query.Queryable queryable);
protected abstract void notBetween(Query.Queryable queryable);
protected abstract O build();
public O build(Query.Queryable queryable) {
if (ObjectHelper.isNull(queryable)) {
return null;
}
if (ObjectHelper.isNotEmpty(queryable.nullEqual())) {
nullEqual(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.notNullEqual())) {
notNullEqual(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.empty())) {
empty(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.notEmpty())) {
notEmpty(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.equal())) {
equal(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.notEqual())) {
notEqual(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.like())) {
like(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.notLike())) {
notLike(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.contain())) {
contain(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.notContain())) {
notContain(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.startWith())) {
startWith(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.notStartWith())) {
notStartWith(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.endWith())) {
endWith(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.notEndWith())) {
notEndWith(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.great())) {
great(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.less())) {
less(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.greatEqual())) {
greatEqual(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.lessEqual())) {
lessEqual(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.inside())) {
inside(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.notInside())) {
notInside(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.between())) {
between(queryable);
}
if (ObjectHelper.isNotEmpty(queryable.notBetween())) {
notBetween(queryable);
}
return build();
}
}

View File

@@ -1,6 +1,7 @@
package com.lanyuanxiaoyao.service.template.common.service;
import com.lanyuanxiaoyao.service.template.common.controller.Query;
import com.lanyuanxiaoyao.service.template.common.entity.Page;
import com.lanyuanxiaoyao.service.template.common.entity.Query;
import java.util.List;
import java.util.Set;