package com.cf.imes.framework.mybatis.core.query;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;

/**
 * LambdaUpdateWrapper拓展
 *
 * @author Gqr
 * @since 2025/1/22 15:58
 */
public class LambdaUpdateWrapperX<T> extends LambdaUpdateWrapper<T> {
    public LambdaUpdateWrapperX<T> eqIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (LambdaUpdateWrapperX<T>) super.eq(column, val);
        }
        return this;
    }

    @Override
    public LambdaUpdateWrapperX<T> eq(SFunction<T, ?> column, Object val) {
        super.eq(column, val);
        return this;
    }

    /**
     * 当条件存在时set
     */
    public LambdaUpdateWrapperX<T> setIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (LambdaUpdateWrapperX<T>) super.set(column, val);
        }
        return this;
    }
}
