package com.glxp.mipsdl.client;

import com.glxp.mipsdl.util.DictUtl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 接口封装，用于获取当前医院的实现，实现controller层通过base接口直接调用对应方法
 */
@Slf4j
@Component
public class ClientProcessor implements ApplicationContextAware {

    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ClientProcessor.context = applicationContext;
    }

    /**
     * 获取当前医院的HttpClient接口实现
     *
     * @return
     */
    public static BaseHttpClient getHttpClient() {
        BaseHttpClient baseHttpClient = context.getBean(DictUtl.CURRENT_HOSP_CODE + "HttpClient", BaseHttpClient.class);
        return baseHttpClient;
    }

    /**
     * 获取当前医院的FileClient接口实现
     *
     * @return
     */
    public static BaseFileClient getFileClient() {
        BaseFileClient baseFileClient = context.getBean(DictUtl.CURRENT_HOSP_CODE + "FileClient", BaseFileClient.class);
        return baseFileClient;
    }

}
