package newactivity import ( "time" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" ) func AddWinRecord(req WinRecords) error { _, err := collWin(nil).UpsertOne(bson.M{ "date": req.Date, "modelId": req.ModelId, }, bson.M{"$set": req}) return err } func WinRecordsByDate(date time.Time) ([]WinRecords, error) { list := make([]WinRecords, 0) return list, collWin(nil).Find(&list, bson.M{"date": date}) } func WinRecordPage(req WinRcdPageReq) (res WinRcdPageRes, err error) { conf := bson.M{} if req.ModelId != nil { conf["modelId"] = req.ModelId } if req.UserId != nil { conf["userId"] = req.UserId } if req.UserName != nil { conf["userName"] = bson.M{"$regex": req.UserName} } if !req.Date.IsZero() { conf["date"] = req.Date } res = WinRcdPageRes{} opts := options.Find().SetSort(bson.D{{Key: "createdAt", Value: -1}}) opts.SetSkip((req.Page - 1) * req.PageSize) opts.SetLimit(req.PageSize) if err = collWin(nil).Find(&res.Data, conf, opts); err != nil { return } res.Total, err = collWin(nil).Count(conf) return }