package com.dhcc.finance.util;
import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.dhcc.common.RestStatus;
import com.dhcc.common.constant.SysConstants;
import com.dhcc.common.constant.enums.DatacenterIdEnum;
import com.dhcc.common.model.CurrencyMeta;
import com.dhcc.common.util.SnowflakeIdWorker;
import com.dhcc.finance.config.DhccCustomPropertiesConfig;

import brave.Tracer;

/**
 * 功能描述：meytaData追踪工具类方法
 * @author haozg
 * @date 2019年1月20日 下午4:15:15
 * @修改日志：
 */
@Component
public class MetaDataUtil {
	
    @Autowired
    private  DhccCustomPropertiesConfig dhccCustomPropertiesConfig;
    
    //配置类
    private static DhccCustomPropertiesConfig metaconfigProperties;

    //初始化配置类进行静态变量复制
    @PostConstruct
    public void init() {
        metaconfigProperties = this.dhccCustomPropertiesConfig;
    }
    
    /**
                *功能描述：获取公共metaData
     * @param tracer
     * @param restStatus
     * @return CurrencyMeta
     * @author haozg
     * @date 2019年1月20日 下午5:00:53
     * @修改日志：
     */
    public static CurrencyMeta getMeta(Tracer tracer, RestStatus restStatus) {
        CurrencyMeta meta = new CurrencyMeta();
        meta.setSerialNo(SnowflakeIdWorker.getInstance().nextIdString());
        meta.setStatusCode(restStatus == null ?String.valueOf(HttpStatus.OK.value()) : restStatus.statusCode());
        meta.setMessage(restStatus == null ?SysConstants.DEFAULT_MESSAGE.BUSINESS_SUCCESS: restStatus.message());
        meta.setTraceId(tracer.currentSpan().context().traceIdString());
        return meta;
    }
}