academy.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package academy
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "go-common/app/job/main/creative/model"
  7. "go-common/library/log"
  8. "go-common/library/xstr"
  9. )
  10. const (
  11. // select
  12. _getArcsSQL = "SELECT id,oid,business FROM academy_archive WHERE state=? AND business=? AND id > ? order by id ASC limit ?"
  13. )
  14. //Archives get limit achives.
  15. func (d *Dao) Archives(c context.Context, id int64, bs, limit int) (res []*model.OArchive, err error) {
  16. rows, err := d.db.Query(c, _getArcsSQL, 0, bs, id, limit)
  17. res = make([]*model.OArchive, 0)
  18. for rows.Next() {
  19. a := &model.OArchive{}
  20. if err = rows.Scan(&a.ID, &a.OID, &a.Business); err != nil {
  21. log.Error("rows.Scan error(%v)", err)
  22. return
  23. }
  24. res = append(res, a)
  25. }
  26. return
  27. }
  28. //UPHotByAIDs update hot by aids.
  29. func (d *Dao) UPHotByAIDs(c context.Context, hots map[int64]int64) error {
  30. var oids []int64
  31. sql := "UPDATE academy_archive SET hot = CASE oid "
  32. for oid, hot := range hots {
  33. sql += fmt.Sprintf("WHEN %d THEN %d ", oid, hot)
  34. oids = append(oids, oid)
  35. }
  36. sql += fmt.Sprintf("END, mtime=? WHERE oid IN (%s)", xstr.JoinInts(oids))
  37. _, err := d.db.Exec(c, sql, time.Now())
  38. if err != nil {
  39. log.Error("d.db.Exec sql(%s) error(%v)", sql, err)
  40. }
  41. log.Info("d.db.Exec sql(%s) hots(%+v) error(%v)", sql, hots, err)
  42. return err
  43. }