mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
fixed: 子表过滤应该在join 不应该在where; close #I7F03L
This commit is contained in:
parent
51df4b93e6
commit
6f2d8113c1
@ -30,7 +30,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class CPI {
|
public class CPI {
|
||||||
|
|
||||||
private CPI() {}
|
private CPI() {
|
||||||
|
}
|
||||||
|
|
||||||
public static Object[] getValueArray(QueryWrapper queryWrapper) {
|
public static Object[] getValueArray(QueryWrapper queryWrapper) {
|
||||||
return queryWrapper.getValueArray();
|
return queryWrapper.getValueArray();
|
||||||
@ -97,6 +98,15 @@ public class CPI {
|
|||||||
return join.getQueryTable();
|
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<QueryTable> getJoinTables(QueryWrapper queryWrapper) {
|
public static List<QueryTable> getJoinTables(QueryWrapper queryWrapper) {
|
||||||
return queryWrapper.getJoinTables();
|
return queryWrapper.getJoinTables();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -632,7 +632,6 @@ public class TableInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final String APPEND_CONDITIONS_FLAG = "appendConditions";
|
private static final String APPEND_CONDITIONS_FLAG = "appendConditions";
|
||||||
private static final String APPEND_JOIN_FLAG = "appendJoins";
|
|
||||||
|
|
||||||
public void appendConditions(Object entity, QueryWrapper queryWrapper) {
|
public void appendConditions(Object entity, QueryWrapper queryWrapper) {
|
||||||
|
|
||||||
@ -699,23 +698,24 @@ public class TableInfo {
|
|||||||
|
|
||||||
|
|
||||||
//join
|
//join
|
||||||
if (!Boolean.TRUE.equals(CPI.getContext(queryWrapper, APPEND_JOIN_FLAG))) {
|
List<Join> joins = CPI.getJoins(queryWrapper);
|
||||||
List<Join> joins = CPI.getJoins(queryWrapper);
|
if (CollectionUtil.isNotEmpty(joins)) {
|
||||||
if (CollectionUtil.isNotEmpty(joins)) {
|
for (Join join : joins) {
|
||||||
for (Join join : joins) {
|
QueryTable joinQueryTable = CPI.getJoinQueryTable(join);
|
||||||
QueryTable joinQueryTable = CPI.getJoinQueryTable(join);
|
if (joinQueryTable instanceof SelectQueryTable) {
|
||||||
if (joinQueryTable instanceof SelectQueryTable) {
|
QueryWrapper childQuery = ((SelectQueryTable) joinQueryTable).getQueryWrapper();
|
||||||
QueryWrapper childQuery = ((SelectQueryTable) joinQueryTable).getQueryWrapper();
|
doAppendConditions(entity, childQuery);
|
||||||
doAppendConditions(entity, childQuery);
|
} else {
|
||||||
} else {
|
|
||||||
String nameWithSchema = joinQueryTable.getNameWithSchema();
|
String nameWithSchema = joinQueryTable.getNameWithSchema();
|
||||||
if (StringUtil.isNotBlank(nameWithSchema)) {
|
if (StringUtil.isNotBlank(nameWithSchema)) {
|
||||||
TableInfo tableInfo = TableInfoFactory.ofTableName(nameWithSchema);
|
TableInfo tableInfo = TableInfoFactory.ofTableName(nameWithSchema);
|
||||||
if (tableInfo != null) {
|
if (tableInfo != null) {
|
||||||
CPI.putContext(queryWrapper, APPEND_CONDITIONS_FLAG, Boolean.FALSE);
|
QueryCondition joinQueryCondition = CPI.getJoinQueryCondition(join);
|
||||||
CPI.putContext(queryWrapper, APPEND_JOIN_FLAG, Boolean.TRUE);
|
QueryWrapper newWrapper = QueryWrapper.create()
|
||||||
tableInfo.appendConditions(entity, queryWrapper);
|
.where(joinQueryCondition);
|
||||||
}
|
tableInfo.appendConditions(entity, newWrapper);
|
||||||
|
CPI.setJoinQueryCondition(join, CPI.getWhereQueryCondition(newWrapper));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user