package com.ruoyi.xq.manager;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.xq.enums.common.OrderTypeEnum;


public class OrderNoUtil {

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

    public static String gen(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;
    }
}
