Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
package questionnremod
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/models"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
const table = models.Questionnaire
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
// initIndex 索引设置
func initIndex() {
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
{
Keys: bson.D{{Key: "uid", Value: 1}},
},
{
Keys: bson.D{{Key: "level", Value: 1}},
},
{
Keys: bson.D{{Key: "uid", Value: 1}, {Key: "level", Value: 1}, {Key: "questionnaireId", Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: "createdAt", Value: 1}},
},
}
if _, err := coll(nil).CreateIndex(many); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
}
}
func Insert(q Questionnaire) error {
q.CreatedAt = time.Now()
_, err := coll(nil).InsertOne(q)
return err
}
func GetByUID(uid uint64) ([]Questionnaire, error) {
data := make([]Questionnaire, 0)
f := bson.M{"uid": uid}
return data, coll(nil).Find(&data, f)
}