Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
102 lines
2.5 KiB
Go
102 lines
2.5 KiB
Go
package srv_videocreater
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
"videoweb/pub/common/log"
|
|
"videoweb/pub/common/srvdef"
|
|
"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{}
|
|
if param.ID > 0 {
|
|
filter[videocreatermod.FN.VideoCreaterInfo.Id] = param.ID
|
|
}
|
|
if param.Name != "" {
|
|
filter[videocreatermod.FN.VideoCreaterInfo.Name] = bson.M{
|
|
"$regex": param.Name,
|
|
}
|
|
}
|
|
|
|
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()
|
|
now := time.Now()
|
|
ac.CreatedAt = now
|
|
ac.UpdatedAt = now
|
|
|
|
if ac.Name == "" {
|
|
return srvdef.New(srvdef.ErrParamError, "", "")
|
|
}
|
|
|
|
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}
|
|
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
|
|
}
|