|
@@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 拓展 MyBatis Plus QueryWrapper 类,主要增加如下功能:
|
|
@@ -32,6 +34,24 @@ public class LambdaQueryWrapperX<T> extends LambdaQueryWrapper<T> {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public LambdaQueryWrapperX<T> inIfPresent(SFunction<T, ?> column, List<?> values) {
|
|
|
+ if (ObjectUtil.isAllNotEmpty(values) && !ArrayUtil.isEmpty(values)) {
|
|
|
+ List<List<?>> newList = splitList(values, 900);
|
|
|
+ if(newList.size() == 1){
|
|
|
+ return (LambdaQueryWrapperX<T>) super.in(column, values);
|
|
|
+ } else {
|
|
|
+ return (LambdaQueryWrapperX<T>) super.and(tLambdaQueryWrapper -> {
|
|
|
+ tLambdaQueryWrapper.in(column, newList.get(0));
|
|
|
+ newList.remove(0);
|
|
|
+ for (List<?> objects : newList){
|
|
|
+ tLambdaQueryWrapper.or().in(column, objects);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
public LambdaQueryWrapperX<T> inIfPresent(SFunction<T, ?> column, Object... values) {
|
|
|
if (ObjectUtil.isAllNotEmpty(values) && !ArrayUtil.isEmpty(values)) {
|
|
|
return (LambdaQueryWrapperX<T>) super.in(column, values);
|
|
@@ -132,4 +152,18 @@ public class LambdaQueryWrapperX<T> extends LambdaQueryWrapper<T> {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public static <F> List<List<?>> splitList(List<?> list, int groupSize) {
|
|
|
+ int length = list.size();
|
|
|
+ // 计算可以分成多少组
|
|
|
+ int num = (length + groupSize - 1) / groupSize;
|
|
|
+ List<List<?>> newList = new ArrayList<>(num);
|
|
|
+ for (int i = 0; i < num; i++) {
|
|
|
+ // 开始位置
|
|
|
+ int fromIndex = i * groupSize;
|
|
|
+ // 结束位置
|
|
|
+ int toIndex = Math.min((i + 1) * groupSize, length);
|
|
|
+ newList.add(list.subList(fromIndex, toIndex));
|
|
|
+ }
|
|
|
+ return newList;
|
|
|
+ }
|
|
|
}
|