init: 初始化 web_hgdjb_server 项目
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package srv_translation
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/models/translationmod"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
type TranslationInfoReq struct {
|
||||
pubdef.Page
|
||||
Id int64 `json:"id" form:"id"` // 导航ID
|
||||
Name string `json:"name" form:"name"` // 导航名称
|
||||
TransCategoryId int64 `json:"transCategoryId" form:"transCategoryId"` // 导航分类ID
|
||||
}
|
||||
type TranslationInfoResp struct {
|
||||
Total int64 `json:"total"`
|
||||
List translationmod.TranslationInfoList `json:"list"`
|
||||
}
|
||||
type TranslationInfoUpdate struct {
|
||||
Name *string `json:"name" bson:"name,omitempty"` // 分类名称
|
||||
Status *bool `json:"status" bson:"status,omitempty"` // 上架状态
|
||||
Rank *int64 `json:"rank" bson:"rank,omitempty"` // 排序
|
||||
HtmlId *int64 `json:"htmlId" bson:"htmlId,omitempty"` // 富文本ID
|
||||
Link *string `json:"link" bson:"link,omitempty"` // 外部跳转
|
||||
IsFriendAds *bool `json:"isFriendAds" bson:"isFriendAds"` // 是否是友链广告位
|
||||
TransCategoryId *int64 `json:"transCategoryId" bson:"transCategoryId,omitempty"` //
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"`
|
||||
}
|
||||
type TranslationInfoUpdateReq struct {
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
Param TranslationInfoUpdate `json:"param" bson:"param"` // appId,唯一id
|
||||
}
|
||||
|
||||
type TranslationInfoDelReq struct {
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
}
|
||||
@@ -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