package com.yeejoin.amos.patrol.utils;

import com.alibaba.ttl.TransmittableThreadLocal;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.context.RequestContextModel;

/**
 * @author Administrator
 *  主子线程见数据共享
 */
public class UserTransmittableUtils {
    private static final TransmittableThreadLocal<RequestContextModel> userLocal = new TransmittableThreadLocal<>();

    public static RequestContextModel getUser() {
        return userLocal.get();
    }

    public static void setUser(){
        RequestContextModel requestContextModel = new RequestContextModel();
        requestContextModel.setAgencyCode(RequestContext.getAgencyCode());
        requestContextModel.setAppKey(RequestContext.getAppKey());
        requestContextModel.setToken(RequestContext.getToken());
        requestContextModel.setProduct(RequestContext.getProduct());
        requestContextModel.setExcutedUserId(RequestContext.getExeUserId());
        userLocal.set(requestContextModel);
    }

    public static void clear(){
        userLocal.remove();
    }
}
