@@ -0,0 +1,154 @@
|
||||
package vidser
|
||||
|
||||
import (
|
||||
"91porn-server/app/service/mediaser"
|
||||
"91porn-server/common/constant"
|
||||
"91porn-server/common/elastic"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models/v/mediamod"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (in *LibraryElasticSearchRequest) MediaLibrarySearch() (AppElasticSearchLibraryResponse, error) {
|
||||
resp := AppElasticSearchLibraryResponse{}
|
||||
from := int64((in.PageNumber - 1) * (in.PageSize))
|
||||
size := int64(in.PageSize + 1)
|
||||
|
||||
must := elastic.A{
|
||||
{"term": elastic.M{"mediaType.keyword": HandleMediaCanvasType(in.Keyword.Canvas.Key)}},
|
||||
}
|
||||
if in.Keyword.Tags.ID != "" {
|
||||
tag := elastic.M{"term": elastic.M{"tags.keyword": in.Keyword.Tags.ID}}
|
||||
must = append(must, tag)
|
||||
}
|
||||
timeType := HandleMediaTimeType(in.Keyword.TimeType.Key)
|
||||
must = append(must, timeType...)
|
||||
|
||||
payType := HandleMediaPayType(in.Keyword.PaymentType.Key)
|
||||
must = append(must, payType...)
|
||||
short := HandleMediaShort(in.Keyword.OrderBy.Key)
|
||||
// 根据数据结构组装数据
|
||||
query := elastic.M{
|
||||
"query": elastic.M{
|
||||
"bool": elastic.M{
|
||||
"must": must,
|
||||
},
|
||||
},
|
||||
"sort": short,
|
||||
"from": from,
|
||||
"size": size,
|
||||
}
|
||||
|
||||
res, err := mediamod.SearchByCondWithTotal(query)
|
||||
if err != nil {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
if uint64(len(res.Hits)) > in.PageSize {
|
||||
res.Hits = res.Hits[:in.PageSize]
|
||||
resp.HasNext = true
|
||||
}
|
||||
mIds := make([]primitive.ObjectID, len(res.Hits))
|
||||
for i, v := range res.Hits {
|
||||
if !v.Source.ID.IsZero() {
|
||||
mIds[i] = v.Source.ID
|
||||
}
|
||||
}
|
||||
// 漫画、动漫、文字小说、有声小说
|
||||
filter := bson.M{"_id": bson.M{"$in": mIds}, "status": 1}
|
||||
op := options.Find().SetSort(bson.D{{Key: "sectionSort", Value: -1}, {Key: "createdAt", Value: -1}})
|
||||
mediaBases, err := mediamod.QueryMediaByCond(filter, op)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("mediaLibrarySearch mediamod.QueryMediaByCond err:%v", err))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(mediaBases) == 0 {
|
||||
log.Warn("mediaLibrarySearch no video info")
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
ret := mediaser.FillMedias(mediaBases, in.UID, true)
|
||||
resp.AllMediaList = ret
|
||||
resp.Total = res.Total.Value
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func HandleMediaTimeType(key string) elastic.A {
|
||||
var timeTypeValue = elastic.A{}
|
||||
now := time.Now()
|
||||
switch key {
|
||||
case "1":
|
||||
timeTypeValue = append(timeTypeValue,
|
||||
elastic.M{"range": elastic.M{"createdAt": elastic.M{"gt": now.AddDate(0, -1, 0)}}},
|
||||
)
|
||||
case "2":
|
||||
timeTypeValue = append(timeTypeValue,
|
||||
elastic.M{"range": elastic.M{"createdAt": elastic.M{"gt": now.AddDate(0, -3, 0), "lt": now.AddDate(0, -1, 0)}}},
|
||||
)
|
||||
case "3":
|
||||
timeTypeValue = append(timeTypeValue,
|
||||
elastic.M{"range": elastic.M{"createdAt": elastic.M{"gt": now.AddDate(0, -6, 0), "lt": now.AddDate(0, -3, 0)}}},
|
||||
)
|
||||
case "4":
|
||||
timeTypeValue = append(timeTypeValue,
|
||||
elastic.M{"range": elastic.M{"createdAt": elastic.M{"gt": now.AddDate(-5, 0, 0), "lt": now.AddDate(0, -6, 0)}}},
|
||||
)
|
||||
default:
|
||||
timeTypeValue = append(timeTypeValue,
|
||||
elastic.M{"range": elastic.M{"createdAt": elastic.M{"gt": now.AddDate(-3, -2, 0)}}},
|
||||
)
|
||||
}
|
||||
return timeTypeValue
|
||||
}
|
||||
|
||||
func HandleMediaPayType(key string) elastic.A {
|
||||
var payTypeValue = elastic.A{}
|
||||
switch key {
|
||||
case "free":
|
||||
payTypeValue = append(payTypeValue,
|
||||
elastic.M{"term": elastic.M{"permission": 2}},
|
||||
)
|
||||
case "vip":
|
||||
payTypeValue = append(payTypeValue,
|
||||
elastic.M{"term": elastic.M{"permission": 0}},
|
||||
)
|
||||
case "point":
|
||||
payTypeValue = append(payTypeValue,
|
||||
elastic.M{"term": elastic.M{"permission": 1}},
|
||||
)
|
||||
default:
|
||||
payTypeValue = append(payTypeValue, elastic.M{"terms": elastic.M{"permission": []int{0, 1, 2}}})
|
||||
}
|
||||
return payTypeValue
|
||||
}
|
||||
|
||||
func HandleMediaShort(key string) elastic.A {
|
||||
var payTypeValue elastic.A
|
||||
switch key {
|
||||
case "playNum":
|
||||
payTypeValue = elastic.A{{"countBrowse": elastic.M{"order": "desc"}}}
|
||||
case "love":
|
||||
payTypeValue = elastic.A{{"countCollect": elastic.M{"order": "desc"}}}
|
||||
case "new":
|
||||
payTypeValue = elastic.A{{"createdAt": elastic.M{"order": "desc"}}}
|
||||
default:
|
||||
payTypeValue = elastic.A{{"countBrowse": elastic.M{"order": "desc"}}, {"createdAt": elastic.M{"order": "desc"}}}
|
||||
}
|
||||
return payTypeValue
|
||||
}
|
||||
|
||||
func HandleMediaCanvasType(key string) string {
|
||||
var moduleTypeValue string
|
||||
switch key {
|
||||
case constant.Cartoon, constant.Comics:
|
||||
moduleTypeValue = key
|
||||
default:
|
||||
moduleTypeValue = constant.Text
|
||||
}
|
||||
return moduleTypeValue
|
||||
}
|
||||
Reference in New Issue
Block a user