From 3e822c0b8442a5a00840a9ae67d7fa03cd5d33b0 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Tue, 22 Jul 2025 20:44:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(data):=20Query=20=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=9A=E5=88=97=E6=9F=A5=E8=AF=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=85=B3=E7=B3=BB=E6=94=AF=E6=8C=81=EF=BC=88=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E4=BB=85=E6=94=AF=E6=8C=81=E6=88=96=E8=80=85=EF=BC=8C?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E4=B9=9F=E6=94=AF=E6=8C=81=E5=B9=B6=E4=B8=94?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../starter/data/annotation/Query.java | 6 ++++ .../starter/data/enums/LogicalRelation.java | 36 +++++++++++++++++++ .../starter/data/util/QueryWrapperHelper.java | 16 ++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 continew-starter-data/continew-starter-data-core/src/main/java/top/continew/starter/data/enums/LogicalRelation.java diff --git a/continew-starter-data/continew-starter-data-core/src/main/java/top/continew/starter/data/annotation/Query.java b/continew-starter-data/continew-starter-data-core/src/main/java/top/continew/starter/data/annotation/Query.java index dc395684..0adb8eb6 100644 --- a/continew-starter-data/continew-starter-data-core/src/main/java/top/continew/starter/data/annotation/Query.java +++ b/continew-starter-data/continew-starter-data-core/src/main/java/top/continew/starter/data/annotation/Query.java @@ -16,6 +16,7 @@ package top.continew.starter.data.annotation; +import top.continew.starter.data.enums.LogicalRelation; import top.continew.starter.data.enums.QueryType; import java.lang.annotation.*; @@ -46,4 +47,9 @@ public @interface Query { * 查询类型(等值查询、模糊查询、范围查询等) */ QueryType type() default QueryType.EQ; + + /** + * 多列查询时的逻辑关系(仅当 columns 长度大于 1 时生效) + */ + LogicalRelation logicalRelation() default LogicalRelation.OR; } diff --git a/continew-starter-data/continew-starter-data-core/src/main/java/top/continew/starter/data/enums/LogicalRelation.java b/continew-starter-data/continew-starter-data-core/src/main/java/top/continew/starter/data/enums/LogicalRelation.java new file mode 100644 index 00000000..5c507d3c --- /dev/null +++ b/continew-starter-data/continew-starter-data-core/src/main/java/top/continew/starter/data/enums/LogicalRelation.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.starter.data.enums; + +/** + * 逻辑关系枚举 + * + * @author Charles7c + * @since 2.13.3 + */ +public enum LogicalRelation { + + /** + * 并且关系 + */ + AND, + + /** + * 或者关系 + */ + OR +} \ No newline at end of file diff --git a/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/util/QueryWrapperHelper.java b/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/util/QueryWrapperHelper.java index fadabfb1..135f000d 100644 --- a/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/util/QueryWrapperHelper.java +++ b/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/util/QueryWrapperHelper.java @@ -32,6 +32,7 @@ import top.continew.starter.core.util.validation.ValidationUtils; import top.continew.starter.data.annotation.Query; import top.continew.starter.data.annotation.QueryIgnore; import top.continew.starter.data.enums.QueryType; +import top.continew.starter.data.enums.LogicalRelation; import java.lang.reflect.Field; import java.util.ArrayList; @@ -174,8 +175,21 @@ public class QueryWrapperHelper { return consumers; } // 解析多列查询 + LogicalRelation logicalRelation = queryAnnotation.logicalRelation(); + List>> columnConsumers = new ArrayList<>(); for (String column : columns) { - parse(queryType, column, fieldValue, consumers); + parse(queryType, column, fieldValue, columnConsumers); + } + + if (logicalRelation == LogicalRelation.AND) { + if (!columnConsumers.isEmpty()) { + consumers.add(q -> { + columnConsumers.get(0).accept(q); + columnConsumers.subList(1, columnConsumers.size()).forEach(q::and); + }); + } + } else { + consumers.addAll(columnConsumers); } return consumers; } catch (BadRequestException e) {