package com.persagy.dmp.file.context;

import com.persagy.dmp.common.context.AppContext;
import com.persagy.dmp.common.helper.SpringHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.stereotype.Component;

/**
 * 默认应用上下文
 * @author Charlie Yu
 * @version 1.0 2021-03-04
 */
@Component
public class OldFileAppContext {

    /** 线程级的上下文 */
    private ThreadLocal<OldFileContext> context = new ThreadLocal<>();
    /***
     * Description: 获取文件上下文
     * @return : com.persagy.dmp.file.context.OldFileContext
     * @author : lijie
     * @date :2021/11/18 18:36
     * Update By lijie 2021/11/18 18:36
     */
    public static OldFileContext getContext() {
        OldFileAppContext fileAppContext = SpringHelper.getBean(OldFileAppContext.class);
        OldFileContext c = fileAppContext.context.get();
        if(c == null){
            c = new OldFileContext();
            fileAppContext.context.set(c);
        }
        return c;
    }
    /***
     * Description: 移除文件上下文
     * @return : com.persagy.dmp.file.context.OldFileContext
     * @author : lijie
     * @date :2021/11/18 18:36
     * Update By lijie 2021/11/18 18:36
     */
    public static void unloadContext() {
        OldFileAppContext fileAppContext = SpringHelper.getBean(OldFileAppContext.class);
        fileAppContext.context.remove();
    }
}
