uuid.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package utils
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "time"
  6. )
  7. var GetUuid = getUuid{}
  8. type getUuid struct {
  9. }
  10. func (*getUuid) GetTalentId() string {
  11. now := time.Now()
  12. nowStr := time.Time.String(now)
  13. str1 := nowStr[11:13] + nowStr[14:16]
  14. str2 := fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
  15. tid := "2" + str1 + str2
  16. return tid
  17. }
  18. func (*getUuid) GetTaskId(ProjectId string, EnterpriseId string, TalentId string) string {
  19. str1 := ProjectId[len(ProjectId)-2:] + EnterpriseId[len(EnterpriseId)-1:] + TalentId[len(TalentId)-2:]
  20. str2 := fmt.Sprintf("%05v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(100000))
  21. tid := str1 + str2
  22. return tid
  23. }
  24. func (*getUuid) GetTeamId(ProjectId string, SelectionId string, TalentId string) string {
  25. str0 := ProjectId + SelectionId
  26. str1 := str0[len(str0)-3:] + TalentId[len(TalentId)-2:]
  27. str2 := fmt.Sprintf("%05v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(100000))
  28. tid := str1 + str2
  29. return tid
  30. }
  31. func (*getUuid) GetRandomString(l int) string {
  32. str := "0123456789"
  33. bytes := []byte(str)
  34. var result []byte
  35. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  36. for i := 0; i < l; i++ {
  37. result = append(result, bytes[r.Intn(len(bytes))])
  38. }
  39. return string(result)
  40. }