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
+70
View File
@@ -0,0 +1,70 @@
package operationlogmod
import (
"fmt"
"time"
"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.OperationLog
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
func initIndex() {
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
{
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(l OperationLog) error {
l.CreatedAt = time.Now()
if _, err := coll(nil).InsertOne(l); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Insert", table, "InsertOne", err))
return err
}
return nil
}
func InsertMany(logs []OperationLog) error {
_, err := coll(nil).InsertMany(logs)
return err
}
// FindMany
func FindManyOperationLog(filter bson.M, opts *options.FindOptions) (data []OperationLog, err error) {
err = coll(nil).Find(&data, filter, opts)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "FindManyOperationLog", table, "FindMany", err), log.Any("blockType", filter))
return
}
return
}
func Count(query bson.M) (total int64) {
total, err := coll(nil).Count(query)
if err != nil {
log.Error("models operationLog Count error", log.E(err))
return
}
return
}
+28
View File
@@ -0,0 +1,28 @@
package operationlogmod
import (
"time"
"91porn-server/common/db"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// @table:operation_log
type OperationLog struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
UserID int64 `json:"userID" bson:"userID"` //用户ID
OperationAPI string `json:"operationAPI" bson:"operationAPI"` //操作类型
OperationType int `json:"operationType" bson:"operationType"` //操作类型
BeforeContent string `json:"beforeContent" bson:"beforeContent"` //操作前内容
AfterContent string `json:"afterContent" bson:"afterContent"` //操作后内容
Reason string `json:"reason" bson:"reason"` //操作原因
CreatedUser string `json:"createdUser" bson:"createdUser" binding:"required"` //创建人
CreatedID int64 `json:"createdID" bson:"createdID" binding:"required"` //创建人id
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
}
func Init() {
mdb = db.Init(table)
initIndex()
}
+17
View File
@@ -0,0 +1,17 @@
package operationlogmod
import "time"
// GetOperationLogListReq 获取帖子、用户操作日志列表 请求数据
type GetOperationLogListReq struct {
UserID *int64 `form:"userID,omitempty" json:"userID,omitempty" bson:"userID,omitempty"` //用户ID
Content *string `form:"content,omitempty" json:"content,omitempty" bson:"content,omitempty"` //操作内容
CreatedUser *string `form:"createdUser,omitempty" json:"createdUser,omitempty" bson:"createdUser,omitempty"` //操作人
CreatedAt *time.Time `form:"createdAt,omitempty" json:"createdAt,omitempty" bson:"createdAt,omitempty"` //操作时间
}
// GetOperationLogListResp 获取帖子、用户操作日志列表 回复数据
type GetOperationLogListResp struct {
Total int64 `json:"total" bson:"total"`
List []OperationLog `json:"list" bson:"list"`
}