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
+14
View File
@@ -0,0 +1,14 @@
package systemmod
import (
"91porn-server/common/db"
"91porn-server/models"
)
var cdb *db.MongoDB
const cTable = models.SystemConfig
func Init() {
configIndex()
}
+79
View File
@@ -0,0 +1,79 @@
package systemmod
import (
"errors"
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/models/commod"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
func configColl(t *db.MongoTool) *db.MongoTool {
if t == nil {
return cdb.Coll(cTable)
}
return t.Coll(cTable)
}
func configIndex() {
cdb = db.Init(cTable)
many := []mongo.IndexModel{
{
Keys: bson.D{{Key: "type", Value: 1}, {Key: "location", Value: 1}},
},
{
Keys: bson.D{{Key: "isActive", Value: 1}},
},
}
if _, err := configColl(nil).CreateIndex(many); err != nil {
panic(fmt.Sprintf("system_config model set index err ==>[%+v]", err))
}
}
func GetByTypeLocation(t commod.SystemConfigType, lc commod.SystemLocationCode) (*Config, error) {
var (
now = time.Now()
c = &Config{
Type: t,
Location: lc,
IsActive: true,
CreatedAt: now,
UpdatedAt: now,
}
)
if err := configColl(nil).FindOne(&c, bson.M{"type": t, "location": lc}); err != nil {
return nil, err
}
if c.ID.IsZero() {
result, err := configColl(nil).InsertOne(&c)
if err != nil {
return nil, err
}
if result.InsertedID == nil {
return nil, errors.New("result.InsertedID is nil")
}
c.ID = result.InsertedID.(primitive.ObjectID)
}
return c, nil
}
func List() ([]*Config, error) {
items := make([]*Config, 0)
return items, configColl(nil).Find(&items, bson.M{"isActive": true})
}
func Edit(filter, update primitive.M) error {
result, err := configColl(nil).UpdateOne(filter, update)
if err != nil {
return err
}
if result.ModifiedCount == 0 {
return errors.New("ModifiedCount is nil")
}
return nil
}
+20
View File
@@ -0,0 +1,20 @@
package systemmod
import (
"time"
"91porn-server/models/commod"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// Config 系统配置
type Config struct {
ID primitive.ObjectID `form:"id" json:"id" bson:"_id,omitempty"` //配置ID
Type commod.SystemConfigType `json:"type" bson:"type" swaggertype:"integer"` //配置类型
Location commod.SystemLocationCode `json:"location" bson:"location" swaggertype:"integer"` //配置位置编号
Content string `json:"content" bson:"content"` //配置内容
IsActive bool `json:"isActive" bson:"isActive"` //是否激活
CreatedAt time.Time `json:"createdAt" bson:"createdAt,omitempty"` //创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` //修改时间
}