package com.dayou.utils;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;
import java.util.function.Predicate;

/**
 * 类说明：
 *
 * @author: wucl
 * @since: 2024/4/26
 * created with IntelliJ IDEA.
 */
public class MybatisPlusUtils {

    /**
     * 只返回 指定字段
     */
    public static <T> LambdaQueryWrapper<T>  fieldValues(List<String> fieldValues, LambdaQueryWrapper<T> queryWrapper, Class<T> aClass) {
            if (CollectionUtil.isNotEmpty(fieldValues)){
                Predicate<TableFieldInfo> predicate = null;
                for (String field : fieldValues) {
                    predicate = predicate == null ? p -> p.getColumn().equals(field) : predicate.or(p -> p.getColumn().equals(field));
                }
                return queryWrapper.select(aClass, predicate);
            }
            return null;
    }
}
