dao.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package data
  2. import (
  3. "context"
  4. "errors"
  5. "go-common/app/job/main/videoup-report/conf"
  6. "go-common/app/job/main/videoup-report/model/data"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. xhttp "go-common/library/net/http/blademaster"
  10. )
  11. const (
  12. _hotArc = "/data/rank/reco-app-remen-pre.json"
  13. _monitorNotify = "/va/monitor/notify"
  14. _replyChange = "/x/internal/v2/reply/subject/state"
  15. _replyInfo = "/x/internal/v2/reply/subject"
  16. _profitUpState = "/allowance/api/x/admin/growup/up/account/state"
  17. )
  18. //Dao dao
  19. type Dao struct {
  20. c *conf.Config
  21. moniNotifyURL string
  22. hotArcURL, replyInfoURL, replyChangeURL, upProfitState string
  23. client, clientWriter *xhttp.Client
  24. }
  25. //New new
  26. func New(c *conf.Config) (d *Dao) {
  27. d = &Dao{
  28. c: c,
  29. hotArcURL: c.Host.Data + _hotArc,
  30. moniNotifyURL: c.Host.Archive + _monitorNotify,
  31. replyInfoURL: c.Host.API + _replyInfo,
  32. replyChangeURL: c.Host.API + _replyChange,
  33. upProfitState: c.Host.Profit + _profitUpState,
  34. client: xhttp.NewClient(c.HTTPClient.Read),
  35. clientWriter: xhttp.NewClient(c.HTTPClient.Write),
  36. }
  37. return
  38. }
  39. // HotArchive get hot archives which need rechecking
  40. func (d *Dao) HotArchive(c context.Context) (aids []int64, err error) {
  41. res := &data.HotArchiveRes{}
  42. if err = d.client.Get(c, d.hotArcURL, "", nil, &res); err != nil {
  43. log.Error("d.HotArchive() error(%v)", err)
  44. return
  45. }
  46. if res.Code != ecode.OK.Code() {
  47. err = errors.New("data api bad response")
  48. log.Error("d.HotArchive() bad code(%d)", res.Code)
  49. return
  50. }
  51. for _, item := range res.List {
  52. aids = append(aids, item.Aid)
  53. }
  54. return
  55. }