package com.yc.ship.module.trade.utils;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;

/**
 * &#064;Description ：交易相关编号生成组件
 * &#064;Author ：qsl
 * &#064;Date ：2025/6/11 10:33
 */
@Component
public class CommonUUCodeUtils {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 生成保险流水号
     *
     * @return  BX + yy-mm-dd + 6 位随机数，例如：ZD2201010001
     */
    public static String createInsuranceFlowNo(){
        Calendar calendar = Calendar.getInstance();
        String dateToString = DateUtil.format(calendar.getTime(), DatePattern.PURE_DATE_PATTERN);
        String date = dateToString.substring(2, 8);
        String currentTimeMillis = String.valueOf(System.currentTimeMillis());
        String substring = currentTimeMillis.substring(6);

        return "BX" + date + substring+RandomUtil.randomStringUpper(5);
    }


    /**
     * 生成自定义合同编号
     *
     * @return  HT + yymmdd + 8 位时间戳+4位随机数
     */
    public static String createERPContractId(){
        String dateToString = DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
        String date = dateToString.substring(2, 8);
        String currentTimeMillis = String.valueOf(System.currentTimeMillis());
        String substring = currentTimeMillis.substring(5);
        String randomString = RandomUtil.randomStringUpper(4);
        return "HT"+date+substring+ randomString;
    }
}
