extra_func.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "strings"
  6. "time"
  7. "go-common/app/job/main/credit/model"
  8. "go-common/library/log"
  9. )
  10. // UpdateVoteCount update user vote count.
  11. func (s *Service) UpdateVoteCount(c context.Context, mr *model.Case) {
  12. cvs, err := s.dao.CaseVotesCID(c, mr.ID)
  13. if err != nil {
  14. log.Error("s.dao.CaseVotesCID(%d)", mr.ID)
  15. return
  16. }
  17. for _, cv := range cvs {
  18. switch {
  19. case mr.JudgeType == model.JudgeTypeViolate:
  20. if cv.Vote == model.VoteTypeDelete || cv.Vote == model.VoteTypeViolate {
  21. if err = s.dao.UpdateVoteRight(c, cv.MID); err != nil {
  22. log.Error("s.dao.UpdateVoteRight(%d)", cv.MID)
  23. }
  24. } else if cv.Vote == model.VoteTypeLegal {
  25. if err = s.dao.UpdateVoteTotal(c, cv.MID); err != nil {
  26. log.Error("s.dao.UpdateVoteTotal(%d)", cv.MID)
  27. }
  28. }
  29. case mr.JudgeType == model.JudgeTypeLegal:
  30. if cv.Vote == model.VoteTypeLegal {
  31. if err = s.dao.UpdateVoteRight(c, cv.MID); err != nil {
  32. log.Error("s.dao.UpdateVoteRight(%d)", cv.MID)
  33. }
  34. } else if cv.Vote == model.VoteTypeViolate || cv.Vote == model.VoteTypeDelete {
  35. if err = s.dao.UpdateVoteTotal(c, cv.MID); err != nil {
  36. log.Error("s.dao.UpdateVoteTotal(%d)", cv.MID)
  37. }
  38. }
  39. }
  40. time.Sleep(100 * time.Millisecond)
  41. }
  42. }
  43. // UpdateCache update blocked info cache.
  44. func (s *Service) UpdateCache(c context.Context, nwMsg []byte) (err error) {
  45. mr := &model.BlockedInfo{}
  46. if err = json.Unmarshal(nwMsg, mr); err != nil {
  47. log.Error("json.Unmarshal(%s) error(%v)", string(nwMsg), err)
  48. return
  49. }
  50. if mr.PublishStatus == int64(model.PublishClose) || mr.Status == int64(model.StatusClose) {
  51. s.dao.DelBlockedInfoIdx(c, mr)
  52. } else {
  53. s.dao.AddBlockInfoIdx(c, mr)
  54. }
  55. return
  56. }
  57. // DelOrigin delorigin content.
  58. func (s *Service) DelOrigin(c context.Context, cs *model.Case) {
  59. switch int8(cs.OriginType) {
  60. case model.OriginReply:
  61. if cs.RelationID != "" {
  62. args := strings.Split(cs.RelationID, "-")
  63. if len(args) != 3 {
  64. return
  65. }
  66. s.dao.DelReply(c, args[0], args[1], args[2])
  67. }
  68. case model.OriginTag:
  69. if cs.RelationID != "" {
  70. args := strings.Split(cs.RelationID, "-")
  71. if len(args) != 2 {
  72. return
  73. }
  74. s.dao.DelTag(c, args[0], args[1])
  75. }
  76. case model.OriginDM:
  77. if cs.RelationID != "" {
  78. args := strings.Split(cs.RelationID, "-")
  79. if len(args) != 4 {
  80. return
  81. }
  82. s.dao.ReportDM(c, args[2], args[1], model.DMNotifyDel)
  83. }
  84. }
  85. }
  86. // DeleteIdx del cache idx.
  87. func (s *Service) DeleteIdx(c context.Context, nwMsg []byte) (err error) {
  88. var opinion *model.Opinion
  89. if err = json.Unmarshal(nwMsg, &opinion); err != nil {
  90. log.Error("json.Unmarshal(%s) error(%v)", string(nwMsg), err)
  91. return
  92. }
  93. s.dao.DelOpinionCache(c, opinion.Vid)
  94. s.dao.DelCaseIdx(c, opinion.Cid)
  95. s.dao.DelVoteIdx(c, opinion.Cid)
  96. return
  97. }
  98. // jugeBlockedUser
  99. func (s *Service) jugeBlockedUser(c context.Context, mid int64, timeStr string, bType int8) (ok bool, count int64, err error) {
  100. var ts, nts time.Time
  101. if ts, err = time.ParseInLocation(model.TimeFormatSec, timeStr, time.Local); err != nil {
  102. log.Error("time.ParseInLocation(%s) error(%v)", timeStr, err)
  103. return
  104. }
  105. switch bType {
  106. case model.DealTimeTypeNone:
  107. nts = ts
  108. case model.DealTimeTypeDay:
  109. nts = ts.AddDate(0, 0, -1)
  110. case model.DealTimeTypeYear:
  111. nts = ts.AddDate(-1, 0, 0)
  112. }
  113. if count, err = s.dao.CountBlocked(c, mid, nts); err != nil {
  114. log.Error("s.dao.CountBlocked(%d,%s) error(%v)", mid, nts, err)
  115. return
  116. }
  117. if count == 0 {
  118. ok = true
  119. }
  120. return
  121. }
  122. // DelJuryInfoCache .
  123. func (s *Service) DelJuryInfoCache(c context.Context, nwMsg []byte) (err error) {
  124. mr := &model.Jury{}
  125. if err = json.Unmarshal(nwMsg, mr); err != nil {
  126. log.Error("json.Unmarshal(%s) error(%v)", string(nwMsg), err)
  127. return
  128. }
  129. if err = s.dao.DelJuryInfoCache(c, mr.Mid); err != nil {
  130. log.Error("s.dao.DelJuryInfoCache(%d) error(%v)", mr.Mid, err)
  131. }
  132. return
  133. }
  134. // DelCaseVoteTopCache .
  135. func (s *Service) DelCaseVoteTopCache(c context.Context, nwMsg []byte) (err error) {
  136. mr := &model.CaseVote{}
  137. if err = json.Unmarshal(nwMsg, mr); err != nil {
  138. log.Error("json.Unmarshal(%s) error(%v)", string(nwMsg), err)
  139. return
  140. }
  141. if err = s.dao.DelCaseVoteTopCache(c, mr.MID); err != nil {
  142. log.Error("s.dao.DelCaseVoteTopCache(%d) error(%v)", mr.MID, err)
  143. }
  144. return
  145. }