123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- package service
- import (
- "context"
- "time"
- "go-common/app/interface/main/dm2/model"
- "go-common/library/database/sql"
- "go-common/library/ecode"
- "go-common/library/log"
- )
- // AuditSubtitle audit subtitle by uper pr assitant
- func (s *Service) AuditSubtitle(c context.Context, oid int64, subtitleID int64, mid int64, pass bool, rejectComment string) (err error) {
- var (
- draft *model.Subtitle
- subject *model.Subject
- )
- if draft, err = s.getSubtitle(c, oid, subtitleID); err != nil {
- log.Error("s.getSubtitle(oid:%v,subtitleID:%v),error(%v)", oid, subtitleID, err)
- return
- }
- if draft == nil {
- err = ecode.NothingFound
- return
- }
- // up主,协管有权限
- if subject, err = s.subject(c, draft.Type, draft.Oid); err != nil {
- return
- }
- // 非up主,无权限
- if subject.Mid != mid {
- err = ecode.SubtitlePermissionDenied
- return
- }
- if draft.Status != model.SubtitleStatusToAudit && draft.Status != model.SubtitleStatusPublish {
- err = ecode.SubtitleUnValid
- return
- }
- draft.RejectComment = rejectComment
- if !pass {
- if draft.Status == model.SubtitleStatusPublish {
- if err = s.backPubSubtitle(c, draft); err != nil {
- return
- }
- return
- }
- if err = s.auditReject(c, draft); err != nil {
- log.Error("params(draft:%+v).error(%v)", draft, err)
- return
- }
- } else {
- if err = s.auditPass(c, draft); err != nil {
- log.Error("params(draft:%+v).error(%v)", draft, err)
- return
- }
- }
- return
- }
- // auditReject subtitle submit
- func (s *Service) auditReject(c context.Context, subtitle *model.Subtitle) (err error) {
- subtitle.Status = model.SubtitleStatusAuditBack
- subtitle.PubTime = time.Now().Unix()
- if err = s.dao.UpdateSubtitle(c, subtitle); err != nil {
- log.Error("params(%+v).error(%v)", subtitle, err)
- return
- }
- s.dao.DelSubtitleDraftCache(context.Background(), subtitle.Oid, subtitle.Type, subtitle.Mid, subtitle.Lan)
- s.dao.DelSubtitleCache(context.Background(), subtitle.Oid, subtitle.ID)
- return
- }
- func (s *Service) auditPass(c context.Context, subtitle *model.Subtitle) (err error) {
- var (
- tx *sql.Tx
- subtitlePub *model.SubtitlePub
- )
- defer func() {
- if err != nil {
- tx.Rollback()
- log.Error("params(subtitle:%+v).err(%v)", subtitle, err)
- return
- }
- if err = tx.Commit(); err != nil {
- log.Error("params(subtitle:%+v).err(%v)", subtitle, err)
- return
- }
- }()
- subtitle.Status = model.SubtitleStatusPublish
- subtitle.PubTime = time.Now().Unix()
- if tx, err = s.dao.BeginBiliDMTrans(c); err != nil {
- log.Error("error(%v)", err)
- return
- }
- if err = s.dao.TxUpdateSubtitle(tx, subtitle); err != nil {
- log.Error("params(%+v).error(%v)", subtitle, err)
- return
- }
- subtitlePub = &model.SubtitlePub{
- Oid: subtitle.Oid,
- Type: subtitle.Type,
- Lan: subtitle.Lan,
- SubtitleID: subtitle.ID,
- }
- if err = s.dao.TxAddSubtitlePub(tx, subtitlePub); err != nil {
- log.Error("params(%+v).error(%v)", subtitlePub, err)
- return
- }
- if err = s.dao.DelSubtitleDraftCache(c, subtitle.Oid, subtitle.Type, subtitle.Mid, subtitle.Lan); err != nil {
- log.Error("DelSubtitleDraftCache.params(subtitle:%+v).err(%v)", subtitle, err)
- return
- }
- if err = s.dao.DelSubtitleCache(c, subtitle.Oid, subtitle.ID); err != nil {
- log.Error("DelSubtitleCache.params(subtitle:%+v).err(%v)", subtitle, err)
- return
- }
- if err = s.dao.DelVideoSubtitleCache(c, subtitle.Oid, subtitle.Type); err != nil {
- log.Error("DelVideoSubtitleCache.params(subtitle:%+v).err(%v)", subtitle, err)
- return
- }
- return
- }
- func (s *Service) backPubSubtitle(c context.Context, subtitle *model.Subtitle) (err error) {
- var (
- tx *sql.Tx
- subtitleNew *model.Subtitle
- subtitlePub *model.SubtitlePub
- )
- defer func() {
- if err != nil {
- tx.Rollback()
- return
- }
- if err = tx.Commit(); err != nil {
- return
- }
- }()
- subtitle.Status = model.SubtitleStatusAuditBack
- subtitle.PubTime = time.Now().Unix()
- if tx, err = s.dao.BeginBiliDMTrans(c); err != nil {
- log.Error("error(%v)", err)
- return
- }
- if err = s.dao.TxUpdateSubtitle(tx, subtitle); err != nil {
- log.Error("params(%+v) error(%v)", subtitle, err)
- return
- }
- if subtitleNew, err = s.dao.TxGetSubtitleOne(tx, subtitle.Oid, subtitle.Type, subtitle.Lan); err != nil {
- log.Error("params(%+v) error(%v)", subtitle, err)
- return
- }
- subtitlePub = &model.SubtitlePub{
- Oid: subtitle.Oid,
- Type: subtitle.Type,
- Lan: subtitle.Lan,
- }
- if subtitleNew == nil {
- subtitlePub.IsDelete = true
- } else {
- subtitlePub.SubtitleID = subtitleNew.ID
- }
- if err = s.dao.TxAddSubtitlePub(tx, subtitlePub); err != nil {
- log.Error("params(%+v) error(%v)", subtitlePub, err)
- return
- }
- if err = s.dao.DelSubtitleCache(context.Background(), subtitle.Oid, subtitle.ID); err != nil {
- log.Error("params(oid:%v,subtitleID:%v) error(%v)", subtitle.Oid, subtitle.ID, err)
- return
- }
- if err = s.dao.DelVideoSubtitleCache(context.Background(), subtitle.Oid, subtitle.Type); err != nil {
- log.Error("params(oid:%v,subtitleID:%v) error(%v)", subtitle.Oid, subtitle.ID, err)
- return
- }
- return
- }
|