package com.sckw.order.config;


import com.sckw.core.model.constant.Global;
import feign.RequestInterceptor;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


/**
 * @Author: tangyishan
 * @CreateTime: 2025-12-12  16:10
 * @Description: feign远程调用配置
 */
@Configuration
public class FeignConfig {

    @Bean
    public RequestInterceptor requestInterceptor() {
        return requestTemplate -> {
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            if (attributes != null) {
                HttpServletRequest request = attributes.getRequest();
                String userInfoStrEncode = request.getHeader(Global.USER_INFO_STR_ENCODE);
                String entInfoStrEncode = request.getHeader(Global.ENT_INFO_STR_ENCODE);
                requestTemplate.header(Global.USER_INFO_STR_ENCODE, userInfoStrEncode);
                requestTemplate.header(Global.ENT_INFO_STR_ENCODE, entInfoStrEncode);
            }
        };
    }

}
