init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
package srv_videocreater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/videocreatermod"
|
||||
"videoweb/pub/mongos"
|
||||
"videoweb/web/service/srv_videoslug"
|
||||
|
||||
"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, "", "")
|
||||
}
|
||||
if serr := srv_videoslug.EnsureCreater(ctx, ac, 0); serr != nil {
|
||||
return serr
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
info, serr := videocreatermod.FindOneVideoCreaterInfo(ctx, bson.M{videocreatermod.FN.VideoCreaterInfo.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.PrepareCreaterOnUpdate(ctx, info, param.Slug, name, keywords)
|
||||
if slugErr != nil {
|
||||
return slugErr
|
||||
}
|
||||
if changed {
|
||||
param.Slug = &slug
|
||||
} else {
|
||||
param.Slug = nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package srv_videocreater
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/models/videocreatermod"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
type VideoCreaterReq struct {
|
||||
pubdef.Page
|
||||
ID int64 `json:"id"` //分类ID
|
||||
Name string `json:"name"` //分类名称
|
||||
}
|
||||
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"` // 是否重新提交索引
|
||||
IndexNow *int64 `bson:"indexNow,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