Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
package srv_videocreater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/slugx"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/common/utils"
|
||||
"videoweb/pub/models/videocreatermod"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// GetVideoCreaters 按照参数搜索视频标签
|
||||
func GetVideoCreaters(ctx context.Context, param *VideoCreaterReq) (*VideoCreaterResp, *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
opt := &options.FindOptions{}
|
||||
resp := &VideoCreaterResp{}
|
||||
|
||||
opt.SetSort(bson.M{videocreatermod.FN.VideoCreaterInfo.Id: 1})
|
||||
opt.SetSkip((param.PageNum - 1) * param.PageSize).SetLimit(param.PageSize)
|
||||
|
||||
total, serr := videocreatermod.CountVideoCreaterInfos(ctx, filter)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.Total = total
|
||||
if total == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
ads, serr := videocreatermod.FindManyVideoCreaterInfos(ctx, filter, opt)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.List = ads
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// AddVideoCreater 添加一视频标签
|
||||
func AddVideoCreater(ctx context.Context,
|
||||
ac *videocreatermod.VideoCreaterInfo) *srvdef.SrvErr {
|
||||
|
||||
ac.Id = mongos.Lid.VideoCreator.Get()
|
||||
exists := func(s string) bool {
|
||||
doc, _ := videocreatermod.FindOneVideoCreaterInfo(ctx, slugx.Filter(
|
||||
videocreatermod.FN.VideoCreaterInfo.Slug, videocreatermod.FN.VideoCreaterInfo.Id, s, 0))
|
||||
return doc != nil
|
||||
}
|
||||
if serr := slugx.Ensure(&ac.Slug, utils.SlugSourceFromKeywordsOrTitle(ac.SeoInfo.Keyworld, ac.Name), exists); serr != nil {
|
||||
return serr
|
||||
}
|
||||
now := time.Now()
|
||||
ac.CreatedAt = now
|
||||
ac.UpdatedAt = now
|
||||
|
||||
log.Info("InsertOneVideoCreaterInfo", log.Any("", *ac))
|
||||
serr := videocreatermod.InsertOneVideoCreaterInfo(ctx, ac)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelVideoCreater 删除指定视频标签
|
||||
func DelVideoCreater(ctx context.Context, id int64) *srvdef.SrvErr {
|
||||
adFilter := bson.M{videocreatermod.FN.VideoCreaterInfo.Id: id}
|
||||
//删除
|
||||
count, serr := videocreatermod.DelOneVideoCreaterInfo(ctx, adFilter)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
if count == 0 {
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateVideoCreater 更新指定视频标签
|
||||
func UpdateVideoCreater(ctx context.Context, id int64, param VideoCreaterUpdate) *srvdef.SrvErr {
|
||||
now := time.Now()
|
||||
param.UpdatedAt = now
|
||||
|
||||
adFilter := bson.M{videocreatermod.FN.VideoCreaterInfo.Id: id}
|
||||
current, serr := videocreatermod.FindOneVideoCreaterInfo(ctx, adFilter)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
name := current.Name
|
||||
if param.Name != nil {
|
||||
name = *param.Name
|
||||
}
|
||||
keywords := current.SeoInfo.Keyworld
|
||||
if param.SeoInfo != nil {
|
||||
keywords = param.SeoInfo.Keyworld
|
||||
}
|
||||
exists := func(s string) bool {
|
||||
doc, _ := videocreatermod.FindOneVideoCreaterInfo(ctx, slugx.Filter(
|
||||
videocreatermod.FN.VideoCreaterInfo.Slug, videocreatermod.FN.VideoCreaterInfo.Id, s, id))
|
||||
return doc != nil
|
||||
}
|
||||
slug, changed, serr := slugx.PrepareOnUpdate(current.Slug, param.Slug,
|
||||
utils.SlugSourceFromKeywordsOrTitle(keywords, name), exists)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
if changed {
|
||||
param.Slug = &slug
|
||||
} else {
|
||||
param.Slug = nil
|
||||
}
|
||||
param.IndexNow = nil
|
||||
if param.IsReIndexNow != nil && *param.IsReIndexNow {
|
||||
indexNow := int64(0)
|
||||
param.IndexNow = &indexNow
|
||||
}
|
||||
updateDoc := bson.M{"$set": param}
|
||||
serr = videocreatermod.UpdateOneVideoCreaterInfo(ctx, adFilter, updateDoc)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user