package <%= packageName %>.util;

<%_ if (ormTool === 'mybatis') { _%>
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.function.Consumer;
<%_ } else { _%>
import org.springframework.data.jpa.domain.Specification;
<%_ } _%>

public class CriteriaUtil {
<%_ if (ormTool === 'mybatis') { _%>

    public static  <ENTITY>  QueryWrapper<ENTITY> build(Boolean useOr, QueryWrapper<ENTITY> queryWrapper, Consumer<QueryWrapper<ENTITY>> consumer) {
        if (useOr) {
            return queryWrapper.or(true,consumer);
        } else {
            return queryWrapper.and(true,consumer);
        }
    }
<%_ } else { _%>

    public static <ENTITY> Specification<ENTITY> build(Boolean useOr, Specification<ENTITY> specification, Specification<ENTITY> field) {
        if (useOr) {
            return specification.or(field);
        } else {
            return specification.and(field);
        }
    }
<%_ } _%>

}
