comment.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package dao
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "go-common/app/interface/bbq/app-bbq/model"
  7. "go-common/library/log"
  8. "go-common/library/net/metadata"
  9. "strings"
  10. jsoniter "github.com/json-iterator/go"
  11. )
  12. const (
  13. //DefaultCmType 默认评论类型
  14. DefaultCmType = 23
  15. )
  16. // ReplyCounts 批量评论数
  17. func (d *Dao) ReplyCounts(c context.Context, ids []int64, t int64) (res map[int64]*model.ReplyCount, err error) {
  18. ip := metadata.String(c, metadata.RemoteIP)
  19. oidStr := strings.Replace(strings.Trim(fmt.Sprint(ids), "[]"), " ", ",", -1)
  20. req := map[string]interface{}{
  21. "type": t,
  22. "oid": oidStr,
  23. }
  24. res = make(map[int64]*model.ReplyCount)
  25. var r []byte
  26. r, err = replyHTTPCommon(c, d.httpClient, d.c.URLs["reply_counts"], "GET", req, ip)
  27. if err != nil {
  28. log.Infov(c,
  29. log.KV("log", fmt.Sprintf("replyHTTPCommon err [%v]", err)),
  30. )
  31. return
  32. }
  33. var json = jsoniter.ConfigCompatibleWithStandardLibrary
  34. decoder := json.NewDecoder(bytes.NewBuffer(r))
  35. decoder.UseNumber()
  36. err = decoder.Decode(&res)
  37. if err != nil {
  38. log.Errorv(c, log.KV("log", fmt.Sprintf("json unmarlshal err data[%s]", string(r))))
  39. }
  40. return
  41. }