up_group.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "go-common/app/admin/main/videoup-task/model"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. )
  9. //UPGroups get all the up groups
  10. func (d *Dao) UPGroups(c context.Context, mids []int64) (groups map[int64][]*model.UPGroup, err error) {
  11. val := url.Values{}
  12. mid := xstr.JoinInts(mids)
  13. val.Set("mids", mid)
  14. val.Set("group_id", "0")
  15. groups = map[int64][]*model.UPGroup{}
  16. for _, mid := range mids {
  17. groups[mid] = []*model.UPGroup{}
  18. }
  19. var res struct {
  20. Code int `json:"code"`
  21. Data struct {
  22. Items []map[string]interface{} `json:"items"`
  23. }
  24. }
  25. if err = d.hclient.Get(c, d.upGroupURL, "", val, &res); err != nil {
  26. log.Error("UPGroups url(%s) error(%v)", d.upGroupURL+"?"+val.Encode(), err)
  27. return
  28. }
  29. if res.Code != 0 || res.Data.Items == nil {
  30. log.Warn("UPGroups code(%d) !=0 or empty url(%s) error(%v)", res.Code, d.upGroupURL+"?"+val.Encode(), res.Code)
  31. return
  32. }
  33. for _, item := range res.Data.Items {
  34. g := &model.UPGroup{
  35. ID: int64(item["group_id"].(float64)),
  36. Tag: item["group_name"].(string),
  37. ShortTag: item["group_tag"].(string),
  38. FontColor: item["font_color"].(string),
  39. BgColor: item["bg_color"].(string),
  40. Note: item["note"].(string),
  41. }
  42. mid := int64(item["mid"].(float64))
  43. groups[mid] = append(groups[mid], g)
  44. }
  45. return
  46. }