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-13 20:35:18 +08:00
|
|
|
NodeWxpayRefund // node 微信支付退款
|
2024-03-07 01:18:41 +08:00
|
|
|
NodeAccountCancellation // node 账户注销
|
2024-03-21 23:26:23 +08:00
|
|
|
NodeZoneMomentThumbsUp // node 私密圈动态点赞
|
2024-04-04 20:48:42 +08:00
|
|
|
NodeZoneSession // node 空间对话表
|
2024-04-08 20:05:13 +08:00
|
|
|
NodeZoneThirdPartner // node 空间代运营表
|
2024-05-15 09:58:45 +08:00
|
|
|
NodeDailyStatementZoneInfo // node 空间相关每日报表
|
2024-05-29 10:56:52 +08:00
|
|
|
NodeYeepayRefund // node 易宝支付退款
|
2024-06-15 13:41:03 +08:00
|
|
|
NodeWorkerId // node 用户职业者id映射表
|
2024-06-19 13:58:47 +08:00
|
|
|
NodeSingleDistributeHis // 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-13 20:35:18 +08:00
|
|
|
|
|
|
|
// wxpay refund
|
|
|
|
func GenWxpayRefundId() string {
|
|
|
|
id, _ := GenIdString(NodeWxpayRefund)
|
|
|
|
return id
|
|
|
|
}
|
2024-03-19 00:01:43 +08:00
|
|
|
|
2024-03-07 01:18:41 +08:00
|
|
|
// account_cancellation
|
|
|
|
func GenAccountCancellationId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeAccountCancellation)
|
|
|
|
return id
|
|
|
|
}
|
2024-03-21 23:26:23 +08:00
|
|
|
|
|
|
|
// zone_moment_thumbs_up
|
|
|
|
func GenZoneMomentThumbsUpId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeZoneMomentThumbsUp)
|
|
|
|
return id
|
|
|
|
}
|
2024-04-04 20:48:42 +08:00
|
|
|
|
|
|
|
// zonesession
|
|
|
|
func GenZoneSessionId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeZoneSession)
|
|
|
|
return id
|
|
|
|
}
|
2024-04-08 20:05:13 +08:00
|
|
|
|
|
|
|
// zone_third_partner
|
|
|
|
func GenZoneThirdPartnerId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeZoneThirdPartner)
|
|
|
|
return id
|
|
|
|
}
|
2024-05-15 09:58:45 +08:00
|
|
|
|
|
|
|
// daily_statement_zone_info
|
|
|
|
func GenDailyStatementZoneInfoId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeDailyStatementZoneInfo)
|
|
|
|
return id
|
|
|
|
}
|
2024-06-15 13:41:03 +08:00
|
|
|
|
2024-05-29 10:56:52 +08:00
|
|
|
// yeepay refund
|
|
|
|
func GenYeepayRefundId() string {
|
|
|
|
id, _ := GenIdString(NodeYeepayRefund)
|
|
|
|
return id
|
|
|
|
}
|
2024-06-28 14:35:10 +08:00
|
|
|
|
2024-06-15 13:41:03 +08:00
|
|
|
// worker_id
|
|
|
|
func GenWorkerIdId() int64 {
|
|
|
|
id, _ := GenIdInt64(NodeWorkerId)
|
|
|
|
return id
|
|
|
|
}
|
2024-06-19 13:58:47 +08:00
|
|
|
|
|
|
|
// single_distribute_his
|
|
|
|
func GenSingleDistributeHisId() string {
|
|
|
|
id, _ := GenIdString(NodeSingleDistributeHis)
|
|
|
|
return id
|
|
|
|
}
|