@@ -0,0 +1,57 @@
|
||||
package export_task_mod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/models"
|
||||
"encoding/json"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"time"
|
||||
)
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
const table = models.ExportTask
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// CreateTask 新增一个任务
|
||||
func CreateTask(taskType int, admin string, param interface{}) (err error) {
|
||||
b, _ := json.Marshal(param)
|
||||
_, err = coll(nil).InsertOne(&ExportTask{
|
||||
Type: taskType,
|
||||
Param: string(b),
|
||||
Admin: admin,
|
||||
UpdatedAt: time.Now(),
|
||||
CreatedAt: time.Now(),
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetTaskList 拉取需要处理的任务数据
|
||||
func GetTaskList() (list []*ExportTask, err error) {
|
||||
var opts = options.Find()
|
||||
opts.SetLimit(10)
|
||||
opts.SetSort(bson.D{{"createdAt", 1}})
|
||||
err = coll(nil).Find(&list, bson.M{
|
||||
"status": 0,
|
||||
}, opts)
|
||||
return list, err
|
||||
}
|
||||
|
||||
func UpdateTask(id primitive.ObjectID, updateData bson.M) (err error) {
|
||||
_, err = coll(nil).UpdateOne(
|
||||
bson.M{"_id": id},
|
||||
bson.M{"$set": updateData},
|
||||
)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package export_task_mod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 导出任务枚举
|
||||
const (
|
||||
ExportUserTask = 1 // 导出用户列表
|
||||
ExportVidTask = 2 // 导出帖子列表
|
||||
ExportAdvanceOrderTask = 3 // 导出预售订单列表
|
||||
ExportProductHistoryTask = 4 // 会员卡购买记录表
|
||||
)
|
||||
|
||||
type ExportTask struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Type int `json:"type" bson:"type"`
|
||||
Param string `json:"param" bson:"param"`
|
||||
Reason string `json:"reason"` // 失败原因
|
||||
Status int `json:"status" bson:"status"` // 任务状态 0-排队处理中 1-处理完成 2-处理失败
|
||||
FileUrl string `json:"fileUrl"`
|
||||
Admin string `json:"admin" bson:"admin"`
|
||||
Total int64 `json:"total" bson:"total"`
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` //创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` //更新时间
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
}
|
||||
Reference in New Issue
Block a user