159 lines
4.0 KiB
Go
159 lines
4.0 KiB
Go
package appInfoSer
|
|
|
|
import (
|
|
"context"
|
|
"stat/api/proto"
|
|
"stat/common/genId"
|
|
"stat/common/stdLog"
|
|
"stat/models/landPageConfig"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
// GetLandPageConfigList
|
|
func GetLandPageConfigList(ctx context.Context, param *proto.FindLandPageConfigReq) (code stdLog.CodeType, data interface{}, err error) {
|
|
resp := proto.LandPageConfigListResp{
|
|
Total: 0,
|
|
List: make(landPageConfig.LandPageConfigList, 0),
|
|
}
|
|
|
|
filter := bson.M{}
|
|
if param.Status != nil {
|
|
filter[landPageConfig.FN.LandPageConfig.Status] = *param.Status
|
|
}
|
|
if param.AppId != nil {
|
|
filter[landPageConfig.FN.LandPageConfig.AppId] = *param.AppId
|
|
}
|
|
if param.Type != nil {
|
|
filter[landPageConfig.FN.LandPageConfig.LandPageType] = *param.Type
|
|
}
|
|
|
|
total, err := landPageConfig.CountLandPageConfigs(ctx, filter)
|
|
if err != nil {
|
|
code = stdLog.Failure
|
|
return
|
|
}
|
|
opt := &options.FindOptions{}
|
|
opt.SetSort(bson.D{
|
|
{landPageConfig.FN.LandPageConfig.Rank, -1},
|
|
{landPageConfig.FN.LandPageConfig.CreateAt, -1},
|
|
})
|
|
opt.SetLimit(param.PageSize)
|
|
opt.SetSkip((param.PageNum - 1) * param.PageSize)
|
|
list, err := landPageConfig.FindManyLandPageConfig(ctx, filter, opt)
|
|
if err != nil {
|
|
code = stdLog.Failure
|
|
return
|
|
}
|
|
|
|
resp.List = list
|
|
resp.Total = total
|
|
|
|
data = resp
|
|
code = stdLog.Success
|
|
return
|
|
}
|
|
|
|
// AddLandPageConfig
|
|
func AddLandPageConfig(ctx context.Context, param *proto.AddLandPageConfigReq) (code stdLog.CodeType, data interface{}, err error) {
|
|
now := time.Now()
|
|
doc := &landPageConfig.LandPageConfig{
|
|
Id: genId.GetLandpageConfigId(),
|
|
AppId: *param.AppId,
|
|
LandPageType: *param.LandPageType,
|
|
Title: *param.Title,
|
|
CreateAt: now,
|
|
UpdateAt: now,
|
|
}
|
|
if param.Desc != nil {
|
|
doc.Desc = *param.Desc
|
|
}
|
|
if param.Actor != nil {
|
|
doc.Actor = *param.Actor
|
|
}
|
|
if param.Bango != nil {
|
|
doc.Bango = *param.Bango
|
|
}
|
|
if param.AddedTime != nil {
|
|
doc.AddedTime = *param.AddedTime
|
|
}
|
|
if param.Picture != nil {
|
|
doc.Picture = *param.Picture
|
|
}
|
|
if param.Media != nil {
|
|
doc.Media = *param.Media
|
|
}
|
|
if param.Rank != nil {
|
|
doc.Rank = *param.Rank
|
|
}
|
|
if param.Status != nil {
|
|
doc.Status = *param.Status
|
|
}
|
|
if err = landPageConfig.InsertOneLandPageConfig(ctx, doc); err != nil {
|
|
code = stdLog.Failure
|
|
return
|
|
}
|
|
code = stdLog.Success
|
|
return
|
|
}
|
|
|
|
// UpdateLandPageConfig
|
|
func UpdateLandPageConfig(ctx context.Context, param *landPageConfig.LandPageConfig) (code stdLog.CodeType, data interface{}, err error) {
|
|
now := time.Now()
|
|
param.UpdateAt = now
|
|
updateDoc := bson.M{"$set": param}
|
|
if err = landPageConfig.UpdateOneLandPageConfig(ctx, bson.M{
|
|
landPageConfig.FN.LandPageConfig.Id: param.Id,
|
|
}, updateDoc); err != nil {
|
|
code = stdLog.Failure
|
|
return
|
|
}
|
|
code = stdLog.Success
|
|
return
|
|
}
|
|
|
|
// DelLandPageConfig
|
|
func DelLandPageConfig(ctx context.Context, param *proto.DelLandPageConfigReq) (code stdLog.CodeType, data interface{}, err error) {
|
|
if _, err = landPageConfig.DelOneLandPageConfig(ctx, bson.M{
|
|
landPageConfig.FN.LandPageConfig.Id: param.ID,
|
|
}); err != nil {
|
|
code = stdLog.Failure
|
|
return
|
|
}
|
|
code = stdLog.Success
|
|
return
|
|
}
|
|
|
|
// GetLandPageConfigByType
|
|
func GetLandPageConfigByType(ctx context.Context, param *proto.GetLandPageConfigByTypeReq) (code stdLog.CodeType, data interface{}, err error) {
|
|
opt := &options.FindOptions{}
|
|
if param.AppId == 0 {
|
|
code = stdLog.Failure
|
|
return
|
|
}
|
|
opt.SetSort(bson.D{
|
|
{landPageConfig.FN.LandPageConfig.Rank, -1},
|
|
{landPageConfig.FN.LandPageConfig.CreateAt, -1},
|
|
})
|
|
opt.SetSkip((param.PageNum - 1) * param.PageSize)
|
|
opt.SetLimit(param.PageSize)
|
|
// param.AppId = 888
|
|
// param.Type = 2
|
|
// param.PageNum = 1
|
|
// param.PageSize = 10
|
|
if data, err = landPageConfig.FindManyLandPageConfig(ctx, bson.M{
|
|
landPageConfig.FN.LandPageConfig.Status: true,
|
|
landPageConfig.FN.LandPageConfig.AppId: param.AppId,
|
|
landPageConfig.FN.LandPageConfig.LandPageType: param.Type,
|
|
}, opt); err != nil {
|
|
//fmt.Println(param, err)
|
|
code = stdLog.Failure
|
|
return
|
|
}
|
|
//fmt.Println("******", param, err)
|
|
code = stdLog.Success
|
|
return
|
|
}
|