subtitle_audit.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/dm2/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. )
  10. // AuditSubtitle audit subtitle by uper pr assitant
  11. func (s *Service) AuditSubtitle(c context.Context, oid int64, subtitleID int64, mid int64, pass bool, rejectComment string) (err error) {
  12. var (
  13. draft *model.Subtitle
  14. subject *model.Subject
  15. )
  16. if draft, err = s.getSubtitle(c, oid, subtitleID); err != nil {
  17. log.Error("s.getSubtitle(oid:%v,subtitleID:%v),error(%v)", oid, subtitleID, err)
  18. return
  19. }
  20. if draft == nil {
  21. err = ecode.NothingFound
  22. return
  23. }
  24. // up主,协管有权限
  25. if subject, err = s.subject(c, draft.Type, draft.Oid); err != nil {
  26. return
  27. }
  28. // 非up主,无权限
  29. if subject.Mid != mid {
  30. err = ecode.SubtitlePermissionDenied
  31. return
  32. }
  33. if draft.Status != model.SubtitleStatusToAudit && draft.Status != model.SubtitleStatusPublish {
  34. err = ecode.SubtitleUnValid
  35. return
  36. }
  37. draft.RejectComment = rejectComment
  38. if !pass {
  39. if draft.Status == model.SubtitleStatusPublish {
  40. if err = s.backPubSubtitle(c, draft); err != nil {
  41. return
  42. }
  43. return
  44. }
  45. if err = s.auditReject(c, draft); err != nil {
  46. log.Error("params(draft:%+v).error(%v)", draft, err)
  47. return
  48. }
  49. } else {
  50. if err = s.auditPass(c, draft); err != nil {
  51. log.Error("params(draft:%+v).error(%v)", draft, err)
  52. return
  53. }
  54. }
  55. return
  56. }
  57. // auditReject subtitle submit
  58. func (s *Service) auditReject(c context.Context, subtitle *model.Subtitle) (err error) {
  59. subtitle.Status = model.SubtitleStatusAuditBack
  60. subtitle.PubTime = time.Now().Unix()
  61. if err = s.dao.UpdateSubtitle(c, subtitle); err != nil {
  62. log.Error("params(%+v).error(%v)", subtitle, err)
  63. return
  64. }
  65. s.dao.DelSubtitleDraftCache(context.Background(), subtitle.Oid, subtitle.Type, subtitle.Mid, subtitle.Lan)
  66. s.dao.DelSubtitleCache(context.Background(), subtitle.Oid, subtitle.ID)
  67. return
  68. }
  69. func (s *Service) auditPass(c context.Context, subtitle *model.Subtitle) (err error) {
  70. var (
  71. tx *sql.Tx
  72. subtitlePub *model.SubtitlePub
  73. )
  74. defer func() {
  75. if err != nil {
  76. tx.Rollback()
  77. log.Error("params(subtitle:%+v).err(%v)", subtitle, err)
  78. return
  79. }
  80. if err = tx.Commit(); err != nil {
  81. log.Error("params(subtitle:%+v).err(%v)", subtitle, err)
  82. return
  83. }
  84. }()
  85. subtitle.Status = model.SubtitleStatusPublish
  86. subtitle.PubTime = time.Now().Unix()
  87. if tx, err = s.dao.BeginBiliDMTrans(c); err != nil {
  88. log.Error("error(%v)", err)
  89. return
  90. }
  91. if err = s.dao.TxUpdateSubtitle(tx, subtitle); err != nil {
  92. log.Error("params(%+v).error(%v)", subtitle, err)
  93. return
  94. }
  95. subtitlePub = &model.SubtitlePub{
  96. Oid: subtitle.Oid,
  97. Type: subtitle.Type,
  98. Lan: subtitle.Lan,
  99. SubtitleID: subtitle.ID,
  100. }
  101. if err = s.dao.TxAddSubtitlePub(tx, subtitlePub); err != nil {
  102. log.Error("params(%+v).error(%v)", subtitlePub, err)
  103. return
  104. }
  105. if err = s.dao.DelSubtitleDraftCache(c, subtitle.Oid, subtitle.Type, subtitle.Mid, subtitle.Lan); err != nil {
  106. log.Error("DelSubtitleDraftCache.params(subtitle:%+v).err(%v)", subtitle, err)
  107. return
  108. }
  109. if err = s.dao.DelSubtitleCache(c, subtitle.Oid, subtitle.ID); err != nil {
  110. log.Error("DelSubtitleCache.params(subtitle:%+v).err(%v)", subtitle, err)
  111. return
  112. }
  113. if err = s.dao.DelVideoSubtitleCache(c, subtitle.Oid, subtitle.Type); err != nil {
  114. log.Error("DelVideoSubtitleCache.params(subtitle:%+v).err(%v)", subtitle, err)
  115. return
  116. }
  117. return
  118. }
  119. func (s *Service) backPubSubtitle(c context.Context, subtitle *model.Subtitle) (err error) {
  120. var (
  121. tx *sql.Tx
  122. subtitleNew *model.Subtitle
  123. subtitlePub *model.SubtitlePub
  124. )
  125. defer func() {
  126. if err != nil {
  127. tx.Rollback()
  128. return
  129. }
  130. if err = tx.Commit(); err != nil {
  131. return
  132. }
  133. }()
  134. subtitle.Status = model.SubtitleStatusAuditBack
  135. subtitle.PubTime = time.Now().Unix()
  136. if tx, err = s.dao.BeginBiliDMTrans(c); err != nil {
  137. log.Error("error(%v)", err)
  138. return
  139. }
  140. if err = s.dao.TxUpdateSubtitle(tx, subtitle); err != nil {
  141. log.Error("params(%+v) error(%v)", subtitle, err)
  142. return
  143. }
  144. if subtitleNew, err = s.dao.TxGetSubtitleOne(tx, subtitle.Oid, subtitle.Type, subtitle.Lan); err != nil {
  145. log.Error("params(%+v) error(%v)", subtitle, err)
  146. return
  147. }
  148. subtitlePub = &model.SubtitlePub{
  149. Oid: subtitle.Oid,
  150. Type: subtitle.Type,
  151. Lan: subtitle.Lan,
  152. }
  153. if subtitleNew == nil {
  154. subtitlePub.IsDelete = true
  155. } else {
  156. subtitlePub.SubtitleID = subtitleNew.ID
  157. }
  158. if err = s.dao.TxAddSubtitlePub(tx, subtitlePub); err != nil {
  159. log.Error("params(%+v) error(%v)", subtitlePub, err)
  160. return
  161. }
  162. if err = s.dao.DelSubtitleCache(context.Background(), subtitle.Oid, subtitle.ID); err != nil {
  163. log.Error("params(oid:%v,subtitleID:%v) error(%v)", subtitle.Oid, subtitle.ID, err)
  164. return
  165. }
  166. if err = s.dao.DelVideoSubtitleCache(context.Background(), subtitle.Oid, subtitle.Type); err != nil {
  167. log.Error("params(oid:%v,subtitleID:%v) error(%v)", subtitle.Oid, subtitle.ID, err)
  168. return
  169. }
  170. return
  171. }