gid_map.go 836 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package model
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. // gid map
  7. const (
  8. TypeMatch = 1
  9. TypeSeason = 2
  10. TypeContest = 3
  11. TypeTeam = 4
  12. TypeArc = 5
  13. _gidMapInsertSQL = "INSERT INTO es_gid_map(`type`,`oid`,`gid`) VALUES %s"
  14. )
  15. // GIDMap .
  16. type GIDMap struct {
  17. ID int64 `json:"id"`
  18. Type int `json:"type"`
  19. Oid int64 `json:"oid"`
  20. Gid int64 `json:"gid"`
  21. IsDeleted int `json:"is_deleted"`
  22. }
  23. // TableName .
  24. func (g GIDMap) TableName() string {
  25. return "es_gid_map"
  26. }
  27. // GidBatchAddSQL .
  28. func GidBatchAddSQL(gidMap []*GIDMap) string {
  29. if len(gidMap) == 0 {
  30. return ""
  31. }
  32. var rowStrings []string
  33. for _, v := range gidMap {
  34. rowStrings = append(rowStrings, fmt.Sprintf("(%d,%d,%d)", v.Type, v.Oid, v.Gid))
  35. }
  36. return fmt.Sprintf(_gidMapInsertSQL, strings.Join(rowStrings, ","))
  37. }