package com.xisc.pm.infra.util;

import com.xisc.pm.infra.constant.Constants;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * xbus 请求头中塞入参数
 * @author yifan.deng@hand-china.com
 */
@Component
public class XbusRequestHeaderUtil {

    /**
     * xbus请求头封装
     * @param serviceId
     * @return
     */
    public static Map<String, String> getHeaders(String serviceId) {
        Map<String, String> headerMap = new HashMap<>(4);

        SimpleDateFormat sdf = new SimpleDateFormat(Constants.XbusCode.MSG_SEND_TIME_FORMAT);
        String msgSendTime = sdf.format(new Date());
        String sourceAppCode = serviceId.substring(0, 2);
        headerMap.put(Constants.XbusCode.SOURCE_APP_CODE, sourceAppCode);
        headerMap.put(Constants.XbusCode.PASSWORD, "");
        headerMap.put(Constants.XbusCode.SERVICE_ID, serviceId);
        headerMap.put(Constants.XbusCode.MSG_SEND_TIME, msgSendTime);
        return headerMap;
    }
}
