tree.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package model
  2. import (
  3. "fmt"
  4. "go-common/library/xstr"
  5. )
  6. const _treeEditSQL = "UPDATE es_matchs_tree SET mid = CASE %s END WHERE id IN (%s)"
  7. // TreeListParam .
  8. type TreeListParam struct {
  9. MadID int64 `form:"mad_id" validate:"required"`
  10. }
  11. // TreeEditParam .
  12. type TreeEditParam struct {
  13. MadID int64 `form:"mad_id" validate:"required"`
  14. Nodes string `form:"nodes" validate:"required"`
  15. }
  16. // TreeDelParam .
  17. type TreeDelParam struct {
  18. MadID int64 `form:"mad_id" validate:"required"`
  19. IDs string `form:"ids" validate:"required"`
  20. }
  21. // Tree .
  22. type Tree struct {
  23. ID int64 `json:"id" form:"id"`
  24. MaID int64 `json:"ma_id,omitempty" form:"ma_id" validate:"required"`
  25. MadID int64 `json:"mad_id,omitempty" form:"mad_id" validate:"required"`
  26. Pid int64 `json:"pid" form:"pid"`
  27. RootID int64 `json:"root_id" form:"root_id"`
  28. GameRank int64 `json:"game_rank,omitempty" form:"game_rank" validate:"required"`
  29. Mid int64 `json:"mid" form:"mid"`
  30. IsDeleted int `json:"is_deleted,omitempty" form:"is_deleted"`
  31. }
  32. // TreeList .
  33. type TreeList struct {
  34. *Tree
  35. *ContestInfo
  36. }
  37. // TreeDetailList .
  38. type TreeDetailList struct {
  39. Detail *MatchDetail `json:"detail"`
  40. Tree [][]*TreeList `json:"tree"`
  41. }
  42. // TableName .
  43. func (t Tree) TableName() string {
  44. return "es_matchs_tree"
  45. }
  46. // BatchEditTreeSQL .
  47. func BatchEditTreeSQL(nodes map[int64]int64) string {
  48. if len(nodes) == 0 {
  49. return ""
  50. }
  51. var (
  52. caseStr string
  53. ids []int64
  54. )
  55. for id, mid := range nodes {
  56. caseStr = fmt.Sprintf("%s WHEN id = %d THEN %d", caseStr, id, mid)
  57. ids = append(ids, id)
  58. }
  59. return fmt.Sprintf(_treeEditSQL, caseStr, xstr.JoinInts(ids))
  60. }