package com.cool.store.utils;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;

import java.util.UUID;

/**
 * @Author suzhuhong
 * @Date 2025/10/15 17:32
 * @Version 1.0
 */
public class MDCUtils {
    public MDCUtils() {
    }

    public static void putIfAbsent(String key, String value) {
        String k = MDC.get(key);
        if (StringUtils.isBlank(value)) {
            value = UUID.randomUUID().toString().replace("-", "");
        }

        if (StringUtils.isBlank(k)) {
            MDC.put(key, value);
        }

    }

    public static void put(String key, String value) {
        MDC.put(key, value);
    }

    public static void put(String key) {
        MDC.put(key, UUID.randomUUID().toString().replace("-", ""));
    }

}
