From 6f2d8113c1e1f8af9f8c22af23251fe2bf663aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Wed, 21 Jun 2023 09:59:31 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20=E5=AD=90=E8=A1=A8=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E5=BA=94=E8=AF=A5=E5=9C=A8join=20=E4=B8=8D=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E5=9C=A8where;=20close=20#I7F03L?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mybatisflex/core/query/CPI.java | 12 ++++++- .../com/mybatisflex/core/table/TableInfo.java | 36 +++++++++---------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java index 09cc40cb..2512763d 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java @@ -30,7 +30,8 @@ import java.util.Map; public class CPI { - private CPI() {} + private CPI() { + } public static Object[] getValueArray(QueryWrapper queryWrapper) { return queryWrapper.getValueArray(); @@ -97,6 +98,15 @@ public class CPI { return join.getQueryTable(); } + public static QueryCondition getJoinQueryCondition(Join join) { + return join.on; + } + + public static void setJoinQueryCondition(Join join, QueryCondition queryCondition) { + join.on = queryCondition; + } + + public static List getJoinTables(QueryWrapper queryWrapper) { return queryWrapper.getJoinTables(); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java index 7a85ae43..87b237ef 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java @@ -632,7 +632,6 @@ public class TableInfo { } private static final String APPEND_CONDITIONS_FLAG = "appendConditions"; - private static final String APPEND_JOIN_FLAG = "appendJoins"; public void appendConditions(Object entity, QueryWrapper queryWrapper) { @@ -699,23 +698,24 @@ public class TableInfo { //join - if (!Boolean.TRUE.equals(CPI.getContext(queryWrapper, APPEND_JOIN_FLAG))) { - List joins = CPI.getJoins(queryWrapper); - if (CollectionUtil.isNotEmpty(joins)) { - for (Join join : joins) { - QueryTable joinQueryTable = CPI.getJoinQueryTable(join); - if (joinQueryTable instanceof SelectQueryTable) { - QueryWrapper childQuery = ((SelectQueryTable) joinQueryTable).getQueryWrapper(); - doAppendConditions(entity, childQuery); - } else { - String nameWithSchema = joinQueryTable.getNameWithSchema(); - if (StringUtil.isNotBlank(nameWithSchema)) { - TableInfo tableInfo = TableInfoFactory.ofTableName(nameWithSchema); - if (tableInfo != null) { - CPI.putContext(queryWrapper, APPEND_CONDITIONS_FLAG, Boolean.FALSE); - CPI.putContext(queryWrapper, APPEND_JOIN_FLAG, Boolean.TRUE); - tableInfo.appendConditions(entity, queryWrapper); - } + List joins = CPI.getJoins(queryWrapper); + if (CollectionUtil.isNotEmpty(joins)) { + for (Join join : joins) { + QueryTable joinQueryTable = CPI.getJoinQueryTable(join); + if (joinQueryTable instanceof SelectQueryTable) { + QueryWrapper childQuery = ((SelectQueryTable) joinQueryTable).getQueryWrapper(); + doAppendConditions(entity, childQuery); + } else { + + String nameWithSchema = joinQueryTable.getNameWithSchema(); + if (StringUtil.isNotBlank(nameWithSchema)) { + TableInfo tableInfo = TableInfoFactory.ofTableName(nameWithSchema); + if (tableInfo != null) { + QueryCondition joinQueryCondition = CPI.getJoinQueryCondition(join); + QueryWrapper newWrapper = QueryWrapper.create() + .where(joinQueryCondition); + tableInfo.appendConditions(entity, newWrapper); + CPI.setJoinQueryCondition(join, CPI.getWhereQueryCondition(newWrapper)); } } }