mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
同步 geSql gtSql leSql ltSql 方法
This commit is contained in:
parent
917a400290
commit
09e8037ff1
@ -32,19 +32,19 @@ public abstract class MPJAbstractLambdaWrapper<T, Children extends MPJAbstractLa
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <X> String columnToString(String index, int node, X column, boolean isJoin) {
|
protected <X> String columnToString(String index, int node, X column, boolean isJoin, Class<?> parent) {
|
||||||
return columnToString(index, node, (SFunction<?, ?>) column, isJoin);
|
return columnToString(index, node, (SFunction<?, ?>) column, isJoin, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
protected final <X> String columnsToString(String index, int node, boolean isJoin, X... columns) {
|
protected final <X> String columnsToString(String index, int node, boolean isJoin, Class<?> parent, X... columns) {
|
||||||
return Arrays.stream(columns).map(i -> columnToString(index, node, (SFunction<?, ?>) i, isJoin)).collect(joining(StringPool.COMMA));
|
return Arrays.stream(columns).map(i -> columnToString(index, node, (SFunction<?, ?>) i, isJoin, parent)).collect(joining(StringPool.COMMA));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String columnToString(String index, int node, SFunction<?, ?> column, boolean isJoin) {
|
protected String columnToString(String index, int node, SFunction<?, ?> column, boolean isJoin, Class<?> parent) {
|
||||||
Class<?> entityClass = LambdaUtils.getEntityClass(column);
|
Class<?> entityClass = LambdaUtils.getEntityClass(column);
|
||||||
return Constant.TABLE_ALIAS + getDefault(index, node, entityClass, isJoin) + StringPool.DOT +
|
return Constant.TABLE_ALIAS + getDefault(index, node, entityClass, isJoin, parent) + StringPool.DOT +
|
||||||
getCache(column).getTagColumn();
|
getCache(column).getTagColumn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ public abstract class MPJAbstractLambdaWrapper<T, Children extends MPJAbstractLa
|
|||||||
return cacheMap.get(LambdaUtils.getName(fn));
|
return cacheMap.get(LambdaUtils.getName(fn));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getDefault(String index, int node, Class<?> clazz, boolean isJoin) {
|
protected String getDefault(String index, int node, Class<?> clazz, boolean isJoin, Class<?> parent) {
|
||||||
if (Objects.isNull(index)) {
|
if (Objects.isNull(index)) {
|
||||||
if (!isJoin && Objects.equals(clazz, getEntityClass())) {
|
if (!isJoin && Objects.equals(clazz, getEntityClass())) {
|
||||||
return StringPool.EMPTY;
|
return StringPool.EMPTY;
|
||||||
@ -65,7 +65,7 @@ public abstract class MPJAbstractLambdaWrapper<T, Children extends MPJAbstractLa
|
|||||||
}
|
}
|
||||||
Table table = tableList.get(clazz, index);
|
Table table = tableList.get(clazz, index);
|
||||||
if (Objects.nonNull(table.getIndex())) {
|
if (Objects.nonNull(table.getIndex())) {
|
||||||
if (isJoin && clazz == getEntityClass()) {
|
if (isJoin && (Objects.equals(clazz, getEntityClass()) || Objects.equals(parent, clazz))) {
|
||||||
if (node == -1) {
|
if (node == -1) {
|
||||||
return StringPool.EMPTY;
|
return StringPool.EMPTY;
|
||||||
} else if (node == 0) {
|
} else if (node == 0) {
|
||||||
@ -218,4 +218,6 @@ public abstract class MPJAbstractLambdaWrapper<T, Children extends MPJAbstractLa
|
|||||||
|
|
||||||
private final String index;
|
private final String index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,8 @@ import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
|
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||||
import com.github.yulichang.wrapper.interfaces.Compare;
|
import com.github.yulichang.wrapper.interfaces.*;
|
||||||
import com.github.yulichang.wrapper.interfaces.Func;
|
|
||||||
import com.github.yulichang.wrapper.interfaces.Join;
|
|
||||||
import com.github.yulichang.wrapper.interfaces.OnCompare;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -37,7 +33,8 @@ import static java.util.stream.Collectors.joining;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL")
|
||||||
public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<T, Children>> extends Wrapper<T>
|
public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<T, Children>> extends Wrapper<T>
|
||||||
implements Compare<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children> {
|
implements Compare<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
||||||
|
CompareStr<Children, String>, FuncStr<Children, String> {
|
||||||
|
|
||||||
protected static final Node ROOT_NODE = new Node(null, 0, null);
|
protected static final Node ROOT_NODE = new Node(null, 0, null);
|
||||||
|
|
||||||
@ -323,11 +320,36 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
|||||||
() -> String.format("(%s)", inValue)));
|
() -> String.format("(%s)", inValue)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <X> Children gtSql(boolean condition, SFunction<X, ?> column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, column, false), GT,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <X> Children geSql(boolean condition, SFunction<X, ?> column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, column, false), GE,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <X> Children ltSql(boolean condition, SFunction<X, ?> column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, column, false), LT,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <X> Children leSql(boolean condition, SFunction<X, ?> column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, column, false), LE,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Children groupBy(boolean condition, List<SFunction<R, ?>> columns) {
|
public <R> Children groupBy(boolean condition, List<SFunction<R, ?>> columns) {
|
||||||
return maybeDo(condition, () -> {
|
return maybeDo(condition, () -> {
|
||||||
if (CollectionUtils.isNotEmpty(columns)) {
|
if (CollectionUtils.isNotEmpty(columns)) {
|
||||||
String one = (StringPool.COMMA + columnsToString(index, getByClass(node, joinClass), false, columns));
|
String one = (StringPool.COMMA + columnsToString(index, getByClass(node, joinClass), false, parentClass(node), columns));
|
||||||
final String finalOne = one;
|
final String finalOne = one;
|
||||||
appendSqlSegments(GROUP_BY, () -> finalOne);
|
appendSqlSegments(GROUP_BY, () -> finalOne);
|
||||||
}
|
}
|
||||||
@ -337,9 +359,9 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
|||||||
@Override
|
@Override
|
||||||
public <X> Children groupBy(boolean condition, SFunction<X, ?> column, SFunction<X, ?>... columns) {
|
public <X> Children groupBy(boolean condition, SFunction<X, ?> column, SFunction<X, ?>... columns) {
|
||||||
return maybeDo(condition, () -> {
|
return maybeDo(condition, () -> {
|
||||||
String one = columnToString(index, getByClass(node, joinClass), column, false);
|
String one = columnToString(index, getByClass(node, joinClass), column, false, parentClass(node));
|
||||||
if (ArrayUtils.isNotEmpty(columns)) {
|
if (ArrayUtils.isNotEmpty(columns)) {
|
||||||
one += (StringPool.COMMA + columnsToString(index, getByClass(node, joinClass), false, columns));
|
one += (StringPool.COMMA + columnsToString(index, getByClass(node, joinClass), false, parentClass(node), columns));
|
||||||
}
|
}
|
||||||
final String finalOne = one;
|
final String finalOne = one;
|
||||||
appendSqlSegments(GROUP_BY, () -> finalOne);
|
appendSqlSegments(GROUP_BY, () -> finalOne);
|
||||||
@ -426,6 +448,11 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
|||||||
() -> formatParam(null, SqlUtils.concatLike(val, sqlLike))));
|
() -> formatParam(null, SqlUtils.concatLike(val, sqlLike))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Children likeValue(boolean condition, SqlKeyword keyword, String column, Object val, SqlLike sqlLike) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), keyword,
|
||||||
|
() -> formatParam(null, SqlUtils.concatLike(val, sqlLike))));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 普通查询条件
|
* 普通查询条件
|
||||||
*
|
*
|
||||||
@ -440,11 +467,15 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected <X, S> Children addCondition(boolean condition, SFunction<X, ?> column, SqlKeyword sqlKeyword, SFunction<S, ?> val) {
|
protected <X, S> Children addCondition(boolean condition, SFunction<X, ?> column, SqlKeyword sqlKeyword, SFunction<S, ?> val) {
|
||||||
Node nnnn = this.node;
|
|
||||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, column, false), sqlKeyword,
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, column, false), sqlKeyword,
|
||||||
columnToSqlSegment(index, val, true)));
|
columnToSqlSegment(index, val, true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Children addCondition(boolean condition, String column, SqlKeyword sqlKeyword, Object val) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), sqlKeyword,
|
||||||
|
() -> formatParam(null, val)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多重嵌套查询条件
|
* 多重嵌套查询条件
|
||||||
*
|
*
|
||||||
@ -626,23 +657,40 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
|||||||
* 获取 columnName
|
* 获取 columnName
|
||||||
*/
|
*/
|
||||||
protected final <X> ISqlSegment columnToSqlSegment(String index, SFunction<X, ?> column, boolean isJoin) {
|
protected final <X> ISqlSegment columnToSqlSegment(String index, SFunction<X, ?> column, boolean isJoin) {
|
||||||
return () -> columnToString(index, getByClass(node, joinClass), column, isJoin);
|
return () -> columnToString(index, getByClass(node, joinClass), column, isJoin, parentClass(node));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <X> ISqlSegment columnToSqlSegment(String column) {
|
||||||
|
return () -> (String) column;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 columnName
|
* 获取 columnName
|
||||||
*/
|
*/
|
||||||
protected <X> String columnToString(String index, int node, X column, boolean isJoin) {
|
protected <X> String columnToString(String index, int node, X column, boolean isJoin, Class<?> parent) {
|
||||||
return (String) column;
|
return (String) column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String columnToString(String column) {
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String columnsToString(List<String> columns) {
|
||||||
|
return columns.stream().map(this::columnToString).collect(joining(StringPool.COMMA));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String columnsToString(String... columns) {
|
||||||
|
return Arrays.stream(columns).map(this::columnToString).collect(joining(StringPool.COMMA));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多字段转换为逗号 "," 分割字符串
|
* 多字段转换为逗号 "," 分割字符串
|
||||||
*
|
*
|
||||||
* @param columns 多字段
|
* @param columns 多字段
|
||||||
*/
|
*/
|
||||||
protected <X> String columnsToString(String index, int node, boolean isJoin, X... columns) {
|
protected <X> String columnsToString(String index, int node, boolean isJoin, Class<?> parent, X... columns) {
|
||||||
return Arrays.stream(columns).map(i -> this.columnToString(index, node, i, isJoin)).collect(joining(StringPool.COMMA));
|
return Arrays.stream(columns).map(i -> this.columnToString(index, node, i, isJoin, parent)).collect(joining(StringPool.COMMA));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -692,8 +740,7 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
|||||||
return addCondition(condition, column, LE, val);
|
return addCondition(condition, column, LE, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Node {
|
public static class Node {
|
||||||
|
|
||||||
@ -715,6 +762,13 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Class<?> parentClass(Node node) {
|
||||||
|
if (node == null || node.parent == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return node.parent.clazz;
|
||||||
|
}
|
||||||
|
|
||||||
private int dg(Node node, Class<?> joinClass) {
|
private int dg(Node node, Class<?> joinClass) {
|
||||||
|
|
||||||
if (node.clazz != null && node.clazz == joinClass) {
|
if (node.clazz != null && node.clazz == joinClass) {
|
||||||
@ -725,4 +779,225 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
|||||||
}
|
}
|
||||||
return getByClass(node.parent, joinClass);
|
return getByClass(node.parent, joinClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ****************************************** **/
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <V> Children allEqStr(boolean condition, Map<String, V> params, boolean null2IsNull) {
|
||||||
|
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||||
|
params.forEach((k, v) -> {
|
||||||
|
if (StringUtils.checkValNotNull(v)) {
|
||||||
|
eq(k, v);
|
||||||
|
} else {
|
||||||
|
if (null2IsNull) {
|
||||||
|
isNull(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return typedThis;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <V> Children allEqStr(boolean condition, BiPredicate<String, V> filter, Map<String, V> params, boolean null2IsNull) {
|
||||||
|
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||||
|
params.forEach((k, v) -> {
|
||||||
|
if (filter.test(k, v)) {
|
||||||
|
if (StringUtils.checkValNotNull(v)) {
|
||||||
|
eq(k, v);
|
||||||
|
} else {
|
||||||
|
if (null2IsNull) {
|
||||||
|
isNull(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return typedThis;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children eq(boolean condition, String column, Object val) {
|
||||||
|
return addCondition(condition, column, EQ, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children ne(boolean condition, String column, Object val) {
|
||||||
|
return addCondition(condition, column, NE, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children gt(boolean condition, String column, Object val) {
|
||||||
|
return addCondition(condition, column, GT, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children ge(boolean condition, String column, Object val) {
|
||||||
|
return addCondition(condition, column, GE, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children lt(boolean condition, String column, Object val) {
|
||||||
|
return addCondition(condition, column, LT, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children le(boolean condition, String column, Object val) {
|
||||||
|
return addCondition(condition, column, LE, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children like(boolean condition, String column, Object val) {
|
||||||
|
return likeValue(condition, LIKE, column, val, SqlLike.DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children notLike(boolean condition, String column, Object val) {
|
||||||
|
return likeValue(condition, NOT_LIKE, column, val, SqlLike.DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children likeLeft(boolean condition, String column, Object val) {
|
||||||
|
return likeValue(condition, LIKE, column, val, SqlLike.LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children likeRight(boolean condition, String column, Object val) {
|
||||||
|
return likeValue(condition, LIKE, column, val, SqlLike.RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children between(boolean condition, String column, Object val1, Object val2) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), BETWEEN,
|
||||||
|
() -> formatParam(null, val1), AND, () -> formatParam(null, val2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children notBetween(boolean condition, String column, Object val1, Object val2) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), NOT_BETWEEN,
|
||||||
|
() -> formatParam(null, val1), AND, () -> formatParam(null, val2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ****************************************** **/
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children isNull(boolean condition, String column) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), IS_NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children isNotNull(boolean condition, String column) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), IS_NOT_NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children in(boolean condition, String column, Collection<?> coll) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), IN, inExpression(coll)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children in(boolean condition, String column, Object... values) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), IN, inExpression(values)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children notIn(boolean condition, String column, Collection<?> coll) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), NOT_IN, inExpression(coll)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children notIn(boolean condition, String column, Object... values) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), NOT_IN, inExpression(values)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children inSql(boolean condition, String column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), IN,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children gtSql(boolean condition, String column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), GT,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children geSql(boolean condition, String column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), GE,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children ltSql(boolean condition, String column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), LT,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children leSql(boolean condition, String column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), LE,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children notInSql(boolean condition, String column, String inValue) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), NOT_IN,
|
||||||
|
() -> String.format("(%s)", inValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children groupBy(boolean condition, String column, String... columns) {
|
||||||
|
return maybeDo(condition, () -> {
|
||||||
|
String one = columnToString(column);
|
||||||
|
if (ArrayUtils.isNotEmpty(columns)) {
|
||||||
|
one += (StringPool.COMMA + columnsToString(columns));
|
||||||
|
}
|
||||||
|
final String finalOne = one;
|
||||||
|
appendSqlSegments(GROUP_BY, () -> finalOne);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Children orderBy(boolean condition, boolean isAsc, String column, String... columns) {
|
||||||
|
return maybeDo(condition, () -> {
|
||||||
|
final SqlKeyword mode = isAsc ? ASC : DESC;
|
||||||
|
appendSqlSegments(ORDER_BY, columnToSqlSegment(columnSqlInjectFilter(column)), mode);
|
||||||
|
if (ArrayUtils.isNotEmpty(columns)) {
|
||||||
|
Arrays.stream(columns).forEach(c -> appendSqlSegments(ORDER_BY,
|
||||||
|
columnToSqlSegment(columnSqlInjectFilter(c)), mode));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String columnSqlInjectFilter(String column) {
|
||||||
|
return StringUtils.sqlInjectionReplaceBlank(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children groupBy(boolean condition, String column) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(GROUP_BY, () -> columnToString(column)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children groupByStr(boolean condition, List<String> columns) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(GROUP_BY, () -> columnsToString(columns)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children orderBy(boolean condition, boolean isAsc, String column) {
|
||||||
|
return maybeDo(condition, () -> appendSqlSegments(ORDER_BY, columnToSqlSegment(columnSqlInjectFilter(column)),
|
||||||
|
isAsc ? ASC : DESC));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Children orderByStr(boolean condition, boolean isAsc, List<String> columns) {
|
||||||
|
return maybeDo(condition, () -> columns.forEach(c -> appendSqlSegments(ORDER_BY,
|
||||||
|
columnToSqlSegment(columnSqlInjectFilter(c)), isAsc ? ASC : DESC)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ import com.github.yulichang.toolkit.support.ColumnCache;
|
|||||||
import com.github.yulichang.wrapper.interfaces.Query;
|
import com.github.yulichang.wrapper.interfaces.Query;
|
||||||
import com.github.yulichang.wrapper.interfaces.QueryJoin;
|
import com.github.yulichang.wrapper.interfaces.QueryJoin;
|
||||||
import com.github.yulichang.wrapper.interfaces.QueryLabel;
|
import com.github.yulichang.wrapper.interfaces.QueryLabel;
|
||||||
import com.github.yulichang.wrapper.interfaces.WrapperBiConsumer;
|
|
||||||
import com.github.yulichang.wrapper.resultmap.MybatisLabel;
|
import com.github.yulichang.wrapper.resultmap.MybatisLabel;
|
||||||
import com.github.yulichang.wrapper.segments.Select;
|
import com.github.yulichang.wrapper.segments.Select;
|
||||||
import com.github.yulichang.wrapper.segments.SelectCache;
|
import com.github.yulichang.wrapper.segments.SelectCache;
|
||||||
@ -29,6 +28,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,6 +184,9 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
|
|||||||
public String getSqlSelect() {
|
public String getSqlSelect() {
|
||||||
if (StringUtils.isBlank(sqlSelect.getStringValue()) && CollectionUtils.isNotEmpty(selectColumns)) {
|
if (StringUtils.isBlank(sqlSelect.getStringValue()) && CollectionUtils.isNotEmpty(selectColumns)) {
|
||||||
String s = selectColumns.stream().map(i -> {
|
String s = selectColumns.stream().map(i -> {
|
||||||
|
if (i.isStr()) {
|
||||||
|
return i.getColumn();
|
||||||
|
}
|
||||||
String str = Constant.TABLE_ALIAS + getDefaultSelect(i.getIndex(), i.getClazz(), i) + StringPool.DOT + i.getColumn();
|
String str = Constant.TABLE_ALIAS + getDefaultSelect(i.getIndex(), i.getClazz(), i) + StringPool.DOT + i.getColumn();
|
||||||
return i.isFunc() ? (String.format(i.getFunc().getSql(), str) + Constant.AS + i.getAlias()) : (i.isHasAlias() ? (str + Constant.AS + i.getAlias()) : str);
|
return i.isFunc() ? (String.format(i.getFunc().getSql(), str) + Constant.AS + i.getAlias()) : (i.isHasAlias() ? (str + Constant.AS + i.getAlias()) : str);
|
||||||
}).collect(Collectors.joining(StringPool.COMMA));
|
}).collect(Collectors.joining(StringPool.COMMA));
|
||||||
@ -302,8 +305,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
|
|||||||
* 调用此方法 keyword 前后需要带空格 比如 " LEFT JOIN " " RIGHT JOIN "
|
* 调用此方法 keyword 前后需要带空格 比如 " LEFT JOIN " " RIGHT JOIN "
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <R> MPJLambdaWrapper<T> join(String keyWord, Class<R> clazz, WrapperBiConsumer<T> consumer) {
|
public <R> MPJLambdaWrapper<T> join(String keyWord, Class<R> clazz, BiConsumer<MPJAbstractLambdaWrapper<T, ?>, MPJLambdaWrapper<T>> consumer) {
|
||||||
Node nnnnn = this.node;
|
|
||||||
String oldIndex = this.getIndex();
|
String oldIndex = this.getIndex();
|
||||||
String newIndex = String.valueOf(tableIndex);
|
String newIndex = String.valueOf(tableIndex);
|
||||||
Node n = Objects.isNull(oldIndex) ? new Node(clazz, tableIndex, ROOT_NODE) : new Node(clazz, tableIndex, this.node);
|
Node n = Objects.isNull(oldIndex) ? new Node(clazz, tableIndex, ROOT_NODE) : new Node(clazz, tableIndex, this.node);
|
||||||
|
@ -0,0 +1,284 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2022, baomidou (jobob@qq.com).
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.github.yulichang.wrapper.interfaces;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copu {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||||
|
*
|
||||||
|
* @since 1.3.12
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("ALL")
|
||||||
|
public interface CompareStr<Children, R> extends Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default <V> Children allEqStr(Map<R, V> params) {
|
||||||
|
return allEqStr(params, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default <V> Children allEqStr(Map<R, V> params, boolean null2IsNull) {
|
||||||
|
return allEqStr(true, params, null2IsNull);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* map 所有非空属性等于 =
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param params map 类型的参数, key 是字段名, value 是字段值
|
||||||
|
* @param null2IsNull 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段\
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
<V> Children allEqStr(boolean condition, Map<R, V> params, boolean null2IsNull);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default <V> Children allEqStr(BiPredicate<R, V> filter, Map<R, V> params) {
|
||||||
|
return allEqStr(filter, params, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default <V> Children allEqStr(BiPredicate<R, V> filter, Map<R, V> params, boolean null2IsNull) {
|
||||||
|
return allEqStr(true, filter, params, null2IsNull);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段过滤接口,传入多参数时允许对参数进行过滤
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param filter 返回 true 来允许字段传入比对条件中
|
||||||
|
* @param params map 类型的参数, key 是字段名, value 是字段值
|
||||||
|
* @param null2IsNull 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
<V> Children allEqStr(boolean condition, BiPredicate<R, V> filter, Map<R, V> params, boolean null2IsNull);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children eq(R column, Object val) {
|
||||||
|
return eq(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 等于 =
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children eq(boolean condition, R column, Object val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children ne(R column, Object val) {
|
||||||
|
return ne(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不等于 <>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children ne(boolean condition, R column, Object val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children gt(R column, Object val) {
|
||||||
|
return gt(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大于 >
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children gt(boolean condition, R column, Object val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children ge(R column, Object val) {
|
||||||
|
return ge(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大于等于 >=
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children ge(boolean condition, R column, Object val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children lt(R column, Object val) {
|
||||||
|
return lt(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小于 <
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children lt(boolean condition, R column, Object val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children le(R column, Object val) {
|
||||||
|
return le(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小于等于 <=
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children le(boolean condition, R column, Object val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children between(R column, Object val1, Object val2) {
|
||||||
|
return between(true, column, val1, val2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BETWEEN 值1 AND 值2
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val1 值1
|
||||||
|
* @param val2 值2
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children between(boolean condition, R column, Object val1, Object val2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children notBetween(R column, Object val1, Object val2) {
|
||||||
|
return notBetween(true, column, val1, val2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOT BETWEEN 值1 AND 值2
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val1 值1
|
||||||
|
* @param val2 值2
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children notBetween(boolean condition, R column, Object val1, Object val2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children like(R column, Object val) {
|
||||||
|
return like(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIKE '%值%'
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children like(boolean condition, R column, Object val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children notLike(R column, Object val) {
|
||||||
|
return notLike(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOT LIKE '%值%'
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children notLike(boolean condition, R column, Object val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children likeLeft(R column, Object val) {
|
||||||
|
return likeLeft(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIKE '%值'
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children likeLeft(boolean condition, R column, Object val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children likeRight(R column, Object val) {
|
||||||
|
return likeRight(true, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIKE '值%'
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children likeRight(boolean condition, R column, Object val);
|
||||||
|
}
|
@ -12,7 +12,7 @@ import java.util.function.Consumer;
|
|||||||
* <p>
|
* <p>
|
||||||
* copy {@link com.baomidou.mybatisplus.core.conditions.interfaces.Func}
|
* copy {@link com.baomidou.mybatisplus.core.conditions.interfaces.Func}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked", "unused"})
|
@SuppressWarnings({"unchecked", "unused", "JavadocDeclaration"})
|
||||||
public interface Func<Children> extends Serializable {
|
public interface Func<Children> extends Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,6 +168,83 @@ public interface Func<Children> extends Serializable {
|
|||||||
*/
|
*/
|
||||||
<R> Children notInSql(boolean condition, SFunction<R, ?> column, String inValue);
|
<R> Children notInSql(boolean condition, SFunction<R, ?> column, String inValue);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 > ( sql语句 )
|
||||||
|
* <p>例1: gtSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例1: gtSql("id", "select id from table where name = 'JunJun'")</p>
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param column
|
||||||
|
* @param inValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
<R> Children gtSql(boolean condition, SFunction<R, ?> column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default <R> Children gtSql(SFunction<R, ?> column, String inValue) {
|
||||||
|
return gtSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 >= ( sql语句 )
|
||||||
|
* <p>例1: geSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例1: geSql("id", "select id from table where name = 'JunJun'")</p>
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param column
|
||||||
|
* @param inValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
<R> Children geSql(boolean condition, SFunction<R, ?> column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default <R> Children geSql(SFunction<R, ?> column, String inValue) {
|
||||||
|
return geSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 < ( sql语句 )
|
||||||
|
* <p>例1: ltSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例1: ltSql("id", "select id from table where name = 'JunJun'")</p>
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param column
|
||||||
|
* @param inValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
<R> Children ltSql(boolean condition, SFunction<R, ?> column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default <R> Children ltSql(SFunction<R, ?> column, String inValue) {
|
||||||
|
return ltSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 <= ( sql语句 )
|
||||||
|
* <p>例1: leSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例1: leSql("id", "select id from table where name = 'JunJun'")</p>
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param column
|
||||||
|
* @param inValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
<R> Children leSql(boolean condition, SFunction<R, ?> column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default <R> Children leSql(SFunction<R, ?> column, String inValue) {
|
||||||
|
return leSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore
|
* ignore
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,408 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2022, baomidou (jobob@qq.com).
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.github.yulichang.wrapper.interfaces;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copy {@link com.baomidou.mybatisplus.core.conditions.interfaces.Func}
|
||||||
|
*
|
||||||
|
* @since 1.3.12
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("ALL")
|
||||||
|
public interface FuncStr<Children, R> extends Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children isNull(R column) {
|
||||||
|
return isNull(true, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 IS NULL
|
||||||
|
* <p>例: isNull("name")</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children isNull(boolean condition, R column);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children isNotNull(R column) {
|
||||||
|
return isNotNull(true, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 IS NOT NULL
|
||||||
|
* <p>例: isNotNull("name")</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children isNotNull(boolean condition, R column);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children in(R column, Collection<?> coll) {
|
||||||
|
return in(true, column, coll);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 IN (value.get(0), value.get(1), ...)
|
||||||
|
* <p>例: in("id", Arrays.asList(1, 2, 3, 4, 5))</p>
|
||||||
|
*
|
||||||
|
* <li> 注意!集合为空若存在逻辑错误,请在 condition 条件中判断 </li>
|
||||||
|
* <li> 如果集合为 empty 则不会进行 sql 拼接 </li>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param coll 数据集合
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children in(boolean condition, R column, Collection<?> coll);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children in(R column, Object... values) {
|
||||||
|
return in(true, column, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 IN (v0, v1, ...)
|
||||||
|
* <p>例: in("id", 1, 2, 3, 4, 5)</p>
|
||||||
|
*
|
||||||
|
* <li> 注意!数组为空若存在逻辑错误,请在 condition 条件中判断 </li>
|
||||||
|
* <li> 如果动态数组为 empty 则不会进行 sql 拼接 </li>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param values 数据数组
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children in(boolean condition, R column, Object... values);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children notIn(R column, Collection<?> coll) {
|
||||||
|
return notIn(true, column, coll);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 NOT IN (value.get(0), value.get(1), ...)
|
||||||
|
* <p>例: notIn("id", Arrays.asList(1, 2, 3, 4, 5))</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param coll 数据集合
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children notIn(boolean condition, R column, Collection<?> coll);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children notIn(R column, Object... value) {
|
||||||
|
return notIn(true, column, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 NOT IN (v0, v1, ...)
|
||||||
|
* <p>例: notIn("id", 1, 2, 3, 4, 5)</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param values 数据数组
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children notIn(boolean condition, R column, Object... values);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children inSql(R column, String inValue) {
|
||||||
|
return inSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 IN ( sql语句 )
|
||||||
|
* <p>!! sql 注入方式的 in 方法 !!</p>
|
||||||
|
* <p>例1: inSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例2: inSql("id", "select id from table where id < 3")</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param inValue sql语句
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children inSql(boolean condition, R column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 > ( sql语句 )
|
||||||
|
* <p>例1: gtSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例1: gtSql("id", "select id from table where name = 'JunJun'")</p>
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param column
|
||||||
|
* @param inValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Children gtSql(boolean condition, R column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children gtSql(R column, String inValue) {
|
||||||
|
return gtSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 >= ( sql语句 )
|
||||||
|
* <p>例1: geSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例1: geSql("id", "select id from table where name = 'JunJun'")</p>
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param column
|
||||||
|
* @param inValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Children geSql(boolean condition, R column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children geSql(R column, String inValue) {
|
||||||
|
return geSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 < ( sql语句 )
|
||||||
|
* <p>例1: ltSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例1: ltSql("id", "select id from table where name = 'JunJun'")</p>
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param column
|
||||||
|
* @param inValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Children ltSql(boolean condition, R column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children ltSql(R column, String inValue) {
|
||||||
|
return ltSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 <= ( sql语句 )
|
||||||
|
* <p>例1: leSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例1: leSql("id", "select id from table where name = 'JunJun'")</p>
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param column
|
||||||
|
* @param inValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Children leSql(boolean condition, R column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children leSql(R column, String inValue) {
|
||||||
|
return leSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ignore
|
||||||
|
*/
|
||||||
|
default Children notInSql(R column, String inValue) {
|
||||||
|
return notInSql(true, column, inValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段 NOT IN ( sql语句 )
|
||||||
|
* <p>!! sql 注入方式的 not in 方法 !!</p>
|
||||||
|
* <p>例1: notInSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||||
|
* <p>例2: notInSql("id", "select id from table where id < 3")</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @param inValue sql语句 ---> 1,2,3,4,5,6 或者 select id from table where id < 3
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children notInSql(boolean condition, R column, String inValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组:GROUP BY 字段, ...
|
||||||
|
* <p>例: groupBy("id")</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 单个字段
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children groupBy(boolean condition, R column);
|
||||||
|
|
||||||
|
default Children groupBy(R column) {
|
||||||
|
return groupBy(true, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组:GROUP BY 字段, ...
|
||||||
|
* <p>例: groupBy(Arrays.asList("id", "name"))</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param columns 字段数组
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children groupByStr(boolean condition, List<R> columns);
|
||||||
|
|
||||||
|
default Children groupByStr(List<R> columns) {
|
||||||
|
return groupByStr(true, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children groupBy(R column, R... columns) {
|
||||||
|
return groupBy(true, column, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组:GROUP BY 字段, ...
|
||||||
|
*/
|
||||||
|
Children groupBy(boolean condition, R column, R... columns);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序:ORDER BY 字段, ... ASC
|
||||||
|
* <p>例: orderByAsc(true, "id")</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 单个字段
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children orderByAsc(boolean condition, R column) {
|
||||||
|
return orderBy(condition, true, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children orderByAsc(R column) {
|
||||||
|
return orderByAsc(true, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序:ORDER BY 字段, ... ASC
|
||||||
|
* <p>例: orderByAsc(true, Arrays.asList("id", "name"))</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param columns 字段数组
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children orderByAscStr(boolean condition, List<R> columns) {
|
||||||
|
return orderByStr(condition, true, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children orderByAscStr(List<R> columns) {
|
||||||
|
return orderByAscStr(true, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children orderByAsc(R column, R... columns) {
|
||||||
|
return orderByAsc(true, column, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序:ORDER BY 字段, ... ASC
|
||||||
|
*/
|
||||||
|
default Children orderByAsc(boolean condition, R column, R... columns) {
|
||||||
|
return orderBy(condition, true, column, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序:ORDER BY 字段, ... DESC
|
||||||
|
* <p>例: orderByDesc(true, "id")</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param column 字段
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children orderByDesc(boolean condition, R column) {
|
||||||
|
return orderBy(condition, false, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children orderByDesc(R column) {
|
||||||
|
return orderByDesc(true, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序:ORDER BY 字段, ... DESC
|
||||||
|
* <p>例: orderByDesc(true, Arrays.asList("id", "name"))</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param columns 字段列表
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children orderByDescStr(boolean condition, List<R> columns) {
|
||||||
|
return orderByStr(condition, false, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children orderByDescStr(List<R> columns) {
|
||||||
|
return orderByDescStr(true, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children orderByDesc(R column, R... columns) {
|
||||||
|
return orderByDesc(true, column, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序:ORDER BY 字段, ... DESC
|
||||||
|
*/
|
||||||
|
default Children orderByDesc(boolean condition, R column, R... columns) {
|
||||||
|
return orderBy(condition, false, column, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序:ORDER BY 字段, ...
|
||||||
|
* <p>例: orderBy(true, "id")</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param isAsc 是否是 ASC 排序
|
||||||
|
* @param column 单个字段
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children orderBy(boolean condition, boolean isAsc, R column);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序:ORDER BY 字段, ...
|
||||||
|
* <p>例: orderBy(true, Arrays.asList("id", "name"))</p>
|
||||||
|
*
|
||||||
|
* @param condition 执行条件
|
||||||
|
* @param isAsc 是否是 ASC 排序
|
||||||
|
* @param columns 字段列表
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
Children orderByStr(boolean condition, boolean isAsc, List<R> columns);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序:ORDER BY 字段, ...
|
||||||
|
*/
|
||||||
|
Children orderBy(boolean condition, boolean isAsc, R column, R... columns);
|
||||||
|
|
||||||
|
}
|
@ -13,6 +13,7 @@ import com.github.yulichang.wrapper.segments.*;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
@ -57,6 +58,16 @@ public interface Query<Children> extends Serializable {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
<E> Children select(SFunction<E, ?>... columns);
|
<E> Children select(SFunction<E, ?>... columns);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String 查询
|
||||||
|
*
|
||||||
|
* @param columns 列
|
||||||
|
*/
|
||||||
|
default Children select(String... columns) {
|
||||||
|
getSelectColum().addAll(Arrays.stream(columns).map(SelectString::new).collect(Collectors.toList()));
|
||||||
|
return getChildren();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 说明:
|
* 说明:
|
||||||
* 比如我们需要查询用户表有10个字段,然而我们只需要3个就够了,用mybatis-plus提供的select<p />
|
* 比如我们需要查询用户表有10个字段,然而我们只需要3个就够了,用mybatis-plus提供的select<p />
|
||||||
|
@ -4,6 +4,10 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
|||||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||||
import com.github.yulichang.toolkit.Constant;
|
import com.github.yulichang.toolkit.Constant;
|
||||||
import com.github.yulichang.toolkit.LambdaUtils;
|
import com.github.yulichang.toolkit.LambdaUtils;
|
||||||
|
import com.github.yulichang.wrapper.MPJAbstractLambdaWrapper;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yulichang
|
* @author yulichang
|
||||||
@ -40,7 +44,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
* @param clazz 关联实体类
|
* @param clazz 关联实体类
|
||||||
* @param function 条件
|
* @param function 条件
|
||||||
*/
|
*/
|
||||||
default <T> Children leftJoin(Class<T> clazz, WrapperFunction<Entity> function) {
|
default <T> Children leftJoin(Class<T> clazz, WrapperFunction<MPJAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
return join(Constant.LEFT_JOIN, clazz, function);
|
return join(Constant.LEFT_JOIN, clazz, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +55,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
* @param left 条件
|
* @param left 条件
|
||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(Constant.LEFT_JOIN, clazz, left, right, ext);
|
return join(Constant.LEFT_JOIN, clazz, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +65,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
* @param left 条件
|
* @param left 条件
|
||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children leftJoin(SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children leftJoin(SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(Constant.LEFT_JOIN, left, right, ext);
|
return join(Constant.LEFT_JOIN, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +77,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
* @param clazz 关联实体类
|
* @param clazz 关联实体类
|
||||||
* @param consumer 条件
|
* @param consumer 条件
|
||||||
*/
|
*/
|
||||||
default <T> Children leftJoin(Class<T> clazz, WrapperBiConsumer<Entity> consumer) {
|
default <T> Children leftJoin(Class<T> clazz, BiConsumer<MPJAbstractLambdaWrapper<Entity, ?>, MPJLambdaWrapper<Entity>> consumer) {
|
||||||
return join(Constant.LEFT_JOIN, clazz, consumer);
|
return join(Constant.LEFT_JOIN, clazz, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,28 +98,28 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children rightJoin(Class<T> clazz, WrapperFunction<Entity> function) {
|
default <T> Children rightJoin(Class<T> clazz, WrapperFunction<MPJAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
return join(Constant.RIGHT_JOIN, clazz, function);
|
return join(Constant.RIGHT_JOIN, clazz, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children rightJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(Constant.RIGHT_JOIN, clazz, left, right, ext);
|
return join(Constant.RIGHT_JOIN, clazz, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children rightJoin(SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(Constant.RIGHT_JOIN, left, right, ext);
|
return join(Constant.RIGHT_JOIN, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children rightJoin(Class<T> clazz, WrapperBiConsumer<Entity> consumer) {
|
default <T, X> Children rightJoin(Class<T> clazz, BiConsumer<MPJAbstractLambdaWrapper<Entity, ?>, MPJLambdaWrapper<Entity>> consumer) {
|
||||||
return join(Constant.RIGHT_JOIN, clazz, consumer);
|
return join(Constant.RIGHT_JOIN, clazz, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,28 +141,28 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children innerJoin(Class<T> clazz, WrapperFunction<Entity> function) {
|
default <T> Children innerJoin(Class<T> clazz, WrapperFunction<MPJAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
return join(Constant.INNER_JOIN, clazz, function);
|
return join(Constant.INNER_JOIN, clazz, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children innerJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children innerJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(Constant.INNER_JOIN, clazz, left, right, ext);
|
return join(Constant.INNER_JOIN, clazz, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children innerJoin(SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children innerJoin(SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(Constant.INNER_JOIN, left, right, ext);
|
return join(Constant.INNER_JOIN, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children innerJoin(Class<T> clazz, WrapperBiConsumer<Entity> consumer) {
|
default <T> Children innerJoin(Class<T> clazz, BiConsumer<MPJAbstractLambdaWrapper<Entity, ?>, MPJLambdaWrapper<Entity>> consumer) {
|
||||||
return join(Constant.INNER_JOIN, clazz, consumer);
|
return join(Constant.INNER_JOIN, clazz, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,28 +184,28 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children fullJoin(Class<T> clazz, WrapperFunction<Entity> function) {
|
default <T> Children fullJoin(Class<T> clazz, WrapperFunction<MPJAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
return join(Constant.FULL_JOIN, clazz, function);
|
return join(Constant.FULL_JOIN, clazz, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children fullJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children fullJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(Constant.FULL_JOIN, clazz, left, right, ext);
|
return join(Constant.FULL_JOIN, clazz, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T, X> Children fullJoin(SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children fullJoin(SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(Constant.FULL_JOIN, left, right, ext);
|
return join(Constant.FULL_JOIN, left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore 参考 left join
|
* ignore 参考 left join
|
||||||
*/
|
*/
|
||||||
default <T> Children fullJoin(Class<T> clazz, WrapperBiConsumer<Entity> consumer) {
|
default <T> Children fullJoin(Class<T> clazz, BiConsumer<MPJAbstractLambdaWrapper<Entity, ?>, MPJLambdaWrapper<Entity>> consumer) {
|
||||||
return join(Constant.FULL_JOIN, clazz, consumer);
|
return join(Constant.FULL_JOIN, clazz, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +242,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
* @param clazz 关联实体类
|
* @param clazz 关联实体类
|
||||||
* @param function 条件
|
* @param function 条件
|
||||||
*/
|
*/
|
||||||
default <T> Children join(String keyWord, Class<T> clazz, WrapperFunction<Entity> function) {
|
default <T> Children join(String keyWord, Class<T> clazz, WrapperFunction<MPJAbstractLambdaWrapper<Entity, ?>> function) {
|
||||||
return join(keyWord, clazz, (on, e) -> function.apply(on));
|
return join(keyWord, clazz, (on, e) -> function.apply(on));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,7 +253,7 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
* @param left 条件
|
* @param left 条件
|
||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children join(String keyWord, Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children join(String keyWord, Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(keyWord, clazz, (on, e) -> {
|
return join(keyWord, clazz, (on, e) -> {
|
||||||
on.eq(left, right);
|
on.eq(left, right);
|
||||||
ext.apply(e);
|
ext.apply(e);
|
||||||
@ -262,12 +266,12 @@ public interface QueryJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
|||||||
* @param left 条件
|
* @param left 条件
|
||||||
* @param right 条件
|
* @param right 条件
|
||||||
*/
|
*/
|
||||||
default <T, X> Children join(String keyWord, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<Entity> ext) {
|
default <T, X> Children join(String keyWord, SFunction<T, ?> left, SFunction<X, ?> right, WrapperFunction<MPJLambdaWrapper<Entity>> ext) {
|
||||||
return join(keyWord, LambdaUtils.getEntityClass(left), left, right, ext);
|
return join(keyWord, LambdaUtils.getEntityClass(left), left, right, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内部使用, 不建议直接调用
|
* 内部使用, 不建议直接调用
|
||||||
*/
|
*/
|
||||||
<T> Children join(String keyWord, Class<T> clazz, WrapperBiConsumer<Entity> consumer);
|
<T> Children join(String keyWord, Class<T> clazz, BiConsumer<MPJAbstractLambdaWrapper<Entity, ?>, MPJLambdaWrapper<Entity>> consumer);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package com.github.yulichang.wrapper.interfaces;
|
|
||||||
|
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface WrapperBiConsumer<T> {
|
|
||||||
|
|
||||||
void accept(MPJLambdaWrapper<T> on, MPJLambdaWrapper<T> ext);
|
|
||||||
}
|
|
@ -1,7 +1,5 @@
|
|||||||
package com.github.yulichang.wrapper.interfaces;
|
package com.github.yulichang.wrapper.interfaces;
|
||||||
|
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* on function
|
* on function
|
||||||
*
|
*
|
||||||
@ -11,5 +9,5 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface WrapperFunction<T> {
|
public interface WrapperFunction<T> {
|
||||||
|
|
||||||
MPJLambdaWrapper<T> apply(MPJLambdaWrapper<T> wrapper);
|
T apply(T wrapper);
|
||||||
}
|
}
|
||||||
|
@ -41,4 +41,6 @@ public interface Select {
|
|||||||
BaseFuncEnum getFunc();
|
BaseFuncEnum getFunc();
|
||||||
|
|
||||||
boolean isLabel();
|
boolean isLabel();
|
||||||
|
|
||||||
|
boolean isStr();
|
||||||
}
|
}
|
||||||
|
@ -92,4 +92,9 @@ public class SelectAlias implements Select {
|
|||||||
public boolean isLabel() {
|
public boolean isLabel() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStr() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,4 +98,9 @@ public class SelectFunc implements Select {
|
|||||||
public boolean isLabel() {
|
public boolean isLabel() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStr() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,4 +116,9 @@ public class SelectLabel implements Select {
|
|||||||
public boolean isLabel() {
|
public boolean isLabel() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStr() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,4 +93,9 @@ public class SelectNormal implements Select {
|
|||||||
public boolean isLabel() {
|
public boolean isLabel() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStr() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
package com.github.yulichang.wrapper.segments;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||||
|
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||||
|
import org.apache.ibatis.type.TypeHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义字符串列
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.3.12
|
||||||
|
*/
|
||||||
|
public class SelectString implements Select {
|
||||||
|
private final String column;
|
||||||
|
|
||||||
|
public SelectString(String column) {
|
||||||
|
this.column = column;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getClazz() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIndex() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPk() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumn() {
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getColumnType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTagColumn() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumProperty() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasTypeHandle() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TypeHandler<?> getTypeHandle() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHasAlias() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAlias() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableFieldInfo getTableFieldInfo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFunc() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseFuncEnum getFunc() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLabel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStr() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user