package org.springblade.thirdparty.ocr.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springblade.core.log.utils.LogTraceUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.thirdparty.ocr.constant.OCRConstant;

import java.util.Date;

/**
 * @author bfhuange
 * @since 2024/12/26
 */
@Slf4j
@AllArgsConstructor
public class OCRRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        // 请求时间
        template.header(OCRConstant.REQUEST_HEADER_TIME, DateUtil.formatDateTime(new Date()));
        String traceId = MDC.get("traceId");
        if (StringUtil.isBlank(traceId)) {
            traceId = LogTraceUtil.getTraceId();
        }
        // traceId
        template.header(OCRConstant.REQUEST_HEADER_TRACE_ID, traceId);
    }
}
