package com.sifang.modules.partner.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @title: ClientReqIdUtils
 * @Author Tan
 * @Date: 2024/7/11 15:11
 * @Version 1.0
 */
public class ClientReqIdUtils {

    private static Logger logger = LoggerFactory.getLogger(PartnerApiUtils.class);

    public static String getClientReqId(String clientId){
        String clientReqId = "";

        // 创建一个Date对象，表示当前时间
        Date currentDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String formattedDate = sdf.format(currentDate);

        // 创建一个SimpleDateFormat对象，指定格式为HHmmssSSS
        SimpleDateFormat formatter = new SimpleDateFormat("HHmmssSSS");
        String formattedTime = formatter.format(currentDate);

        //创建两个随机数
        Random random = new Random();
        int firstNumber = random.nextInt(100); // 生成一个0到99之间的随机整数
        int secondNumber = random.nextInt(100);

        // 将整数转换为字符串
        String firstNumberStr = String.format("%02d", firstNumber);
        String secondNumberStr = String.format("%02d", secondNumber);

        clientReqId = formattedDate+clientId+firstNumberStr+"00"+formattedTime+secondNumberStr;
        return clientReqId;
    }

}