init: web_hgdjc_server

This commit is contained in:
2026-11-07 10:46:18 +08:00
commit b2ff6ac8ff
707 changed files with 147645 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
package playletser
import (
"context"
"strings"
"videoweb/app/api/proto"
"videoweb/pub/common/srvdef"
"videoweb/pub/models/playletmod"
"videoweb/pub/models/playletthememod"
"videoweb/pub/models/playlettopicgroupmod"
"go.mongodb.org/mongo-driver/bson"
)
func enabledTopicGroups(ctx context.Context) (playlettopicgroupmod.PlayletTopicGroupList, *srvdef.SrvErr) {
return playlettopicgroupmod.FindMany(ctx, bson.M{"status": true})
}
type topicPlayletCount struct {
Id int64 `bson:"_id"`
Count int64 `bson:"count"`
}
// topicGroupPage 分页查询区块下有已上架短剧的专题
func topicGroupPage(ctx context.Context, group *playlettopicgroupmod.PlayletTopicGroup, skip, limit int64) (playletthememod.PlayletThemeList, map[int64]int64, int64, *srvdef.SrvErr) {
counts := make(map[int64]int64)
if len(group.TopicIds) == 0 {
return playletthememod.PlayletThemeList{}, counts, 0, nil
}
themes, err := playletthememod.FindManyPlayletTheme(ctx, bson.M{
playletthememod.FN.PlayletTheme.Id: bson.M{"$in": group.TopicIds},
playletthememod.FN.PlayletTheme.Status: true,
})
if err != nil {
return nil, nil, 0, err
}
byID := make(map[int64]*playletthememod.PlayletTheme, len(themes))
for _, theme := range themes {
if theme != nil {
byID[theme.Id] = theme
}
}
rows := make([]topicPlayletCount, 0)
err = playletmod.AggregatePlaylet(ctx, &rows, []bson.M{
{"$match": bson.M{playletmod.FN.Playlet.Status: playletmod.StatusUp, playletmod.FN.Playlet.ThemeIds: bson.M{"$in": group.TopicIds}}},
{"$unwind": "$" + playletmod.FN.Playlet.ThemeIds},
{"$match": bson.M{playletmod.FN.Playlet.ThemeIds: bson.M{"$in": group.TopicIds}}},
{"$group": bson.M{"_id": "$" + playletmod.FN.Playlet.ThemeIds, "count": bson.M{"$sum": 1}}},
})
if err != nil {
return nil, nil, 0, err
}
for _, row := range rows {
counts[row.Id] = row.Count
}
available := make(playletthememod.PlayletThemeList, 0, len(themes))
seen := make(map[int64]bool, len(group.TopicIds))
for _, id := range group.TopicIds {
if seen[id] {
continue
}
seen[id] = true
if theme := byID[id]; theme != nil && counts[id] > 0 {
available = append(available, theme)
}
}
total := int64(len(available))
if skip >= total {
return playletthememod.PlayletThemeList{}, counts, total, nil
}
end := skip + limit
if end > total {
end = total
}
return available[skip:end], counts, total, nil
}
// topicGroupPageData 组装区块当前页专题及单部短剧预览
func topicGroupPageData(ctx context.Context, group *playlettopicgroupmod.PlayletTopicGroup, skip, limit int64) (*proto.PlayletTopicGroupPageItem, *srvdef.SrvErr) {
themes, counts, totalCount, err := topicGroupPage(ctx, group, skip, limit)
if err != nil {
return nil, err
}
page := &proto.PlayletTopicGroupPageItem{
Id: group.Id, Name: group.Name, Desc: group.Desc, Rank: group.Rank,
TotalCount: totalCount, List: make([]*proto.PlayletTopicPageItem, 0, len(themes)),
}
if len(themes) == 0 {
return page, nil
}
previewByTheme := make(map[int64]playletmod.PlayletList, len(themes))
previews := make(playletmod.PlayletList, 0, len(themes))
for _, theme := range themes {
filter, sort := playletTopicPagePlayletQuery(0, theme.Id)
list, err := findHomePlaylets(ctx, filter, sort, 1)
if err != nil {
return nil, err
}
previewByTheme[theme.Id] = list
previews = append(previews, list...)
}
themeNameMap, err := buildHomeThemeNameMap(ctx, previews)
if err != nil {
return nil, err
}
tagNameMap, err := buildHomeTagNameMap(ctx, previews)
if err != nil {
return nil, err
}
for _, theme := range themes {
preview := playletsToHomeCommonData(ctx, previewByTheme[theme.Id], themeNameMap, tagNameMap)
covers := make([]string, 0, len(preview))
if len(preview) > 0 {
cover := preview[0].HorizontalCover
if cover == "" {
cover = preview[0].Cover
}
if cover != "" {
covers = append(covers, cover)
}
}
page.List = append(page.List, &proto.PlayletTopicPageItem{
Id: theme.Id, Name: theme.Name, Slug: theme.Slug,
Desc: strings.TrimSpace(theme.SeoInfo.Description),
Icon: withImageDomain(ctx, theme.Icon), Rank: theme.Rank,
PlayletCount: counts[theme.Id], Covers: covers, List: preview,
SeoInfo: buildPageSeoInfoFromValue(theme.SeoInfo, theme.Name, "", buildPlayletThemeListCanonicalURL(theme.Slug, theme.Id)),
})
}
return page, nil
}