egg.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package egg
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/app-resource/conf"
  6. "go-common/app/interface/main/app-resource/model/static"
  7. xsql "go-common/library/database/sql"
  8. "go-common/library/log"
  9. )
  10. const (
  11. _eggSQL = `SELECT e.id,ep.plat,ep.conditions,ep.build,ep.url,ep.md5,ep.size FROM egg AS e,egg_plat AS ep
  12. WHERE e.id=ep.egg_id AND e.stime<? AND e.etime>? AND e.publish=1 AND e.delete=0 AND ep.deleted=0`
  13. )
  14. type Dao struct {
  15. db *xsql.DB
  16. }
  17. func New(c *conf.Config) (d *Dao) {
  18. d = &Dao{
  19. db: xsql.NewMySQL(c.MySQL.Show),
  20. }
  21. return
  22. }
  23. // Egg select all egg
  24. func (d *Dao) Egg(ctx context.Context, now time.Time) (res map[int8][]*static.Static, err error) {
  25. res = map[int8][]*static.Static{}
  26. rows, err := d.db.Query(ctx, _eggSQL, now, now)
  27. if err != nil {
  28. log.Error("mysqlDB.Query error(%v)", err)
  29. return
  30. }
  31. defer rows.Close()
  32. for rows.Next() {
  33. s := &static.Static{}
  34. if err = rows.Scan(&s.Sid, &s.Plat, &s.Condition, &s.Build, &s.URL, &s.Hash, &s.Size); err != nil {
  35. log.Error("egg rows.Scan error(%v)", err)
  36. return
  37. }
  38. if s.URL == "" {
  39. continue
  40. }
  41. s.StaticChange()
  42. res[s.Plat] = append(res[s.Plat], s)
  43. }
  44. err = rows.Err()
  45. return
  46. }