@@ -0,0 +1,126 @@
|
||||
package srv_videocategory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/videocategorymod"
|
||||
"videoweb/pub/mongos"
|
||||
"videoweb/web/service/srv_videoslug"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// GetVideoCategorys 按照参数搜索视频分类
|
||||
func GetVideoCategorys(ctx context.Context, param *VideoCategoryReq) (*VideoCategoryResp, *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
opt := &options.FindOptions{}
|
||||
resp := &VideoCategoryResp{}
|
||||
if param.ID > 0 {
|
||||
filter[videocategorymod.FN.VideoCategory.Id] = param.ID
|
||||
}
|
||||
if param.Name != "" {
|
||||
filter[videocategorymod.FN.VideoCategory.Name] = bson.M{
|
||||
"$regex": param.Name,
|
||||
}
|
||||
}
|
||||
|
||||
opt.SetSort(bson.M{videocategorymod.FN.VideoCategory.Rank: -1})
|
||||
opt.SetSkip((param.PageNum - 1) * param.PageSize).SetLimit(param.PageSize)
|
||||
|
||||
total, serr := videocategorymod.CountVideoCategorys(ctx, filter)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.Total = total
|
||||
if total == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
ads, serr := videocategorymod.FindManyVideoCategorys(ctx, filter, opt)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.List = ads
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// AddVideoCategory 添加一个视频分类
|
||||
func AddVideoCategory(ctx context.Context,
|
||||
ac *videocategorymod.VideoCategory) *srvdef.SrvErr {
|
||||
|
||||
ac.Id = mongos.Lid.VideoCategory.Get()
|
||||
now := time.Now()
|
||||
ac.CreatedAt = now
|
||||
ac.UpdatedAt = now
|
||||
|
||||
if ac.Name == "" {
|
||||
return srvdef.New(srvdef.ErrParamError, "", "")
|
||||
}
|
||||
if serr := srv_videoslug.EnsureCategory(ctx, ac, 0); serr != nil {
|
||||
return serr
|
||||
}
|
||||
|
||||
serr := videocategorymod.InsertOneVideoCategory(ctx, ac)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelVideoCategory 删除指定视频分类
|
||||
func DelVideoCategory(ctx context.Context, id int64) *srvdef.SrvErr {
|
||||
adFilter := bson.M{videocategorymod.FN.VideoCategory.Id: id}
|
||||
//删除
|
||||
count, serr := videocategorymod.DelOneVideoCategory(ctx, adFilter)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
if count == 0 {
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateVideoCategory 更新指定视频分类
|
||||
func UpdateVideoCategory(ctx context.Context, id int64, param VideoCategoryUpdate) *srvdef.SrvErr {
|
||||
now := time.Now()
|
||||
param.UpdatedAt = now
|
||||
|
||||
info, serr := videocategorymod.FindOneVideoCategory(ctx, bson.M{videocategorymod.FN.VideoCategory.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.PrepareCategoryOnUpdate(ctx, info, param.Slug, name, keywords)
|
||||
if slugErr != nil {
|
||||
return slugErr
|
||||
}
|
||||
if changed {
|
||||
param.Slug = &slug
|
||||
} else {
|
||||
param.Slug = nil
|
||||
}
|
||||
|
||||
adFilter := bson.M{videocategorymod.FN.VideoCategory.Id: id}
|
||||
param.IndexNow = nil
|
||||
if param.IsReIndexNow != nil && *param.IsReIndexNow {
|
||||
indexNow := int64(0)
|
||||
param.IndexNow = &indexNow
|
||||
}
|
||||
|
||||
updateDoc := bson.M{"$set": param}
|
||||
serr = videocategorymod.UpdateOneVideoCategory(ctx, adFilter, updateDoc)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package srv_videocategory
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/models/videocategorymod"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
type VideoCategoryReq struct {
|
||||
pubdef.Page
|
||||
ID int64 `json:"id"` //分类ID
|
||||
Name string `json:"name"` //分类名称
|
||||
}
|
||||
type VideoCategoryResp struct {
|
||||
Total int64 `json:"total"`
|
||||
List videocategorymod.VideoCategoryList `json:"list"`
|
||||
}
|
||||
type VideoCategoryUpdate 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
|
||||
Title *string `json:"title" bson:"title,omitempty"` // APP显示
|
||||
Desc *string `json:"desc" bson:"desc,omitempty"` // 描述
|
||||
SortType *int64 `json:"sortType" bson:"sortType,omitempty"` // 排序方式 0:上线时间 1:观看次数 2排序
|
||||
ContentType *int64 `json:"contentType" bson:"contentType,omitempty"` // 内容:0: 默认 1:首页 2:今日
|
||||
Rank *int64 `json:"rank" bson:"rank,omitempty"` // 排序
|
||||
SeoInfo *pubdef.SeoValue `json:"seoInfo" bson:"seoInfo,omitempty"` // Seo相关信息
|
||||
Status *bool `json:"status" bson:"status,omitempty"` // 上架状态
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"`
|
||||
IsReIndexNow *bool `json:"isReIndexNow" bson:"isReIndexNow"` // 是否重新提交索引
|
||||
IndexNow *int64 `bson:"indexNow,omitempty"`
|
||||
}
|
||||
type VideoCategoryUpdateReq struct {
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
Param VideoCategoryUpdate `json:"param" bson:"param"` // appId,唯一id
|
||||
}
|
||||
|
||||
type VideoCategoryDelReq struct {
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
}
|
||||
Reference in New Issue
Block a user