You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
995 B
42 lines
995 B
|
1 year ago
|
package generalmethod
|
||
|
|
|
||
|
|
import (
|
||
|
|
"appNewPlatform/utils/snowflake"
|
||
|
|
"crypto/rand"
|
||
|
|
"fmt"
|
||
|
|
"math/big"
|
||
|
|
"strconv"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
// 初始化map(泛型)
|
||
|
|
func MapOut[T GenericityVariable]() (data map[T]interface{}) {
|
||
|
|
data = make(map[T]interface{}) //必可不少,分配内存
|
||
|
|
return data
|
||
|
|
}
|
||
|
|
|
||
|
|
// 编号,纯数字
|
||
|
|
func TableNumber(class ...string) (number int64) {
|
||
|
|
result, _ := rand.Int(rand.Reader, big.NewInt(8999))
|
||
|
|
numberTeam := result.Int64() + 1000
|
||
|
|
numberStr := fmt.Sprintf("%v%v", time.Now().Unix(), numberTeam)
|
||
|
|
if len(class) > 0 {
|
||
|
|
resultLong, _ := rand.Int(rand.Reader, big.NewInt(8999999))
|
||
|
|
numberTeamLong := resultLong.Int64() + 1000000
|
||
|
|
numberStr = fmt.Sprintf("%v%v", time.Now().Unix(), numberTeamLong)
|
||
|
|
}
|
||
|
|
number, _ = strconv.ParseInt(numberStr, 10, 64)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取UUID
|
||
|
|
func GetUUid(workId int64) (uuId int64) {
|
||
|
|
snowflakeId, snowflakeErr := snowflake.NewWorker(workId)
|
||
|
|
if snowflakeErr != nil {
|
||
|
|
uuId = TableNumber()
|
||
|
|
} else {
|
||
|
|
uuId = snowflakeId.GetId()
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|