init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package srv_translation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/translationmod"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// GetTranslationInfos 按照参数搜索视频标签
|
||||
func GetTranslationInfos(ctx context.Context, param *TranslationInfoReq) (*TranslationInfoResp, *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
opt := &options.FindOptions{}
|
||||
resp := &TranslationInfoResp{}
|
||||
|
||||
if param.Id > 0 {
|
||||
filter[translationmod.FN.TranslationInfo.Id] = param.Id
|
||||
}
|
||||
if name := strings.TrimSpace(param.Name); name != "" {
|
||||
filter[translationmod.FN.TranslationInfo.Name] = bson.M{"$regex": name}
|
||||
}
|
||||
if param.TransCategoryId > 0 {
|
||||
filter[translationmod.FN.TranslationInfo.TransCategoryId] = param.TransCategoryId
|
||||
}
|
||||
|
||||
opt.SetSort(bson.M{translationmod.FN.TranslationInfo.Rank: -1})
|
||||
opt.SetSkip((param.PageNum - 1) * param.PageSize).SetLimit(param.PageSize)
|
||||
|
||||
total, serr := translationmod.CountTranslationInfos(ctx, filter)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.Total = total
|
||||
if total == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
ads, serr := translationmod.FindManyTranslationInfos(ctx, filter, opt)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.List = ads
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// AddTranslationInfo 添加一视频标签
|
||||
func AddTranslationInfo(ctx context.Context,
|
||||
ac *translationmod.TranslationInfo) *srvdef.SrvErr {
|
||||
|
||||
ac.Id = mongos.Lid.Translation.Get()
|
||||
now := time.Now()
|
||||
ac.CreatedAt = now
|
||||
ac.UpdatedAt = now
|
||||
|
||||
serr := translationmod.InsertOneTranslationInfo(ctx, ac)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelTranslationInfo 删除指定视频标签
|
||||
func DelTranslationInfo(ctx context.Context, id int64) *srvdef.SrvErr {
|
||||
adFilter := bson.M{translationmod.FN.TranslationInfo.Id: id}
|
||||
//删除
|
||||
count, serr := translationmod.DelOneTranslationInfo(ctx, adFilter)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
if count == 0 {
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateTranslationInfo 更新指定视频标签
|
||||
func UpdateTranslationInfo(ctx context.Context, id int64, param TranslationInfoUpdate) *srvdef.SrvErr {
|
||||
now := time.Now()
|
||||
param.UpdatedAt = now
|
||||
|
||||
adFilter := bson.M{translationmod.FN.TranslationInfo.Id: id}
|
||||
updateDoc := bson.M{"$set": param}
|
||||
serr := translationmod.UpdateOneTranslationInfo(ctx, adFilter, updateDoc)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user