package snowflakehelper

// 雪花算法用于生成订单号

import (
	"fmt"
	"go-admin/config"

	"github.com/bwmarrin/snowflake"
)

var (
	snowNode *snowflake.Node
)

func init() {
	snowflake.Epoch = 1649212361224 // time.Now().UnixMilli()
	// nodeId := utility.StringAsInt64()
	node, err := snowflake.NewNode(config.ExtConfig.ServiceId)
	if err != nil {
		fmt.Println("snowflake.NewNode err:", err)
		return
	}
	snowNode = node
}

// GetOrderId 生成int64订单id
func GetOrderId() int64 {
	return snowNode.Generate().Int64()
}
