63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
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
|
|
}
|