package srv_report import ( "context" "encoding/json" "fmt" "strconv" "time" "videoweb/pub/common/log" "videoweb/pub/common/useragent" "videoweb/pub/dataReport" "videoweb/pub/models/eventmod" "videoweb/pub/models/videocategorymod" "videoweb/pub/models/videoinformationmod" "go.mongodb.org/mongo-driver/bson" ) // ReportVideoStatusChangeEvent 视频状态变更事件上报 func ReportVideoStatusChangeEvent(media *videoinformationmod.VideoInformation, flag, userId int64, ua useragent.UA) { if media == nil || media.Id == 0 || flag == 0 { return } var lsjId string var videoTypeID = "default" var videoTypeName = "默认分类" if len(media.CategoryIds) > 0 { ctx, cancel := context.WithTimeout(context.Background(), time.Second*3) defer cancel() category, _ := videocategorymod.FindOneVideoCategory(ctx, bson.M{ videocategorymod.FN.VideoCategory.Id: media.CategoryIds[0], }) if category != nil { videoTypeID = fmt.Sprintf("%v", category.Id) videoTypeName = category.Name } } event := dataReport.NewCommonField("", dataReport.EventTypeVideoStatusChange, "", ua, strconv.FormatInt(userId, 10), "") event.Payload = dataReport.JsonRawMessage(&dataReport.VideoStatusChangeEvent{ MediaId: lsjId, VideoID: fmt.Sprintf("%v", media.Id), VideoTitle: media.Title, VideoTypeID: videoTypeID, VideoTypeName: videoTypeName, Flag: dataReport.JsonNumber(flag), }) b, _ := json.Marshal(event) if err := eventmod.InsertOneEvent(context.Background(), &eventmod.Event{ EventId: event.EventID, EventType: event.Event, Data: string(b), Status: eventmod.Default, CreatedAt: time.Now(), UpdatedAt: time.Now(), }); err != nil { log.Error("ReportVideoStatusChangeEvent fail", log.Any("mediaId", media.Id), log.E(err)) } } // VideoStatusFlag 将媒体状态映射为上报flag func VideoStatusFlag(status videoinformationmod.InformationSatus) int64 { switch status { case videoinformationmod.InformationSatusVerifyOK: return 1 // 上架 case videoinformationmod.InformationSatusVerifyCancel: return 2 // 未通过 default: return 0 } }