diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractWrapper.java index abf744f..0fb6fd1 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractWrapper.java @@ -15,6 +15,7 @@ import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.kt.interfaces.CompareIfExists; import com.github.yulichang.kt.interfaces.Func; import com.github.yulichang.kt.interfaces.OnCompare; +import com.github.yulichang.kt.segments.FuncArgs; import com.github.yulichang.toolkit.KtUtils; import com.github.yulichang.toolkit.MPJSqlInjectionUtils; import com.github.yulichang.toolkit.Ref; @@ -25,15 +26,13 @@ import com.github.yulichang.wrapper.enums.PrefixEnum; import com.github.yulichang.wrapper.interfaces.CompareStrIfExists; import com.github.yulichang.wrapper.interfaces.FuncStr; import com.github.yulichang.wrapper.interfaces.Join; +import com.github.yulichang.wrapper.segments.SelectFunc; import kotlin.reflect.KProperty; import lombok.Getter; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.BiPredicate; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.function.Supplier; +import java.util.function.*; import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*; import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.APPLY; @@ -310,6 +309,18 @@ public abstract class KtAbstractWrapper formatSqlMaybeWithParam(applySql, null, values))); } + public Children applyFunc(String applySql, Function consumerFunction, Object... values) { + return applyFunc(true, applySql, consumerFunction, values); + } + + public Children applyFunc(boolean condition, String applySql, + Function consumerFunction, Object... values) { + return maybeDo(condition, () -> appendSqlSegments(APPLY, + () -> formatSqlMaybeWithParam(String.format(applySql, + Arrays.stream(consumerFunction.apply(new FuncArgs())).map(func -> + columnToString(index, null, (KProperty) func.getProperty(), false, PrefixEnum.CD_FIRST)).toArray()), null, values))); + } + @Override public Children last(boolean condition, String lastSql) { if (condition) { diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/segments/FuncArgs.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/segments/FuncArgs.java index aa4f413..17f2610 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/segments/FuncArgs.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/segments/FuncArgs.java @@ -16,7 +16,7 @@ import java.util.Arrays; public class FuncArgs { public SelectFunc.Arg[] accept(KProperty... kProperty) { - return Arrays.stream(kProperty).map(i -> new SelectFunc.Arg(KtUtils.ref(i), i.getName(), false, null)).toArray(SelectFunc.Arg[]::new); + return Arrays.stream(kProperty).map(i -> new SelectFunc.Arg(KtUtils.ref(i), i.getName(), false, null, i)).toArray(SelectFunc.Arg[]::new); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/segments/SelectFunc.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/segments/SelectFunc.java index aa70315..396a30d 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/segments/SelectFunc.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/segments/SelectFunc.java @@ -75,9 +75,9 @@ public class SelectFunc implements Select { boolean ins = i instanceof Fun; if (ins) { Fun f = (Fun) i; - return new Arg(LambdaUtils.getEntityClass(f.getFunc()), LambdaUtils.getName(f.getFunc()), true, f.getAlias()); + return new Arg(LambdaUtils.getEntityClass(f.getFunc()), LambdaUtils.getName(f.getFunc()), true, f.getAlias(), null); } else { - return new Arg(LambdaUtils.getEntityClass(i), LambdaUtils.getName(i), false, null); + return new Arg(LambdaUtils.getEntityClass(i), LambdaUtils.getName(i), false, null, null); } }).toArray(Arg[]::new); this.cache = null; @@ -164,5 +164,6 @@ public class SelectFunc implements Select { private final String prop; private final boolean hasTableAlias; private final String tableAlias; + private final Object property; } }