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
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package srv_videocreater
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/models/videocreatermod"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
type VideoCreaterReq struct {
|
||||
pubdef.Page
|
||||
}
|
||||
type VideoCreaterResp struct {
|
||||
Total int64 `json:"total"`
|
||||
List videocreatermod.VideoCreaterInfoList `json:"list"`
|
||||
}
|
||||
type VideoCreaterUpdate struct {
|
||||
AppId *int32 `json:"appId" bson:"appId,omitempty"` // appId,唯一id
|
||||
Name *string `json:"name" bson:"name,omitempty"` // 名称
|
||||
Slug *string `json:"slug" bson:"slug,omitempty"` // slug
|
||||
Status *bool `json:"status" bson:"status,omitempty"` // 上架状态
|
||||
Sort *int64 `json:"sort" bson:"sort,omitempty"` // 排序
|
||||
SeoInfo *pubdef.SeoValue `json:"seoInfo" bson:"seoInfo,omitempty"` // Seo相关信息
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"`
|
||||
IsReIndexNow *bool `json:"isReIndexNow" bson:"isReIndexNow"` // 是否重新提交索引
|
||||
MediaTypes *[]int64 `json:"mediaTypes" bson:"mediaTypes"` // 作者关联的资源类型 1视频
|
||||
IndexNow *int64 `bson:"indexNow,omitempty" json:"-"`
|
||||
Works *int64 `json:"works" bson:"works,omitempty"` // 作品数量
|
||||
Image *string `json:"image" bson:"image,omitempty"` // 头像
|
||||
Background *string `json:"background" bson:"background,omitempty"` // 背景
|
||||
CreateType *int64 `json:"createType" bson:"createType,omitempty"` // 创作者类型 0=普通 1=官方
|
||||
Desc *string `json:"desc" bson:"desc,omitempty"` // 简介
|
||||
}
|
||||
type VideoCreaterUpdateReq struct {
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
Param VideoCreaterUpdate `json:"param" bson:"param"` // appId,唯一id
|
||||
}
|
||||
|
||||
type VideoCreaterDelReq struct {
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
}
|
||||
Reference in New Issue
Block a user