subtitle.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/dm2/model"
  6. account "go-common/app/service/main/account/api"
  7. "go-common/app/service/main/archive/api"
  8. archive "go-common/app/service/main/archive/model/archive"
  9. filterCli "go-common/app/service/main/filter/api/grpc/v1"
  10. "go-common/library/ecode"
  11. "go-common/library/log"
  12. )
  13. const (
  14. _filterArea = "subtitle"
  15. )
  16. // SubtitleFilter .
  17. func (s *Service) SubtitleFilter(c context.Context, words string) (hit []string, err error) {
  18. var (
  19. reply *filterCli.HitReply
  20. )
  21. if len(words) > model.SubtitleContentSizeLimit {
  22. err = ecode.SubtitleSizeLimit
  23. return
  24. }
  25. if reply, err = s.filterRPC.Hit(c, &filterCli.HitReq{
  26. Area: _filterArea,
  27. Msg: words,
  28. }); err != nil {
  29. log.Error("SubtitleFilter(params:%+v),error(%v)", words, err)
  30. return
  31. }
  32. hit = reply.Hits
  33. return
  34. }
  35. // SubtitlePermission .
  36. func (s *Service) SubtitlePermission(c context.Context, aid int64, oid int64, tp int32, mid int64) (err error) {
  37. var (
  38. subject *model.Subject
  39. )
  40. if subject, err = s.subject(c, tp, oid); err != nil {
  41. log.Error("params(tp:%v,oid:%v).error(%v)", tp, oid, err)
  42. return
  43. }
  44. if s.checkAidOid(c, aid, oid); err != nil {
  45. return
  46. }
  47. if err = s.checkSubtitlePermission(c, aid, oid, tp, mid, subject); err != nil {
  48. return
  49. }
  50. return
  51. }
  52. // DelSubtitle .
  53. func (s *Service) DelSubtitle(c context.Context, oid int64, subtitleID int64, mid int64) (err error) {
  54. var (
  55. subtitle *model.Subtitle
  56. )
  57. if subtitle, err = s.getSubtitle(c, oid, subtitleID); err != nil {
  58. log.Error("params(oid:%v, subtitleID:%v) error(%v)", oid, subtitleID, err)
  59. return
  60. }
  61. if subtitle == nil {
  62. err = ecode.NothingFound
  63. return
  64. }
  65. if subtitle.Mid != mid {
  66. err = ecode.SubtitlePermissionDenied
  67. return
  68. }
  69. if subtitle.Status != model.SubtitleStatusDraft &&
  70. subtitle.Status != model.SubtitleStatusToAudit &&
  71. subtitle.Status != model.SubtitleStatusAuditBack &&
  72. subtitle.Status != model.SubtitleStatusManagerBack {
  73. err = ecode.SubtitleDelUnExist
  74. return
  75. }
  76. subtitle.Status = model.SubtitleStatusRemove
  77. subtitle.PubTime = time.Now().Unix()
  78. if err = s.updateSubtitle(c, subtitle); err != nil {
  79. return
  80. }
  81. s.subtitleReportDelete(c, oid, subtitleID)
  82. return
  83. }
  84. // addSubtitle new a subtitle draft
  85. func (s *Service) addSubtitle(c context.Context, draft *model.Subtitle) (insertID int64, err error) {
  86. if insertID, err = s.dao.AddSubtitle(c, draft); err != nil {
  87. log.Error("params(draft:%+v).error(%v)", draft, err)
  88. return
  89. }
  90. s.dao.DelSubtitleDraftCache(context.Background(), draft.Oid, draft.Type, draft.Mid, draft.Lan)
  91. s.dao.DelSubtitleCache(context.Background(), draft.Oid, draft.ID)
  92. return
  93. }
  94. // updateSubtitle update an exist subtitle
  95. func (s *Service) updateSubtitle(c context.Context, subtitle *model.Subtitle) (err error) {
  96. if err = s.dao.UpdateSubtitle(c, subtitle); err != nil {
  97. log.Error("params(draft:%+v).error(%v)", subtitle, err)
  98. return
  99. }
  100. s.dao.DelSubtitleDraftCache(context.Background(), subtitle.Oid, subtitle.Type, subtitle.Mid, subtitle.Lan)
  101. s.dao.DelSubtitleCache(context.Background(), subtitle.Oid, subtitle.ID)
  102. return
  103. }
  104. // SubtitleSign .
  105. func (s *Service) SubtitleSign(c context.Context, oid int64, tp int32, mid int64, subtitleID int64, isSign bool) (err error) {
  106. var (
  107. subtitle *model.Subtitle
  108. )
  109. if subtitle, err = s.getSubtitle(c, oid, subtitleID); err != nil {
  110. log.Error("params(oid:%v,subtitleID:%v).error(%v)", oid, subtitleID, err)
  111. return
  112. }
  113. if subtitle == nil {
  114. err = ecode.NothingFound
  115. return
  116. }
  117. if mid != subtitle.Mid {
  118. err = ecode.SubtitlePermissionDenied
  119. return
  120. }
  121. if subtitle.Status != model.SubtitleStatusDraft &&
  122. subtitle.Status != model.SubtitleStatusToAudit &&
  123. subtitle.Status != model.SubtitleStatusAuditBack &&
  124. subtitle.Status != model.SubtitleStatusPublish &&
  125. subtitle.Status != model.SubtitleStatusCheckToAudit &&
  126. subtitle.Status != model.SubtitleStatusCheckPublish &&
  127. subtitle.Status != model.SubtitleStatusManagerBack {
  128. err = ecode.SubtitlePermissionDenied
  129. return
  130. }
  131. subtitle.IsSign = isSign
  132. if err = s.dao.UpdateSubtitle(c, subtitle); err != nil {
  133. log.Error("params(%+v).error(%v)", subtitle, err)
  134. return
  135. }
  136. if err = s.dao.DelSubtitleCache(c, oid, subtitleID); err != nil {
  137. log.Error("DelSubtitleCache.params(oid:%v,subtitleID:%v).error(%v)", oid, subtitleID, err)
  138. return
  139. }
  140. if err = s.dao.DelVideoSubtitleCache(c, oid, tp); err != nil {
  141. log.Error("DelVideoSubtitleCache.params(oid:%v,tp:%v).error(%v)", oid, tp, err)
  142. return
  143. }
  144. return
  145. }
  146. // SubtitleLock .
  147. func (s *Service) SubtitleLock(c context.Context, oid int64, tp int32, mid int64, subtitleID int64, isLock bool) (err error) {
  148. var (
  149. subject *model.Subject
  150. subtitle *model.Subtitle
  151. )
  152. if subtitle, err = s.getSubtitle(c, oid, subtitleID); err != nil {
  153. log.Error("params(oid:%v,subtitleID:%v).error(%v)", oid, subtitleID, err)
  154. return
  155. }
  156. if subtitle == nil {
  157. err = ecode.NothingFound
  158. return
  159. }
  160. if subject, err = s.subject(c, tp, oid); err != nil {
  161. log.Error("params(oid:%v,tp:%v).error(%v)", oid, tp, err)
  162. return
  163. }
  164. if mid != subject.Mid {
  165. err = ecode.SubtitlePermissionDenied
  166. return
  167. }
  168. if subtitle.Status != model.SubtitleStatusPublish &&
  169. subtitle.Status != model.SubtitleStatusCheckPublish {
  170. err = ecode.SubtitleNotPublish
  171. return
  172. }
  173. subtitle.IsLock = isLock
  174. if err = s.dao.UpdateSubtitle(c, subtitle); err != nil {
  175. log.Error("params(%+v).error(%v)", subtitle, err)
  176. return
  177. }
  178. if err = s.dao.DelSubtitleCache(c, oid, subtitleID); err != nil {
  179. log.Error("DelSubtitleCache.params(oid:%v,subtitleID:%v).error(%v)", oid, subtitleID, err)
  180. return
  181. }
  182. if err = s.dao.DelVideoSubtitleCache(c, oid, tp); err != nil {
  183. log.Error("DelVideoSubtitleCache.params(oid:%v,tp:%v).error(%v)", oid, tp, err)
  184. return
  185. }
  186. return
  187. }
  188. // ArchiveName .
  189. func (s *Service) ArchiveName(c context.Context, aid int64) (arcvhiveName string, err error) {
  190. var (
  191. res *api.Arc
  192. )
  193. if res, err = s.arcRPC.Archive3(c, &archive.ArgAid2{
  194. Aid: aid,
  195. }); err != nil {
  196. log.Error("params(aid:%v).error(%v)", aid, err)
  197. return
  198. }
  199. arcvhiveName = res.Title
  200. return
  201. }
  202. // SubtitleShow .
  203. func (s *Service) SubtitleShow(c context.Context, oid int64, subtitleID int64, mid int64) (subtitleShow *model.SubtitleShow, err error) {
  204. var (
  205. subtitle *model.Subtitle
  206. canShow bool
  207. res *api.Arc
  208. infoReply *account.InfoReply
  209. showStatus model.SubtitleStatus
  210. )
  211. if subtitle, err = s.getSubtitle(c, oid, subtitleID); err != nil {
  212. log.Error("params(oid:%v,subtitleID:%v).error(%v)", oid, subtitleID, err)
  213. return
  214. }
  215. if subtitle == nil {
  216. err = ecode.NothingFound
  217. return
  218. }
  219. showStatus = subtitle.Status
  220. // 发布的状态都可见
  221. // 非发布的状态本人可见
  222. // 审核状态 up 主可见
  223. switch subtitle.Status {
  224. case model.SubtitleStatusPublish:
  225. canShow = true
  226. case model.SubtitleStatusToAudit,
  227. model.SubtitleStatusCheckPublish:
  228. if subtitle.UpMid == mid || subtitle.Mid == mid {
  229. canShow = true
  230. }
  231. case model.SubtitleStatusDraft,
  232. model.SubtitleStatusAuditBack,
  233. model.SubtitleStatusCheckToAudit:
  234. if subtitle.Mid == mid {
  235. canShow = true
  236. }
  237. case model.SubtitleStatusManagerBack:
  238. if subtitle.Mid == mid {
  239. canShow = true
  240. }
  241. showStatus = model.SubtitleStatusAuditBack
  242. default:
  243. err = ecode.SubtitlePermissionDenied
  244. return
  245. }
  246. if !canShow {
  247. err = ecode.SubtitlePermissionDenied
  248. return
  249. }
  250. lan, lanDoc := s.subtitleLans.GetByID(int64(subtitle.Lan))
  251. subtitleShow = &model.SubtitleShow{
  252. ID: subtitle.ID,
  253. Oid: subtitle.Oid,
  254. Type: subtitle.Type,
  255. Aid: subtitle.Aid,
  256. Lan: lan,
  257. LanDoc: lanDoc,
  258. Mid: subtitle.Mid,
  259. IsSign: subtitle.IsSign,
  260. IsLock: subtitle.IsLock,
  261. Status: showStatus,
  262. SubtitleURL: subtitle.SubtitleURL,
  263. RejectComment: subtitle.RejectComment,
  264. }
  265. if subtitle.UpMid == mid {
  266. subtitleShow.UpperStatus = model.UpperStatusUpper
  267. }
  268. if subtitle.Mid == mid {
  269. subtitleShow.AuthorStatus = model.AuthorStatusAuthor
  270. }
  271. if res, err = s.arcRPC.Archive3(c, &archive.ArgAid2{
  272. Aid: subtitle.Aid,
  273. }); err != nil {
  274. log.Error("params(aid:%v).error(%v)", subtitle.Aid, err)
  275. err = nil
  276. } else {
  277. subtitleShow.ArchiveName = res.Title
  278. }
  279. if infoReply, err = s.accountRPC.Info3(c, &account.MidReq{
  280. Mid: subtitle.AuthorID,
  281. }); err != nil {
  282. log.Error("params(mid:%v).error(%v)", subtitle.Mid, err)
  283. err = nil
  284. } else {
  285. subtitleShow.Author = infoReply.GetInfo().GetName()
  286. }
  287. return
  288. }