package com.yeejoin.amos.boot.module.jczs.biz.utils;

import java.util.Map;
import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: xl
 * @Description:
 * @Date: 2022/8/4 9:08
 */
public class StringUtils {

    public static StringJoiner getWhereSql(String operator, Map<String, String> map){
        StringJoiner stringJoiner = new StringJoiner(" " + operator +" ");
        for (Map.Entry entry :map.entrySet()) {
            stringJoiner.add(entry.getKey() + "=" + str2sqlValue(entry.getValue().toString()));
        }
        return stringJoiner;
    }

    public static String str2sqlValue(String str){
        return "'" + str + "'";
    }

    public static String getStrByPattern(String str, Pattern reg){
        Matcher mat = reg.matcher(str);
        while (mat.find()) {
            return mat.group(0);
        }
        return "";
    }
}
