upper.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. model "go-common/app/job/main/reply/model/reply"
  6. "go-common/library/log"
  7. xtime "go-common/library/time"
  8. )
  9. func (s *Service) actionUp(c context.Context, msg *consumerMsg) {
  10. var d struct {
  11. Op string `json:"op"`
  12. Action uint32 `json:"action"`
  13. Oid int64 `json:"oid"`
  14. Tp int64 `json:"tp"`
  15. RpID int64 `json:"rpid"`
  16. MTime xtime.Time `json:"mtime"`
  17. }
  18. if err := json.Unmarshal([]byte(msg.Data), &d); err != nil {
  19. log.Error("json.Unmarshal() error(%v)", err)
  20. return
  21. }
  22. if d.Oid == 0 || d.RpID == 0 {
  23. log.Error("The structure of action(%s) from rpCh was wrong", msg.Data)
  24. return
  25. }
  26. rp, err := s.getReplyCache(c, d.Oid, d.RpID)
  27. if err != nil {
  28. log.Error("s.getReply failed , oid(%d), RpID(%d) err(%v)", d.Oid, d.RpID, err)
  29. return
  30. }
  31. if rp == nil {
  32. log.Error("reply is nil oid(%d) RpID(%d)", d.Oid, d.RpID)
  33. return
  34. }
  35. var state int8
  36. switch {
  37. case d.Op == "show":
  38. if rp.State != model.ReplyStateHidden {
  39. log.Warn("reply state(%d) is not hidden", rp.State)
  40. return
  41. }
  42. state = model.ReplyStateNormal
  43. case d.Op == "hide":
  44. if rp.State != model.ReplyStateNormal && rp.State != model.ReplyStateGarbage && rp.State != model.ReplyStateFiltered && rp.State != model.ReplyStateFolded {
  45. log.Warn("reply state(%d) is not normal", rp.State)
  46. return
  47. }
  48. state = model.ReplyStateHidden
  49. case d.Op == "top_add":
  50. if err := s.topAdd(c, rp, d.MTime, d.Action, model.SubAttrUpperTop); err != nil {
  51. log.Error("s.topAdd(oid %d) err(%v)", d.Oid, err)
  52. }
  53. return
  54. }
  55. if rows, err := s.dao.Reply.UpState(c, d.Oid, d.RpID, state, d.MTime.Time()); err != nil || rows < 1 {
  56. log.Error("dao.Reply.Update(%d, %d, %d), error(%v) and rows==0", d.Oid, d.RpID, state, err)
  57. } else {
  58. // if rp, err := s.dao.Mc.GetReply(nil, d.RpID); err == nil && rp != nil {
  59. rp.State = state
  60. if err = s.dao.Mc.AddReply(c, rp); err != nil {
  61. log.Error("s.dao.Mc.AddReply(%d, %d, %d), error(%v) and rows==0", d.Oid, d.RpID, state, err)
  62. }
  63. // }
  64. }
  65. // callSearchUp(rp.Oid, rp.RpID, rp.Type, false)
  66. }