init: 初始化 web_hgdjb_server 项目
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
package srv_videotopic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/videotopicmod"
|
||||
"videoweb/pub/mongos"
|
||||
"videoweb/web/service/srv_videoslug"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// GetVideoTopics 按照参数搜索视频分类
|
||||
func GetVideoTopics(ctx context.Context, param *VideoTopicReq) (*VideoTopicResp, *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
if param.VideoCategoryId != nil {
|
||||
filter[videotopicmod.FN.VideoTopicModel.VideoCategoryId] = *param.VideoCategoryId
|
||||
}
|
||||
opt := &options.FindOptions{}
|
||||
resp := &VideoTopicResp{}
|
||||
|
||||
opt.SetSort(bson.M{videotopicmod.FN.VideoTopicModel.Rank: -1})
|
||||
opt.SetSkip((param.PageNum - 1) * param.PageSize).SetLimit(param.PageSize)
|
||||
|
||||
total, serr := videotopicmod.CountVideoTopicModels(ctx, filter)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.Total = total
|
||||
if total == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
ads, serr := videotopicmod.FindManyVideoTopicModels(ctx, filter, opt)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.List = ads
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// AddVideoTopic 添加一个视频分类
|
||||
func AddVideoTopic(ctx context.Context,
|
||||
ac *videotopicmod.VideoTopicModel) *srvdef.SrvErr {
|
||||
|
||||
ac.Id = mongos.Lid.VideoTopic.Get()
|
||||
now := time.Now()
|
||||
ac.CreatedAt = now
|
||||
ac.UpdatedAt = now
|
||||
if serr := srv_videoslug.EnsureTopic(ctx, ac, 0); serr != nil {
|
||||
return serr
|
||||
}
|
||||
|
||||
serr := videotopicmod.InsertOneVideoTopicModel(ctx, ac)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelVideoTopic 删除指定视频分类
|
||||
func DelVideoTopic(ctx context.Context, id int64) *srvdef.SrvErr {
|
||||
adFilter := bson.M{videotopicmod.FN.VideoTopicModel.Id: id}
|
||||
//删除
|
||||
count, serr := videotopicmod.DelOneVideoTopicModel(ctx, adFilter)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
if count == 0 {
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateVideoTopic 更新指定视频分类
|
||||
func UpdateVideoTopic(ctx context.Context, id int64, param VideoTopicUpdate) *srvdef.SrvErr {
|
||||
now := time.Now()
|
||||
param.UpdatedAt = now
|
||||
|
||||
info, serr := videotopicmod.FindOneVideoTopicModel(ctx, bson.M{videotopicmod.FN.VideoTopicModel.Id: id})
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
name := info.Name
|
||||
if param.Name != nil {
|
||||
name = *param.Name
|
||||
}
|
||||
keywords := info.SeoInfo.Keyworld
|
||||
if param.SeoInfo != nil {
|
||||
keywords = param.SeoInfo.Keyworld
|
||||
}
|
||||
slug, changed, slugErr := srv_videoslug.PrepareTopicOnUpdate(ctx, info, param.Slug, name, keywords)
|
||||
if slugErr != nil {
|
||||
return slugErr
|
||||
}
|
||||
if changed {
|
||||
param.Slug = &slug
|
||||
} else {
|
||||
param.Slug = nil
|
||||
}
|
||||
|
||||
adFilter := bson.M{videotopicmod.FN.VideoTopicModel.Id: id}
|
||||
param.IndexNow = nil
|
||||
if param.IsReIndexNow != nil && *param.IsReIndexNow {
|
||||
indexNow := int64(0)
|
||||
param.IndexNow = &indexNow
|
||||
}
|
||||
updateDoc := bson.M{"$set": param}
|
||||
serr = videotopicmod.UpdateOneVideoTopicModel(ctx, adFilter, updateDoc)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user