show.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package show
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-show/model/show"
  5. "go-common/library/log"
  6. )
  7. const (
  8. // real data
  9. _headSQL = "SELECT s.id,s.plat,s.title,s.type,s.param,s.style,s.rank,s.build,s.conditions,l.name FROM show_head AS s,language AS l WHERE l.id=s.lang_id ORDER BY rank DESC"
  10. _itemSQL = "SELECT sid,title,random,cover,param FROM show_item"
  11. // temp preview
  12. _headTmpSQL = "SELECT s.id,s.plat,s.title,s.type,s.param,s.style,s.rank,s.build,s.conditions,l.name FROM show_head_temp AS s,language AS l WHERE l.id=s.lang_id ORDER BY rank DESC"
  13. _itemTmpSQL = "SELECT sid,title,random,cover,param FROM show_item_temp"
  14. )
  15. // Heads get show head data.
  16. func (d *Dao) Heads(ctx context.Context) (heads map[int8][]*show.Head, err error) {
  17. rows, err := d.getHead.Query(ctx)
  18. if err != nil {
  19. log.Error("d.getItem.Query() error(%v)", err)
  20. return
  21. }
  22. defer rows.Close()
  23. heads = make(map[int8][]*show.Head, 20)
  24. for rows.Next() {
  25. h := &show.Head{}
  26. if err = rows.Scan(&h.ID, &h.Plat, &h.Title, &h.Type, &h.Param, &h.Style, &h.Rank, &h.Build, &h.Condition, &h.Language); err != nil {
  27. log.Error("row.Scan error(%v)", err)
  28. return nil, err
  29. }
  30. heads[h.Plat] = append(heads[h.Plat], h)
  31. }
  32. return
  33. }
  34. // Items get item data.
  35. func (d *Dao) Items(ctx context.Context) (items map[int][]*show.Item, err error) {
  36. rows, err := d.getItem.Query(ctx)
  37. if err != nil {
  38. log.Error("d.getItem.Query error(%v)", err)
  39. return nil, err
  40. }
  41. defer rows.Close()
  42. items = make(map[int][]*show.Item, 50)
  43. for rows.Next() {
  44. i := &show.Item{}
  45. if err = rows.Scan(&i.Sid, &i.Title, &i.Random, &i.Cover, &i.Param); err != nil {
  46. log.Error("row.Scan error(%v)", err)
  47. return nil, err
  48. }
  49. items[i.Sid] = append(items[i.Sid], i)
  50. }
  51. return
  52. }
  53. // TempHeads get show temp head data.
  54. func (d *Dao) TempHeads(ctx context.Context) (heads map[int8][]*show.Head, err error) {
  55. rows, err := d.db.Query(ctx, _headTmpSQL)
  56. if err != nil {
  57. log.Error("d.tempHeads.Query() error(%v)", err)
  58. return
  59. }
  60. defer rows.Close()
  61. heads = make(map[int8][]*show.Head, 20)
  62. for rows.Next() {
  63. h := &show.Head{}
  64. if err = rows.Scan(&h.ID, &h.Plat, &h.Title, &h.Type, &h.Param, &h.Style, &h.Rank, &h.Build, &h.Condition, &h.Language); err != nil {
  65. log.Error("row.Scan error(%v)", err)
  66. return nil, err
  67. }
  68. heads[h.Plat] = append(heads[h.Plat], h)
  69. }
  70. return
  71. }
  72. // TempItems get temp item data.
  73. func (d *Dao) TempItems(ctx context.Context) (items map[int][]*show.Item, err error) {
  74. rows, err := d.db.Query(ctx, _itemTmpSQL)
  75. if err != nil {
  76. log.Error("d.tempItems.Query error(%v)", err)
  77. return nil, err
  78. }
  79. defer rows.Close()
  80. items = make(map[int][]*show.Item, 50)
  81. for rows.Next() {
  82. i := &show.Item{}
  83. if err = rows.Scan(&i.Sid, &i.Title, &i.Random, &i.Cover, &i.Param); err != nil {
  84. log.Error("row.Scan error(%v)", err)
  85. return nil, err
  86. }
  87. items[i.Sid] = append(items[i.Sid], i)
  88. }
  89. return
  90. }