Skip to content

Commit

Permalink
fix: applyFunc 子查询异常
Browse files Browse the repository at this point in the history
  • Loading branch information
yulichang committed Nov 1, 2024
1 parent 8ecc698 commit d7f7f19
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ public Children applyFunc(boolean condition, String applySql,
Arrays.stream(funcConsumer.getArgs()).map(func -> {
if (func instanceof Fun) {
Fun<?, ?> fun = (Fun<?, ?>) func;
if (fun.isSub()) {
@SuppressWarnings("rawtypes")
MPJLambdaWrapper wrapper = fun.getSub().apply((MPJLambdaWrapper) subInstance(fun.getClazz()));
return WrapperUtils.buildUnionSqlByWrapper(fun.getClazz(),
fun.getSub().apply(wrapper));
}
return columnToString(index, fun.getAlias(), fun.getFunc(), false, PrefixEnum.CD_FIRST, false);
}
return columnToString(index, null, func, false, PrefixEnum.CD_FIRST, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,26 @@ void applyFunc() {
list1.forEach(System.out::println);
}

@Test
void applyFunc1() {
ThreadLocalUtils.set("""
SELECT
t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id,
t.address_id2, t.del, t.create_by, t.update_by
FROM `user` t
LEFT JOIN address t1 ON (t1.user_id = t.id)
WHERE t.del = false
AND t1.del = false
AND (concat(t.id, t.id, (SELECT st.id, st.id FROM `user` st WHERE st.del = false AND (st.id = ? AND st.id = ?)), ?) IS NOT NULL)
""");
JoinWrappers.lambda(UserDO.class)
.selectAll(UserDO.class, UserDO::getId)
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
.applyFunc("concat(%s, %s, %s, {0}) is not null", arg -> arg.accept(
UserDO::getId,
Fun.f("t", UserDO::getId),
Fun.f(UserDO.class, user -> user.select(UserDO::getId).eq(UserDO::getId, 1))
), "12")
.list();
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</modules>

<properties>
<revision>1.5.2</revision>
<revision>1.5.3</revision>
<mybatis.plus.version>3.5.9</mybatis.plus.version>

<jdkVersion>17</jdkVersion>
Expand Down

0 comments on commit d7f7f19

Please sign in to comment.