package com.ruoyi.common.core;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
import com.baomidou.mybatisplus.core.enums.SqlLike;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author LinQiLong
 * @date 2022/5/31 14:19
 */
public class CustomQueryWrapper<T> extends QueryWrapper<T> {
    @Override
    protected QueryWrapper<T> addCondition(boolean condition, String column, SqlKeyword sqlKeyword, Object val) {
        if (Objects.isNull(val)) {
            condition = false;
        }
        if (val instanceof String) {
            if (StringUtils.isBlank((CharSequence) val)) {
                condition = false;
            }
        }

        return super.addCondition(condition, column, sqlKeyword, val);
    }

    @Override
    protected QueryWrapper<T> likeValue(boolean condition, SqlKeyword keyword, String column, Object val, SqlLike sqlLike) {
        if (Objects.isNull(val)) {
            condition = false;
        }
        if (val instanceof String) {
            if (StringUtils.isBlank((CharSequence) val)) {
                condition = false;
            }
        }
        return super.likeValue(condition, keyword, column, val, sqlLike);
    }
}
