diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractWrapper.java index b504ad12..db33dc7b 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractWrapper.java @@ -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); diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ApplyFuncTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ApplyFuncTest.java index 81e011f6..1fadd7eb 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ApplyFuncTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ApplyFuncTest.java @@ -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(); + } } diff --git a/pom.xml b/pom.xml index f7b71d81..c0484647 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ - 1.5.2 + 1.5.3 3.5.9 17