package com.ruoyi.cai.pay;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;


public class OrderNoUtil {

    public static final Snowflake snowflake = IdUtil.getSnowflake(1, 1);

    public static String createOrderNo(OrderTypeEnum sub){
        return sub.getType() + snowflake.nextIdStr();
    }

    public static OrderTypeEnum getType(String orderNo){
        if(orderNo == null){
            return null;
        }
        OrderTypeEnum[] values = OrderTypeEnum.values();
        for (OrderTypeEnum value : values) {
            if(orderNo.startsWith(value.getType())){
                return value;
            }
        }
        return null;
    }
}
