59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package esmod
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
"videoweb/pub/common/srvdef"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
const (
|
|
FiveMinuteScale = 5 //对齐时间(分钟)
|
|
)
|
|
|
|
var (
|
|
videoIndex = "webhddjweb_video_index_v1"
|
|
playletIndex = "webhddjweb_playlet_index_v1"
|
|
)
|
|
|
|
func GetVideoIndex() string {
|
|
return videoIndex
|
|
}
|
|
|
|
func GetPlayletIndex() string {
|
|
return playletIndex
|
|
}
|
|
func GetRecordByESIndex(ctx context.Context, esIndex string) (
|
|
*ESTimestamp, *srvdef.SrvErr) {
|
|
|
|
filter := bson.M{FN.ESRecord.EsIndex: esIndex}
|
|
esRecord, serr := FindOneESRecord(ctx, filter)
|
|
if serr != nil {
|
|
if serr.Code != srvdef.ErrNoData {
|
|
return nil, serr
|
|
}
|
|
return nil, nil
|
|
}
|
|
return &esRecord.Timestamp, nil
|
|
}
|
|
|
|
func SetOneEsRecord(ctx context.Context, esIndex string,
|
|
timestamp *ESTimestamp) *srvdef.SrvErr {
|
|
filter := bson.M{FN.ESRecord.EsIndex: esIndex}
|
|
upsertDoc := bson.M{
|
|
"$set": bson.M{
|
|
FN.ESRecord.Timestamp.T: timestamp.T,
|
|
FN.ESRecord.Timestamp.I: timestamp.I,
|
|
FN.ESRecord.UpdatedAt: time.Now(),
|
|
},
|
|
"$setOnInsert": bson.M{
|
|
FN.ESRecord.Id: primitive.NewObjectID(),
|
|
FN.ESRecord.CreatedAt: time.Now(),
|
|
},
|
|
}
|
|
serr := UpsertOneESRecord(ctx, filter, upsertDoc)
|
|
return serr
|
|
}
|