Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
package srv_actress
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/slugx"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/common/utils"
|
||||
"videoweb/pub/models/actress"
|
||||
"videoweb/pub/mongos"
|
||||
"videoweb/pub/pubdef"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func ActressList(ctx context.Context, req *ActressListReq) (*ActressListResp, *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
if req.Id != nil && *req.Id > 0 {
|
||||
filter[actress.FN.Actress.Id] = *req.Id
|
||||
}
|
||||
if req.TranslationCategoryId != nil && *req.TranslationCategoryId > 0 {
|
||||
filter[actress.FN.Actress.TranslationCategoryId] = *req.TranslationCategoryId
|
||||
}
|
||||
if req.Region != nil && len(*req.Region) > 0 {
|
||||
filter[actress.FN.Actress.Region] = bson.M{"$regex": *req.Region}
|
||||
}
|
||||
if req.Status != nil {
|
||||
filter[actress.FN.Actress.Status] = *req.Status
|
||||
}
|
||||
if req.Alias != nil && *req.Alias != "" {
|
||||
filter[actress.FN.Actress.Alias] = bson.M{"$regex": *req.Alias}
|
||||
}
|
||||
count, err := actress.CountActresss(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("ActressList CountActresss", log.Any("filter", filter), log.E(err))
|
||||
return nil, err
|
||||
}
|
||||
resp := &ActressListResp{
|
||||
Total: 0,
|
||||
List: make([]*actress.Actress, 0),
|
||||
}
|
||||
if count == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
opts := &options.FindOptions{}
|
||||
opts.SetLimit(req.PageSize)
|
||||
opts.SetSkip((req.PageNum - 1) * req.PageSize)
|
||||
sort := bson.M{actress.FN.Actress.CreatedAt: -1}
|
||||
switch req.SortType {
|
||||
case 1:
|
||||
sort = bson.M{actress.FN.Actress.Score: -1}
|
||||
case 2:
|
||||
sort = bson.M{actress.FN.Actress.Rank: -1}
|
||||
case 3:
|
||||
sort = bson.M{actress.FN.Actress.Works: -1}
|
||||
case 4:
|
||||
sort = bson.M{actress.FN.Actress.Real.WatchTimes: -1}
|
||||
case 5:
|
||||
sort = bson.M{actress.FN.Actress.HotValue: -1, actress.FN.Actress.Id: -1}
|
||||
}
|
||||
opts.SetSort(sort)
|
||||
list, err := actress.FindManyActresss(ctx, filter, opts)
|
||||
if err != nil {
|
||||
log.Warn("ActressList FindManyActresss", log.Any("filter", filter), log.E(err))
|
||||
return nil, err
|
||||
}
|
||||
resp.Total = count
|
||||
resp.List = list
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func UpdateActress(ctx context.Context, req *ActressUpdateReq) *srvdef.SrvErr {
|
||||
current, err := actress.FindOneActress(ctx, bson.M{actress.FN.Actress.Id: req.Id})
|
||||
if err != nil {
|
||||
log.Warn("UpdateActress", log.Any("id", req.Id), log.E(err))
|
||||
return err
|
||||
}
|
||||
alias := current.Alias
|
||||
if req.Param.Alias != nil {
|
||||
alias = *req.Param.Alias
|
||||
}
|
||||
keywords := current.SeoInfo.Keyworld
|
||||
if req.Param.SeoInfo != nil {
|
||||
keywords = req.Param.SeoInfo.Keyworld
|
||||
}
|
||||
exists := func(s string) bool {
|
||||
doc, _ := actress.FindOneActress(ctx, slugx.Filter(actress.FN.Actress.Slug, actress.FN.Actress.Id, s, req.Id))
|
||||
return doc != nil
|
||||
}
|
||||
slug, changed, serr := slugx.PrepareOnUpdate(current.Slug, req.Param.Slug,
|
||||
utils.SlugSourceFromKeywordsOrTitle(keywords, alias), exists)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
if changed {
|
||||
req.Param.Slug = &slug
|
||||
} else {
|
||||
req.Param.Slug = nil
|
||||
}
|
||||
now := time.Now()
|
||||
req.Param.UpdatedAt = &now
|
||||
return actress.UpdateOneActress(ctx, bson.M{actress.FN.Actress.Id: req.Id}, bson.M{"$set": req.Param})
|
||||
}
|
||||
|
||||
func AddActress(ctx context.Context, req *ActressAddReq) *srvdef.SrvErr {
|
||||
if len(req.Alias) == 0 {
|
||||
return srvdef.New(srvdef.ErrParamError, "alias 不能为空", "alias 不能为空")
|
||||
}
|
||||
_, err := actress.FindOneActress(ctx, bson.M{
|
||||
actress.FN.Actress.Alias: req.Alias,
|
||||
})
|
||||
if err != nil && err.Code != srvdef.ErrNoData {
|
||||
log.Warn("AddActress", log.Any("req", req), log.E(err))
|
||||
return err
|
||||
}
|
||||
if err == nil {
|
||||
log.Warn("AddActress Re", log.Any("req", req))
|
||||
return srvdef.New(srvdef.RepeatActress)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
info := &actress.Actress{
|
||||
Id: mongos.Lid.Actress.Get(),
|
||||
Alias: req.Alias,
|
||||
Slug: req.Slug,
|
||||
SeoInfo: req.SeoInfo,
|
||||
Avatar: req.Avatar,
|
||||
Cover: req.Cover,
|
||||
Desc: req.Desc,
|
||||
TranslationCategoryId: req.TranslationCategoryId,
|
||||
Meas: req.Meas,
|
||||
Office: req.Office,
|
||||
DebutDate: req.DebutDate,
|
||||
BornDate: req.BornDate,
|
||||
Region: req.Region,
|
||||
Score: req.Score,
|
||||
Rank: req.Rank,
|
||||
HotValue: req.HotValue,
|
||||
Status: req.Status,
|
||||
Works: 0,
|
||||
Real: pubdef.Flow{},
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
exists := func(s string) bool {
|
||||
doc, _ := actress.FindOneActress(ctx, slugx.Filter(actress.FN.Actress.Slug, actress.FN.Actress.Id, s, 0))
|
||||
return doc != nil
|
||||
}
|
||||
if serr := slugx.Ensure(&info.Slug, utils.SlugSourceFromKeywordsOrTitle(info.SeoInfo.Keyworld, info.Alias), exists); serr != nil {
|
||||
return serr
|
||||
}
|
||||
return actress.InsertOneActress(ctx, info)
|
||||
}
|
||||
|
||||
func DeleteActress(ctx context.Context, req *ActressDelReq) *srvdef.SrvErr {
|
||||
_, err := actress.FindOneActress(ctx, bson.M{actress.FN.Actress.Id: req.Id})
|
||||
if err != nil {
|
||||
log.Warn("DeleteActress", log.Any("id", req.Id), log.E(err))
|
||||
return err
|
||||
}
|
||||
_, err = actress.DelOneActress(ctx, bson.M{actress.FN.Actress.Id: req.Id})
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package srv_actress
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/models/actress"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
type ActressListReq struct {
|
||||
pubdef.Page
|
||||
Id *int64 `form:"id" json:"id"` // Id
|
||||
Alias *string `form:"alias" json:"alias"` // 别名
|
||||
TranslationCategoryId *int64 `form:"translationCategoryId" json:"translationCategoryId"` // 关联导航分类id
|
||||
Region *string `form:"region" json:"region"` // 地区/国家
|
||||
Status *bool `form:"status" json:"status" ` // 是否启用
|
||||
SortType int64 `form:"sortType" json:"sortType"` // 排序方式 0=创建时间 1=评分 2=排序值 3=作品数 4=总观看次数 5=热度值
|
||||
}
|
||||
type ActressListResp struct {
|
||||
Total int64 `json:"total"`
|
||||
List []*actress.Actress `json:"list"`
|
||||
}
|
||||
|
||||
type ActressUpdateReq struct {
|
||||
Id int64 `json:"id,omitempty" binding:"required"`
|
||||
Param ActressUpdateParam `json:"param" binding:"required"`
|
||||
}
|
||||
|
||||
type ActressUpdateParam struct {
|
||||
Alias *string `bson:"alias,omitempty" json:"alias"` // 别名
|
||||
Slug *string `json:"slug" bson:"slug,omitempty"` // slug
|
||||
Avatar *string `bson:"avatar,omitempty" json:"avatar"` // 头像
|
||||
Cover *string `bson:"cover,omitempty" json:"cover"` // 封面大图
|
||||
Desc *string `bson:"desc,omitempty" json:"desc"` // 详细描述
|
||||
TranslationCategoryId *int64 `bson:"translationCategoryId,omitempty" json:"translationCategoryId"` // 关联导航分类id
|
||||
Meas *actress.Meas `bson:"meas,omitempty" json:"meas"` // 三围
|
||||
Office *string `json:"office" bson:"office,omitempty"` // 事务所
|
||||
DebutDate *time.Time `bson:"debutDate,omitempty" json:"debutDate" ` // 出道日期
|
||||
BornDate *time.Time `bson:"bornDate,omitempty" json:"bornDate"` // 出生日期
|
||||
Region *string `json:"region" bson:"region,omitempty"` // 地区/国家
|
||||
Score *string `json:"score" bson:"score,omitempty"` // 评分
|
||||
Rank *int64 `json:"rank" bson:"rank,omitempty"` // 排序
|
||||
HotValue *int64 `json:"hotValue" bson:"hotValue,omitempty"` // 热度值
|
||||
Status *bool `json:"status" bson:"status,omitempty"` // 是否启用
|
||||
SeoInfo *pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
UpdatedAt *time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` // 更新时间
|
||||
}
|
||||
|
||||
type ActressAddReq struct {
|
||||
Alias string `bson:"alias" json:"alias"` // 别名
|
||||
Slug string `json:"slug" bson:"slug"` // slug,不传则按 SEO 关键词或别名自动生成
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
Avatar string `bson:"avatar" json:"avatar"` // 头像
|
||||
Cover string `bson:"cover" json:"cover"` // 封面大图
|
||||
Desc string `bson:"desc" json:"desc"` // 详细描述
|
||||
TranslationCategoryId int64 `bson:"translationCategoryId" json:"translationCategoryId"` // 关联导航分类id
|
||||
Meas actress.Meas `bson:"meas" json:"meas"` // 三围
|
||||
Office string `json:"office" bson:"office"` // 事务所
|
||||
DebutDate time.Time `bson:"debutDate" json:"debutDate" ` // 出道日期
|
||||
BornDate time.Time `bson:"bornDate" json:"bornDate"` // 出生日期
|
||||
Region string `json:"region" bson:"region"` // 地区/国家
|
||||
Score string `json:"score" bson:"score"` // 评分
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
HotValue int64 `json:"hotValue" bson:"hotValue"` // 热度值
|
||||
Status bool `json:"status" bson:"status"` // 是否启用
|
||||
}
|
||||
|
||||
type ActressDelReq struct {
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
Reference in New Issue
Block a user