reply.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package data
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/job/main/videoup-report/model/archive"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. // OpenReply change subject state to open
  12. func (d *Dao) OpenReply(c context.Context, aid int64, mid int64) (err error) {
  13. params := url.Values{}
  14. // guanguan admin id
  15. params.Set("adid", "399")
  16. params.Set("mid", strconv.FormatInt(mid, 10))
  17. params.Set("oid", strconv.FormatInt(aid, 10))
  18. params.Set("type", "1")
  19. params.Set("state", "0")
  20. var res struct {
  21. Code int `json:"code"`
  22. Message string `json:"message"`
  23. }
  24. if err = d.clientWriter.Post(c, d.replyChangeURL, "", params, &res); err != nil {
  25. log.Error("OpenReply url(%s) error(%v)", d.replyChangeURL+"?"+params.Encode(), err)
  26. return
  27. }
  28. if res.Code != 0 {
  29. log.Error("OpenReply url(%s) code(%d) msg(%s)", d.replyChangeURL+"?"+params.Encode(), res.Code, res.Message)
  30. if res.Code == ecode.ReplySubjectExist.Code() || res.Code == ecode.ReplySubjectFrozen.Code() || res.Code == ecode.ReplyIllegalSubState.Code() || res.Code == ecode.ReplyIllegalSubType.Code() {
  31. return
  32. }
  33. err = fmt.Errorf("OpenReply call failed")
  34. }
  35. return
  36. }
  37. // CloseReply change subject state to close
  38. func (d *Dao) CloseReply(c context.Context, aid int64, mid int64) (err error) {
  39. params := url.Values{}
  40. // guanguan admin id
  41. params.Set("adid", "399")
  42. params.Set("mid", strconv.FormatInt(mid, 10))
  43. params.Set("oid", strconv.FormatInt(aid, 10))
  44. params.Set("type", "1")
  45. params.Set("state", "1")
  46. var res struct {
  47. Code int `json:"code"`
  48. Message string `json:"message"`
  49. }
  50. if err = d.clientWriter.Post(c, d.replyChangeURL, "", params, &res); err != nil {
  51. log.Error("CloseReply url(%s) error(%v)", d.replyChangeURL+"?"+params.Encode(), err)
  52. return
  53. }
  54. if res.Code != 0 {
  55. log.Error("CloseReply url(%s) code(%d) msg(%s)", d.replyChangeURL+"?"+params.Encode(), res.Code, res.Message)
  56. if res.Code == ecode.ReplySubjectExist.Code() || res.Code == ecode.ReplySubjectFrozen.Code() || res.Code == ecode.ReplyIllegalSubState.Code() || res.Code == ecode.ReplyIllegalSubType.Code() {
  57. return
  58. }
  59. err = fmt.Errorf("CloseReply call failed")
  60. }
  61. return
  62. }
  63. // CheckReply get subject state
  64. func (d *Dao) CheckReply(c context.Context, aid int64) (replyState int64, err error) {
  65. params := url.Values{}
  66. // guanguan admin id
  67. params.Set("adid", "399")
  68. params.Set("oid", strconv.FormatInt(aid, 10))
  69. params.Set("type", "1")
  70. var res struct {
  71. Code int `json:"code"`
  72. Data *struct {
  73. Oid int64 `json:"oid"`
  74. Mid int64 `json:"mid"`
  75. State int8 `json:"state"`
  76. } `json:"data"`
  77. Message string `json:"message"`
  78. }
  79. if err = d.client.Get(c, d.replyInfoURL, "", params, &res); err != nil {
  80. replyState = archive.ReplyDefault
  81. log.Error("CheckReply url(%s) error(%v)", d.replyInfoURL+"?"+params.Encode(), err)
  82. return
  83. }
  84. if res.Code != 0 {
  85. replyState = archive.ReplyDefault
  86. log.Info("CheckReply url(%s) code(%d)", d.replyInfoURL+"?"+params.Encode(), res.Code)
  87. return
  88. }
  89. if res.Data == nil {
  90. replyState = archive.ReplyDefault
  91. log.Info("CheckReply url(%s) code(%d) data(%v)", d.replyInfoURL+"?"+params.Encode(), res.Code, res.Data)
  92. return
  93. }
  94. replyState = int64(res.Data.State)
  95. return
  96. }