@@ -0,0 +1,119 @@
|
||||
package aichangefacevidmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
const table = models.AiChangeFaceVideo
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// InitARDIndex 设置账户充值流水表索引
|
||||
func initIndex() {
|
||||
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
|
||||
{
|
||||
Keys: bson.D{{Key: "sort", Value: -1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "createdAt", Value: -1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "status", Value: -1}},
|
||||
},
|
||||
}
|
||||
if _, err := coll(nil).CreateIndex(many); err != nil {
|
||||
panic(fmt.Sprintf("AiUnDressIndex err+%v", err))
|
||||
}
|
||||
}
|
||||
|
||||
func GetMods(cond bson.M, skip, limit int) ([]AiChangeFaceVidMod, error) {
|
||||
var acfms []AiChangeFaceVidMod
|
||||
opts := options.Find().SetSort(bson.D{{Key: "createdAt", Value: -1}})
|
||||
if skip > 0 {
|
||||
opts.SetSkip(int64(skip))
|
||||
}
|
||||
if limit > 0 {
|
||||
opts.SetLimit(int64(limit))
|
||||
}
|
||||
return acfms, coll(nil).Find(&acfms, cond, opts)
|
||||
}
|
||||
|
||||
func GetValidMods(skip, limit int) ([]AiChangeFaceVidMod, error) {
|
||||
var acfms []AiChangeFaceVidMod
|
||||
opts := options.Find().SetSort(bson.D{{Key: "createdAt", Value: -1}})
|
||||
if skip > 0 {
|
||||
opts.SetSkip(int64(skip))
|
||||
}
|
||||
if limit > 0 {
|
||||
opts.SetLimit(int64(limit))
|
||||
}
|
||||
return acfms, coll(nil).Find(&acfms, bson.M{"status": 1}, opts)
|
||||
}
|
||||
|
||||
func GetAllMods() ([]AiChangeFaceVidMod, error) {
|
||||
var mod []AiChangeFaceVidMod
|
||||
opts := options.Find().SetSort(bson.D{{Key: "sort", Value: -1}, {Key: "createdAt", Value: -1}})
|
||||
return mod, coll(nil).Find(&mod, bson.M{"status": 1}, opts)
|
||||
}
|
||||
|
||||
func GetModById(id primitive.ObjectID) (*AiChangeFaceVidMod, error) {
|
||||
var acfvm AiChangeFaceVidMod
|
||||
return &acfvm, coll(nil).FindOne(&acfvm, bson.M{"_id": id})
|
||||
}
|
||||
|
||||
func GetModByIDs(ids []primitive.ObjectID) ([]AiChangeFaceVidMod, error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
var acfms []AiChangeFaceVidMod
|
||||
return acfms, coll(nil).Find(&acfms, bson.M{"_id": bson.M{"$in": ids}})
|
||||
}
|
||||
|
||||
// QueryAllDocument 分页查询文档
|
||||
func QueryAllDocument(filter primitive.M, opts ...*options.FindOptions) (out []*AiChangeFaceVidMod, err error) {
|
||||
if err = coll(nil).Find(&out, filter, opts...); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllDocument", table, "Find", err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// CountDocument 查询文档条目数
|
||||
func CountDocument(filter primitive.M) (int64, error) {
|
||||
if count, err := coll(nil).Count(filter); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "CountDocument", table, "Count", err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return 0, err
|
||||
} else {
|
||||
return count, nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetAllModsByCond(filter primitive.M) ([]AiChangeFaceVidMod, error) {
|
||||
var mod []AiChangeFaceVidMod
|
||||
opts := options.Find().SetSort(bson.D{{Key: "sort", Value: -1}, {Key: "createdAt", Value: -1}})
|
||||
return mod, coll(nil).Find(&mod, filter, opts)
|
||||
}
|
||||
|
||||
func UpdateManyByCond(filter primitive.M, set bson.M) error {
|
||||
_, err := coll(nil).UpdateMany(filter, set)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user