来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83 项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet 测试目录 /server/hkdj_net,App/Web API 30331/30332 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package esmod
|
|
|
|
import (
|
|
"context"
|
|
"hkdj-web-server/pub/common/srvdef"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
const (
|
|
FiveMinuteScale = 5 //对齐时间(分钟)
|
|
)
|
|
|
|
var (
|
|
videoIndex = "webhkdjnet_video_index_v1"
|
|
playletIndex = "webhkdjnet_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
|
|
}
|