package com.cf.imes.framework.organ.core.rpc;

import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;

import static com.cf.imes.framework.web.core.util.WebFrameworkUtils.HEADER_ORGAN_ID;

/**
 * Tenant 的 RequestInterceptor 实现类：Feign 请求时，将 {@link OrganContextHolder} 设置到 header 中，继续透传给被调用的服务
 *
 * @author 晨丰科技
 */
public class OrganRequestInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        Long organId = OrganContextHolder.getOrganId();
        if (organId != null) {
            requestTemplate.header(HEADER_ORGAN_ID, String.valueOf(organId));
        }
    }

}
