package org.jeecg.modules.common.util;

import com.alibaba.ttl.TransmittableThreadLocal;
import org.jeecg.modules.common.entity.CsHttpLog;

/**
 * @description:
 * @author: niugeng
 * @create: 2023-12-05 19:49
 **/
public class ThreadLocalUtil {

    /**
     * 记录日志操作，集中打印
     */
    private static ThreadLocal<CsHttpLog> tlog = new ThreadLocal<>();

    private static TransmittableThreadLocal<String> tStr = new TransmittableThreadLocal<>();

    /**
     * 获取
     *
     * @return {@link CsHttpLog}
     */
    public static CsHttpLog getTlog() {
        if (tlog !=null){
            return tlog.get();
        }else {
            return new CsHttpLog();
        }

    }

    /**
     * 赋值
     *
     */
    public static void settlog(CsHttpLog log) {
        if (tlog!=null){
            tlog.set(log);
        }

    }

    /**
     * 移除 threadlocal
     */
    public static void removeTlog() {
        if (tlog!=null){
            tlog.remove();
        }
    }


    /**
     * 获取
     *
     * @return {@link CsHttpLog}
     */
    public static String getTStr() {
        if (tStr !=null){
            return tStr.get();
        }else {
            return "";
        }

    }

    /**
     * 赋值
     *
     */
    public static void setStr(String type) {
        if (tStr!=null){
            tStr.set(type);
        }

    }

    /**
     * 移除 threadlocal
     */
    public static void removeTStr() {
        if (tStr!=null){
            tStr.remove();
        }
    }

}
