tab.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package tab
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/app-channel/conf"
  6. "go-common/app/interface/main/app-channel/model/tab"
  7. "go-common/library/database/sql"
  8. )
  9. const (
  10. _getAllMenuSQL = `SELECT ct.id,ct.tag_id,ct.tab_id,ct.title,ct.priority,a.name from channel_tab AS ct,app_active AS a
  11. WHERE ct.stime<? AND ct.etime>? AND ct.is_delete=0 AND a.id=ct.tab_id ORDER BY ct.priority ASC`
  12. )
  13. type Dao struct {
  14. db *sql.DB
  15. }
  16. func New(c *conf.Config) (d *Dao) {
  17. d = &Dao{
  18. db: sql.NewMySQL(c.MySQL.Show),
  19. }
  20. return
  21. }
  22. // Menus menus tab
  23. func (d *Dao) Menus(c context.Context, now time.Time) (menus map[int64][]*tab.Menu, err error) {
  24. var (
  25. rows *sql.Rows
  26. )
  27. if rows, err = d.db.Query(c, _getAllMenuSQL, now.Unix(), now.Unix()); err != nil {
  28. return
  29. }
  30. defer rows.Close()
  31. menus = map[int64][]*tab.Menu{}
  32. for rows.Next() {
  33. m := &tab.Menu{}
  34. if err = rows.Scan(&m.ID, &m.TagID, &m.TabID, &m.Name, &m.Priority, &m.Title); err != nil {
  35. return
  36. }
  37. menus[m.TagID] = append(menus[m.TagID], m)
  38. }
  39. err = rows.Err()
  40. return
  41. }