@@ -0,0 +1,62 @@
|
||||
package pullgmod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
const table = models.PullLog
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// initIndex 初始化索引
|
||||
func initIndex() {
|
||||
many := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "createdAt", Value: -1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "newUpdatedAt", Value: -1}},
|
||||
},
|
||||
}
|
||||
if _, err := coll(nil).CreateIndex(many); err != nil {
|
||||
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertPullLog InsertPullLog
|
||||
func InsertPullLog(p PullLog) error {
|
||||
_, err := coll(nil).InsertOne(&p)
|
||||
return err
|
||||
}
|
||||
|
||||
// FindPullRecord 查询
|
||||
func FindPullRecord(vidType, newUpdateAt string) (pr *PullLog, err error) {
|
||||
opts := options.FindOne().SetSort(bson.D{{Key: "createdAt", Value: -1}})
|
||||
cond := bson.M{}
|
||||
if vidType != "" {
|
||||
cond["vidType"] = vidType
|
||||
}
|
||||
if newUpdateAt != "" {
|
||||
cond["newUpdatedAt"] = newUpdateAt
|
||||
}
|
||||
if err = coll(nil).FindOne(&pr, cond, opts); err != nil {
|
||||
log.Error("FindPullRecord error", log.E(err))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package pullgmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/db"
|
||||
)
|
||||
|
||||
// PullLog 从aws同步视频记录
|
||||
type PullLog struct {
|
||||
LastID string `json:"lastId" bson:"lastId"`
|
||||
Count int `json:"count" bson:"count"`
|
||||
FailCount int `json:"failCount" bson:"failCount"`
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
|
||||
FailIDs []string `json:"failIDs" bson:"failIDs,omitempty"`
|
||||
VidType string `json:"vidType" bson:"vidType"`
|
||||
NewUpdatedAt string `json:"newUpdatedAt" bson:"newUpdatedAt"`
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
initIndex()
|
||||
}
|
||||
Reference in New Issue
Block a user