2023-12-21 22:17:40 +08:00
|
|
|
package idgenerator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/bwmarrin/snowflake"
|
|
|
|
)
|
|
|
|
|
|
|
|
// With default settings, this snowflake generator should be sufficiently fast enough
|
|
|
|
// on most systems to generate 4096 unique ID's per millisecond. This is the maximum
|
|
|
|
// that the snowflake ID format supports. That is, around 243-244 nanoseconds per operation.
|
|
|
|
|
|
|
|
// 业务node, node ∈ [0, 1023]
|
|
|
|
const (
|
|
|
|
NodeMin = 0 // 最小node 包括
|
|
|
|
NodeMax = 1023 // 最大node 包括
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ = iota
|
|
|
|
NodeMaterial // node 素材(商品)
|
|
|
|
NodeCatalog // node 分类
|
|
|
|
NodeOrder // node 订单
|
|
|
|
NodeBanner // node banner
|
|
|
|
NodeLogin // node login
|
|
|
|
NodeToken // node token
|
|
|
|
NodeAccount // node account
|
|
|
|
NodeVeriCode // node vericode
|
|
|
|
NodeMember // node 用户id
|
|
|
|
NodeProduct // node 商品
|
|
|
|
NodeMoment // node 动态
|
|
|
|
NodeFootPrint // node 足迹
|
|
|
|
NodeThumbsUp // node 点赞
|
|
|
|
NodeAccountRelation // node 用户关系
|
|
|
|
NodeStreamer // node 主播
|
|
|
|
NodeFeedback // node 意见反馈
|
|
|
|
NodeCallHistory // node 通话记录
|
|
|
|
NodeStreamerLink // node 主播链接
|
|
|
|
NodeUserWxAddCheck // node 用户微信添加审核
|
|
|
|
NodeRealNameAuthentication // node 实名认证
|
|
|
|
NodeContactCustomerService // node 联系客服
|
|
|
|
NodeImageAudit // node 图像审核
|
|
|
|
NodeCoinOrder // node 金币订单
|
|
|
|
NodeImageAuditTask // node 图像审核任务
|
|
|
|
NodeTextAudit // node 文字审核
|
|
|
|
NodeTextAuditTask // node 文字审核任务
|
2024-01-03 16:16:41 +08:00
|
|
|
NodeDailyStatement // node 每日报表表
|
2024-01-08 11:49:16 +08:00
|
|
|
NodeWithdrawOrderId // node 提现订单
|
2024-02-01 09:52:45 +08:00
|
|
|
NodeAppConfig // node 应用配置表
|
2024-03-07 01:18:41 +08:00
|
|
|
NodeAccountCancellation // node 账户注销
|
2024-03-13 20:35:18 +08:00
|
|
|
NodeWxpayRefund // node 微信支付退款
|
2023-12-21 22:17:40 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func GenIdInt64(node int64) (int64, error) {
|
|
|
|
if node < NodeMin || node > NodeMax {
|
|
|
|
return -1, errors.New("node number must include [0, 1023]")
|
|
|
|
}
|
|
|
|
|
|
|
|
n, err := snowflake.NewNode(node)
|
|
|
|
if err != nil {
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
return n.Generate().Int64(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenIdString(node int64) (string, error) {
|
|
|
|
if node < NodeMin || node > NodeMax {
|
|
|
|
return "", errors.New("node number must include [0, 1023]")
|
|
|
|
}
|
|
|
|
|
|
|
|
n, err := snowflake.NewNode(node)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return n.Generate().String(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 商品
|
|
|
|
func GenProductId() string {
|
|
|
|
id, _ := GenIdString(NodeProduct)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// 订单
|
|
|
|
func GenOrderId() string {
|
|
|
|
id, _ := GenIdString(NodeOrder)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// 金币订单
|
|
|
|
func GenCoinOrderId() string {
|
|
|
|
id, _ := GenIdString(NodeCoinOrder)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// banner
|
|
|
|
func GenBannerId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeBanner)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// login
|
|
|
|
func GenLoginId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeLogin)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// token
|
|
|
|
func GenTokenId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeToken)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// account
|
|
|
|
func GenAccountId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeAccount)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// vericode
|
|
|
|
func GenVeriCodeId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeVeriCode)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// catalog
|
|
|
|
func GenCatalogId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeCatalog)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// moment
|
|
|
|
func GenMomentId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeMoment)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// footprint
|
|
|
|
func GenFootPrintId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeFootPrint)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// thumbs_up
|
|
|
|
func GenThumbsUpId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeThumbsUp)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// account_relation
|
|
|
|
func GenAccountRelationId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeAccountRelation)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// streamer
|
|
|
|
func GenStreamerId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeStreamer)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// feedback
|
|
|
|
func GenFeedbackId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeFeedback)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// callhistory
|
|
|
|
func GenCallHistoryId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeCallHistory)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// streamerlink
|
|
|
|
func GenStreamerLinkId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeStreamerLink)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// userwxaddcheck
|
|
|
|
func GenUserWxAddCheckId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeUserWxAddCheck)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// realname_authentication
|
|
|
|
func GenRealNameAuthenticationId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeRealNameAuthentication)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// contact_customer_service
|
|
|
|
func GenContactCustomerServiceId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeContactCustomerService)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
2024-01-03 16:16:41 +08:00
|
|
|
// daily_statement
|
|
|
|
func GenDailyStatementId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeDailyStatement)
|
|
|
|
return id
|
|
|
|
}
|
2024-01-08 11:49:16 +08:00
|
|
|
|
|
|
|
// withdraw_order
|
|
|
|
func GenWithdrawOrderId() string {
|
|
|
|
id, _ := GenIdString(NodeWithdrawOrderId)
|
|
|
|
return id
|
|
|
|
}
|
2024-02-01 09:52:45 +08:00
|
|
|
|
|
|
|
// app_config
|
|
|
|
func GenAppConfigId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeAppConfig)
|
|
|
|
return id
|
|
|
|
}
|
2024-03-07 01:18:41 +08:00
|
|
|
|
|
|
|
// account_cancellation
|
|
|
|
func GenAccountCancellationId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeAccountCancellation)
|
|
|
|
return id
|
|
|
|
}
|
2024-03-16 22:36:05 +08:00
|
|
|
|
2024-03-13 20:35:18 +08:00
|
|
|
// wxpay refund
|
|
|
|
func GenWxpayRefundId() string {
|
|
|
|
id, _ := GenIdString(NodeWxpayRefund)
|
|
|
|
return id
|
|
|
|
}
|