@@ -0,0 +1,219 @@
|
||||
package export_task
|
||||
|
||||
import (
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models/v/export_task_mod"
|
||||
"91porn-server/models/v/modulevidmod"
|
||||
"91porn-server/models/v/tagmod"
|
||||
"91porn-server/models/v/vidmod"
|
||||
"91porn-server/web/vidhelp"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ExecExportVideoTask(task *export_task_mod.ExportTask) (total int64, err error) {
|
||||
arg := vidmod.ListReq{}
|
||||
err = json.Unmarshal([]byte(task.Param), &arg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cond, err := assembleConditions(arg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
secID, cond, _, err := dealVidListCond(cond)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var skip int64
|
||||
var size int64 = 100
|
||||
index := 1
|
||||
path := fmt.Sprintf("./temp/%v%v", "帖子列表-", task.ID.Hex())
|
||||
zipName := fmt.Sprintf("%v_%v_帖子列表_%v.zip", task.Admin, GetProName(), task.CreatedAt.Format("2006-01-02_15:04:05"))
|
||||
var records []*vidmod.WebVideo
|
||||
excelList := []string{}
|
||||
for {
|
||||
fmt.Println("skip", skip, " now ", time.Now().Format("2006-01-02 15:04:05"))
|
||||
list, err := vidmod.ExportFindMany(cond, skip, size)
|
||||
if err != nil {
|
||||
log.Error("ExecExportVideoTask vidmod.ExportFindMany fail", log.E(err))
|
||||
return total, err
|
||||
}
|
||||
infos, err := vidhelp.EncodeVideoInfo(list, secID)
|
||||
if err != nil {
|
||||
log.Error("ExecExportVideoTask vidhelp.EncodeVideoInfo fail", log.E(err))
|
||||
return total, err
|
||||
}
|
||||
records = append(records, infos...)
|
||||
var fileName = fmt.Sprintf("帖子列表_%v.xlsx", index)
|
||||
if len(records) >= maxDataNum {
|
||||
// 获取到的数据已经达到了单文件最大限制数据量
|
||||
filePath, err := SaveExcel(records, path, fileName)
|
||||
if err != nil {
|
||||
log.Error("ExecExportVideoTask SaveExcel fail", log.E(err))
|
||||
return total, err
|
||||
}
|
||||
// 重新归0
|
||||
records = []*vidmod.WebVideo{}
|
||||
index = index + 1
|
||||
excelList = append(excelList, filePath)
|
||||
fmt.Println("index:", index)
|
||||
total = total + int64(len(records))
|
||||
} else if len(list) < int(size) {
|
||||
if len(records) > 0 {
|
||||
// 数据库已经取不到更多的数据了
|
||||
filePath, err := SaveExcel(records, path, fileName)
|
||||
if err != nil {
|
||||
log.Error("ExecExportVideoTask SaveExcel fail", log.E(err))
|
||||
return total, err
|
||||
}
|
||||
excelList = append(excelList, filePath)
|
||||
total = total + int64(len(records))
|
||||
}
|
||||
// 结束循环
|
||||
break
|
||||
}
|
||||
skip = skip + size
|
||||
}
|
||||
|
||||
// 发送到tg
|
||||
err = SendTg(task.Admin, excelList, zipName)
|
||||
if err != nil {
|
||||
log.Error("ExecExportVideoTask SendTg fail", log.E(err))
|
||||
return
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
func dealVidListCond(cond bson.M) (primitive.ObjectID, bson.M, []primitive.ObjectID, error) {
|
||||
var secID primitive.ObjectID
|
||||
var err error
|
||||
sectionID, ok := cond["sectionID"]
|
||||
if ok {
|
||||
secID, err = primitive.ObjectIDFromHex(sectionID.(string))
|
||||
if err != nil {
|
||||
log.Error("primitive.ObjectIDFromHex", log.Any("sectionID", sectionID), log.E(err))
|
||||
return secID, cond, nil, err
|
||||
}
|
||||
var flag bool
|
||||
isSorted, ok := cond["isSortedUnderModule"]
|
||||
if ok {
|
||||
flag = isSorted.(bool)
|
||||
}
|
||||
videoIDs, err := modulevidmod.GetBySectionID(secID, flag)
|
||||
if err != nil {
|
||||
return secID, cond, nil, err
|
||||
}
|
||||
cond["_id"] = bson.M{"$in": videoIDs}
|
||||
delete(cond, "sectionID")
|
||||
delete(cond, "isSortedUnderModule")
|
||||
return secID, cond, videoIDs, nil
|
||||
}
|
||||
delete(cond, "sectionID")
|
||||
delete(cond, "isSortedUnderModule")
|
||||
return secID, cond, nil, nil
|
||||
}
|
||||
|
||||
func assembleConditions(req vidmod.ListReq) (m map[string]interface{}, err error) {
|
||||
m = make(map[string]interface{})
|
||||
if req.ShowType != nil {
|
||||
m["showType"] = *req.ShowType
|
||||
}
|
||||
if req.Status != 4 {
|
||||
if req.Status == 7 {
|
||||
m["status"] = map[string]int{"$gt": 0}
|
||||
} else {
|
||||
m["status"] = req.Status
|
||||
}
|
||||
}
|
||||
if req.IsFree == 0 {
|
||||
m["coins"] = map[string]int{"$gt": 0}
|
||||
}
|
||||
if req.IsFree == 1 {
|
||||
m["coins"] = map[string]int{"$eq": 0}
|
||||
}
|
||||
if req.IsUserUp == 2 {
|
||||
m["publisherID"] = map[string]int{"$lt": 115000}
|
||||
}
|
||||
if req.IsUserUp == 1 {
|
||||
m["publisherID"] = map[string]int{"$gt": 115000}
|
||||
}
|
||||
if len(req.Title) != 0 {
|
||||
m["title"] = map[string]string{"$regex": req.Title, "$options": "i"}
|
||||
}
|
||||
if req.UID > 0 {
|
||||
m["publisherID"] = req.UID
|
||||
}
|
||||
if req.Chosen == 1 {
|
||||
m["chosen"] = true
|
||||
}
|
||||
if req.Chosen == 2 {
|
||||
m["chosen"] = false
|
||||
}
|
||||
if req.FreeArea == 1 {
|
||||
m["freeArea"] = true
|
||||
}
|
||||
if req.FreeArea == 2 {
|
||||
m["freeArea"] = false
|
||||
}
|
||||
if !req.End.IsZero() {
|
||||
m["createdAt"] = map[string]time.Time{"$gte": req.Start, "$lt": req.End}
|
||||
}
|
||||
if len(req.Tag) != 0 {
|
||||
id, err := tagmod.GetTagIDByName(req.Tag)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
m["tags"] = id
|
||||
}
|
||||
if len(req.ID) != 0 {
|
||||
oid, err := primitive.ObjectIDFromHex(req.ID)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
m["_id"] = oid
|
||||
}
|
||||
//通过初始价格判断是否是马甲账号
|
||||
if req.IsPretendAcc == 1 {
|
||||
m["coins"] = vidmod.PretendAccInitCoins
|
||||
}
|
||||
if req.IsPretendAcc == 2 {
|
||||
//i := make(map[string]int64)
|
||||
//i["$ne"] = vidmod.PretendAccInitCoins
|
||||
m["coins"] = map[string]int64{"$ne": vidmod.PretendAccInitCoins}
|
||||
}
|
||||
m["deleteAt"] = bson.M{"$exists": false}
|
||||
if req.NewsType != "" {
|
||||
m["newsType"] = req.NewsType
|
||||
}
|
||||
|
||||
if req.LiaoBaTop != nil {
|
||||
m["liaoBaTop"] = *req.LiaoBaTop
|
||||
}
|
||||
if req.SectionID != "" {
|
||||
m["sectionID"] = req.SectionID
|
||||
}
|
||||
m["isSortedUnderModule"] = req.IsSortedUnderModule
|
||||
if req.IsRecommended != nil {
|
||||
if *req.IsRecommended {
|
||||
m["recoWeight"] = bson.M{"$gte": 0}
|
||||
} else {
|
||||
m["recoWeight"] = bson.M{"$lt": 0}
|
||||
}
|
||||
}
|
||||
if req.Key == "likeRate" || req.Key == "purchaseRate" {
|
||||
m[req.Key] = req.Value
|
||||
}
|
||||
if req.IsHappinessPlazaTop != nil && *req.IsHappinessPlazaTop {
|
||||
if *req.IsHappinessPlazaTop {
|
||||
m["happinessPlazaTop"] = bson.M{"$gt": 0}
|
||||
} else {
|
||||
m["happinessPlazaTop"] = bson.M{"$lte": 0}
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
Reference in New Issue
Block a user