mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
feat: 添加 applyFunc(), apply形式的"selectFunc"
This commit is contained in:
parent
93d3ab6e1c
commit
321abffa01
@ -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<T, Children extends KtAbstractWrapper<T,
|
||||
() -> formatSqlMaybeWithParam(applySql, null, values)));
|
||||
}
|
||||
|
||||
public Children applyFunc(String applySql, Function<FuncArgs, SelectFunc.Arg[]> consumerFunction, Object... values) {
|
||||
return applyFunc(true, applySql, consumerFunction, values);
|
||||
}
|
||||
|
||||
public Children applyFunc(boolean condition, String applySql,
|
||||
Function<FuncArgs, SelectFunc.Arg[]> 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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user