package com.ejlchina.searcher.operator;

import com.ejlchina.searcher.FieldOp;
import com.ejlchina.searcher.SqlWrapper;
import com.ejlchina.searcher.implement.DialectWrapper;
import com.ejlchina.searcher.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

import static com.ejlchina.searcher.util.ObjectUtils.firstNotNull;

/**
 * 包含运算符
 * @author Troy.Zhou @ 2022-01-19
 * @since v3.3.0
 */
public class Contain extends DialectWrapper implements FieldOp {

    @Override
    public String name() {
        return "Contain";
    }

    @Override
    public boolean isNamed(String name) {
        return "ct".equals(name) || "in".equals(name) || "Contain".equals(name) || "Include".equals(name);
    }

    @Override
    public boolean lonely() {
        return false;
    }

    @Override
    public List<Object> operate(StringBuilder sqlBuilder, OpPara opPara) {
        SqlWrapper<Object> fieldSql = opPara.getFieldSql();
        Object[] values = opPara.getValues();
        if (opPara.isIgnoreCase()) {
            toUpperCase(sqlBuilder, fieldSql.getSql());
            ObjectUtils.upperCase(values);
        } else {
            sqlBuilder.append(fieldSql.getSql());
        }
        sqlBuilder.append(" like ?");
        List<Object> params = new ArrayList<>(fieldSql.getParas());
        params.add("%" + firstNotNull(values) + "%");
        return params;
    }

}
@@ -214,16 +214,73 @@
 ctUtils;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -527,16 +527,87 @@
 ldOp %7B%0A%0A
+    static final Logger log = LoggerFactory.getLogger(Contain.class);%0A%0A
     @Ove
@@ -740,18 +740,15 @@
     
-return %22ct
+if (%22in
 %22.eq
@@ -761,15 +761,157 @@
 ame)
- %7C%7C %22in
+) %7B%0A            log.warn(%22FieldOp 'in' is deprecated from v3.2.0, please use 'ct' instead.%22);%0A            return true;%0A        %7D%0A        if (%22Include
 %22.eq
@@ -924,20 +924,165 @@
 ame)
- %7C%7C %22Contain
+) %7B%0A            log.warn(%22FieldOp 'Include' is deprecated from v3.2.0, please use 'Contain' instead.%22);%0A            return true;%0A        %7D%0A        return %22ct
 %22.eq
@@ -1096,23 +1096,23 @@
 me) %7C%7C %22
-Include
+Contain
 %22.equals

优化 Contain 运算符，当用户使用 in / Include 运算符时，输出警告日志