tab.go 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package tab
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/app-resource/conf"
  6. "go-common/app/interface/main/app-resource/model/tab"
  7. "go-common/library/database/sql"
  8. )
  9. const (
  10. _getAllMenuSQL = "SELECT id,plat,name,ctype,cvalue,plat_ver,status,color,badge FROM app_menus WHERE stime<? AND etime>? AND status=1 ORDER BY `order` ASC"
  11. )
  12. type Dao struct {
  13. db *sql.DB
  14. }
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. db: sql.NewMySQL(c.MySQL.Show),
  18. }
  19. return
  20. }
  21. // Menus menus tab
  22. func (d *Dao) Menus(c context.Context, now time.Time) (menus []*tab.Menu, err error) {
  23. var rows *sql.Rows
  24. if rows, err = d.db.Query(c, _getAllMenuSQL, now, now); err != nil {
  25. return
  26. }
  27. defer rows.Close()
  28. for rows.Next() {
  29. m := &tab.Menu{}
  30. if err = rows.Scan(&m.TabID, &m.Plat, &m.Name, &m.CType, &m.CValue, &m.PlatVersion, &m.Status, &m.Color, &m.Badge); err != nil {
  31. return
  32. }
  33. if m.CValue != "" {
  34. m.Change()
  35. menus = append(menus, m)
  36. }
  37. }
  38. err = rows.Err()
  39. return
  40. }