audit.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package audit
  2. import (
  3. "context"
  4. "go-common/app/interface/main/tv/model"
  5. "go-common/library/database/sql"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // HandleAudits treats the slice of IDList
  10. func (s *Service) HandleAudits(ctx context.Context, vals []*model.IDList) (err error) {
  11. var tx *sql.Tx
  12. if tx, err = s.auditDao.BeginTran(ctx); err != nil {
  13. log.Error("audit HandleAudits BeginTran Err %v", err)
  14. return
  15. }
  16. for _, v := range vals {
  17. if err = s.handleAudit(ctx, v, tx); err != nil {
  18. log.Error("HandleAudits audit (%v), err %v", v, err)
  19. tx.Rollback()
  20. return
  21. }
  22. }
  23. tx.Commit()
  24. return
  25. }
  26. // handleAudit checks the prefix to dispatch the task to ugc/pgc season/ep
  27. func (s *Service) handleAudit(ctx context.Context, val *model.IDList, tx *sql.Tx) (err error) {
  28. var (
  29. op = new(model.AuditOp)
  30. )
  31. if err = op.FromIDList(val); err != nil {
  32. log.Error("audit handle Type error %v", val)
  33. return
  34. }
  35. switch op.ContentType {
  36. case model.UgcArc:
  37. if arcCMS, err := s.cmsDao.LoadArcMeta(ctx, op.KID); err == nil && arcCMS != nil && arcCMS.NotDeleted() {
  38. return auditCore(ctx, op, tx, s.auditDao.UpdateArc)
  39. }
  40. case model.UgcVideo:
  41. if videoCMS, err := s.cmsDao.LoadVideoMeta(ctx, op.KID); err == nil && videoCMS != nil && videoCMS.NotDeleted() {
  42. return auditCore(ctx, op, tx, s.auditDao.UpdateVideo)
  43. }
  44. case model.PgcSn:
  45. if snCMS, err := s.cmsDao.SnAuth(ctx, op.KID); err == nil && snCMS != nil && snCMS.NotDeleted() {
  46. return auditCore(ctx, op, tx, s.auditDao.UpdateSea)
  47. }
  48. case model.PgcEp:
  49. if epCMS, err := s.cmsDao.EpAuth(ctx, op.KID); err == nil && epCMS != nil && epCMS.NotDeleted() {
  50. return auditCore(ctx, op, tx, s.auditDao.UpdateCont)
  51. }
  52. default:
  53. log.Error("audit handle Content Type Error %s", op.ToMsg())
  54. return ecode.TvDangbeiWrongType
  55. }
  56. return ecode.NothingFound
  57. }
  58. type doAudit func(ctx context.Context, v *model.AuditOp, tx *sql.Tx) (err error)
  59. func auditCore(c context.Context, v *model.AuditOp, tx *sql.Tx, updateFunc doAudit) (err error) {
  60. if err = updateFunc(c, v, tx); err != nil {
  61. log.Error("%s fail(%v)", v.ToMsg(), err)
  62. }
  63. return
  64. }