sidebar.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package show
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/service/main/resource/model"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _selSideSQL = `SELECT s.id,s.plat,s.module,s.name,s.logo,s.logo_white,s.param,s.rank,l.build,l.conditions,s.tip,s.need_login,s.white_url,s.logo_selected,s.tab_id,s.red_dot_url,lang.name FROM
  10. sidebar AS s,sidebar_limit AS l,language AS lang WHERE s.state=1 AND s.id=l.s_id AND lang.id=s.lang_id AND s.online_time<? ORDER BY s.rank DESC,l.id ASC`
  11. )
  12. // SideBar get side bar.
  13. func (d *Dao) SideBar(ctx context.Context, now time.Time) (ss []*model.SideBar, limits map[int64][]*model.SideBarLimit, err error) {
  14. rows, err := d.db.Query(ctx, _selSideSQL, now)
  15. if err != nil {
  16. log.Error("d.db.Query error(%v)", err)
  17. return
  18. }
  19. defer rows.Close()
  20. limits = make(map[int64][]*model.SideBarLimit)
  21. for rows.Next() {
  22. s := &model.SideBar{}
  23. if err = rows.Scan(&s.ID, &s.Plat, &s.Module, &s.Name, &s.Logo, &s.LogoWhite, &s.Param, &s.Rank, &s.Build, &s.Conditions, &s.Tip, &s.NeedLogin, &s.WhiteURL, &s.LogoSelected, &s.TabID, &s.Red, &s.Language); err != nil {
  24. log.Error("row.Scan error(%v)", err)
  25. return
  26. }
  27. if _, ok := limits[s.ID]; !ok {
  28. ss = append(ss, s)
  29. }
  30. limit := &model.SideBarLimit{
  31. ID: s.ID,
  32. Build: s.Build,
  33. Condition: s.Conditions,
  34. }
  35. limits[s.ID] = append(limits[s.ID], limit)
  36. }
  37. err = rows.Err()
  38. return
  39. }