package cn.sh.stc.sict.cloud.common.data.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

public class HySearchWrapperUtil {

    public static void setWrapper(LambdaQueryWrapper wrapper, String param) {
        StringBuilder sb = new StringBuilder();
        if (StrUtil.isNotBlank(param) && JSONUtil.isJsonObj(param)) {
            sb.append("where 1 = 1");
            JSONObject json = JSONUtil.parseObj(param);
            json.forEach((k, v) -> {
                sb.append(" and ");
                sb.append(k);
                sb.append(" like '%");
                sb.append(v);
                sb.append("%'");
            });
            wrapper.last(sb.toString());
        }
    }
}
