@@ -0,0 +1,210 @@
|
||||
package userser
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/pageopt"
|
||||
"91porn-server/models/v/reptmod"
|
||||
"91porn-server/models/v/tagmod"
|
||||
"91porn-server/models/v/usermod"
|
||||
"91porn-server/models/v/vidmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type Matcher = pageopt.Matcher
|
||||
|
||||
type UIDMatch = pageopt.UIDMatch
|
||||
|
||||
// M M from Map
|
||||
type M = bson.M
|
||||
|
||||
// D D from Doc
|
||||
type D = bson.D
|
||||
|
||||
// A A from Array
|
||||
type A = []interface{}
|
||||
|
||||
type ObjectID = primitive.ObjectID
|
||||
|
||||
type Tag struct {
|
||||
ID *ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
|
||||
Name *string `json:"name,omitempty" bson:"tagName,omitempty"` //标签名
|
||||
}
|
||||
|
||||
type Video struct {
|
||||
Title *string `json:"title,omitempty"` //标题
|
||||
PublisherID *uint64 `json:"publisherID,omitempty"` //发布者ID
|
||||
HasLocked bool `json:"hasLocked"` //发布者是否被封禁
|
||||
Cover *string `json:"cover,omitempty"` //封面
|
||||
SourceURL *string `json:"sourceURL,omitempty"` //资源地址
|
||||
SourceID *string `json:"sourceID,omitempty"` //资源ID
|
||||
Tags []Tag `json:"tags,omitempty"` //标签
|
||||
}
|
||||
|
||||
type Comment struct {
|
||||
ID *ObjectID `json:"id,omitempty"` //_id
|
||||
UID *uint64 `json:"uid,omitempty"` //发表评论的 用户ID
|
||||
Content *string `json:"content,omitempty"` //内容
|
||||
}
|
||||
|
||||
type ReportedUser struct {
|
||||
UID *uint64 `json:"uid,omitempty"` //被举报对用户ID
|
||||
HasLocked *bool `json:"hasLocked,omitempty"` //已禁止登陆
|
||||
HasBanned *bool `json:"hasBanned,omitempty"` //已禁言
|
||||
}
|
||||
|
||||
type ReportInfoDoc struct {
|
||||
ID *ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
|
||||
UID *uint64 `json:"uid,omitempty" bson:"uid,omitempty"` //举报者ID
|
||||
ObjType *reptmod.ReportObjType `json:"objType,omitempty" bson:"objType,omitempty"` //举报对象类型
|
||||
ObjID *ObjectID `json:"objID,omitempty" bson:"objID,omitempty"` //举报对象ID
|
||||
Types *string `json:"types,omitempty" bson:"types,omitempty"` //举报分类
|
||||
CreatedAt *time.Time `json:"createdAt,omitempty" bson:"createdAt,omitempty"` //举报时间
|
||||
Video Video `json:"video,omitempty" bson:"video,omitempty"` //视屏信息
|
||||
Comment Comment `json:"comment,omitempty" bson:"comment,omitempty"` //评论信息
|
||||
ReportedUser ReportedUser `json:"reportedUser,omitempty" bson:"reportedUser,omitempty"` //被举报的用户
|
||||
ReptStatus *bool `json:"reptStatus,omitempty" bson:"reptStatus,omitempty"` //举报状态
|
||||
}
|
||||
|
||||
type ReportInfoPage struct {
|
||||
Total int64 `json:"total" bson:"total"`
|
||||
List []ReportInfoDoc `json:"list" bson:"list"`
|
||||
}
|
||||
|
||||
func ReportInfoPages(typesArray []reptmod.ReportObjType, sort D, skip int64, limit int64, uidMatch UIDMatch, typesMatch reptmod.TypesMatch, createdAtMatch reptmod.CreatedAtGTEAndLTMatch) (ReportInfoPage, error) {
|
||||
inObjTypeMatch := reptmod.InObjTypeMatch{Typs: typesArray}
|
||||
matList := []Matcher{
|
||||
inObjTypeMatch.New(),
|
||||
uidMatch.New(),
|
||||
typesMatch.New(),
|
||||
createdAtMatch.New(),
|
||||
}
|
||||
list, err := reptmod.List(sort, skip, limit, matList...)
|
||||
if err != nil {
|
||||
return ReportInfoPage{}, err
|
||||
}
|
||||
reportList, err := toReportInfoDocList(list)
|
||||
if err != nil {
|
||||
return ReportInfoPage{}, err
|
||||
}
|
||||
count, err := reptmod.Count(matList...)
|
||||
if err != nil {
|
||||
return ReportInfoPage{}, err
|
||||
}
|
||||
page := ReportInfoPage{
|
||||
Total: count,
|
||||
List: reportList,
|
||||
}
|
||||
return page, nil
|
||||
}
|
||||
|
||||
func fillUser(doc *ReportInfoDoc, userMap map[uint64]*usermod.BaseInfo) {
|
||||
if doc.ObjType == nil {
|
||||
return
|
||||
}
|
||||
if *doc.ObjType != reptmod.User {
|
||||
return
|
||||
}
|
||||
ruid := doc.ReportedUser.UID
|
||||
if ruid == nil {
|
||||
return
|
||||
}
|
||||
user, ok := userMap[*ruid]
|
||||
if ok {
|
||||
doc.ReportedUser.HasLocked = &user.HasLocked
|
||||
doc.ReportedUser.HasBanned = &user.HasBanned
|
||||
}
|
||||
}
|
||||
|
||||
func fillVideo(doc *ReportInfoDoc, videoMap map[ObjectID]*vidmod.VideoModel, userMap map[uint64]*usermod.BaseInfo) {
|
||||
if doc.ObjType == nil {
|
||||
return
|
||||
}
|
||||
if *doc.ObjType != reptmod.Video {
|
||||
return
|
||||
}
|
||||
vid := doc.ObjID
|
||||
if vid == nil {
|
||||
return
|
||||
}
|
||||
video, ok := videoMap[*vid]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
publishID := video.PublisherID
|
||||
hasLocked := false
|
||||
user, ok := userMap[publishID]
|
||||
if ok {
|
||||
hasLocked = user.HasLocked
|
||||
}
|
||||
doc.Video.Title = &video.Title
|
||||
doc.Video.Cover = &video.Cover
|
||||
doc.Video.SourceURL = &video.SourceURL
|
||||
doc.Video.SourceID = &video.SourceID
|
||||
doc.Video.PublisherID = &publishID
|
||||
doc.Video.HasLocked = hasLocked
|
||||
tagMap, err := tagmod.TagMap(video.Tags)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tagList := make([]Tag, len(tagMap))
|
||||
i := 0
|
||||
for _, tag := range tagMap {
|
||||
tagList[i] = Tag{ID: &tag.ID, Name: &tag.TagName}
|
||||
i++
|
||||
}
|
||||
doc.Video.Tags = tagList
|
||||
}
|
||||
|
||||
func toReportInfoDocList(reportList []reptmod.Report) ([]ReportInfoDoc, error) {
|
||||
reportListLen := len(reportList)
|
||||
uidList := make([]uint64, reportListLen)
|
||||
vidList := make([]ObjectID, 0, reportListLen)
|
||||
for i, v := range reportList {
|
||||
uidList[i] = v.UID
|
||||
switch v.ObjType {
|
||||
case reptmod.User:
|
||||
if v.ObjUID != nil {
|
||||
uidList = append(uidList, *v.ObjUID)
|
||||
}
|
||||
case reptmod.Video:
|
||||
if v.ObjID != nil {
|
||||
vidList = append(vidList, *v.ObjID)
|
||||
}
|
||||
}
|
||||
}
|
||||
videoMap, err := vidmod.VideoMap(vidList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//同时查询发布视频者的信息
|
||||
for _, v := range videoMap {
|
||||
uidList = append(uidList, v.PublisherID)
|
||||
}
|
||||
userMap, err := usermod.GetUsersBaseInfoMap(uidList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
docList := make([]ReportInfoDoc, len(reportList))
|
||||
for i, v := range reportList {
|
||||
_v := v
|
||||
doc := ReportInfoDoc{
|
||||
ID: &_v.ID,
|
||||
ObjType: &_v.ObjType,
|
||||
UID: &_v.UID,
|
||||
ReportedUser: ReportedUser{
|
||||
UID: _v.ObjUID,
|
||||
},
|
||||
ObjID: _v.ObjID,
|
||||
Types: &_v.Types,
|
||||
ReptStatus: &_v.Status,
|
||||
CreatedAt: &_v.CreatedAt,
|
||||
}
|
||||
fillUser(&doc, userMap)
|
||||
fillVideo(&doc, videoMap, userMap)
|
||||
docList[i] = doc
|
||||
}
|
||||
return docList, nil
|
||||
}
|
||||
Reference in New Issue
Block a user