@@ -0,0 +1,126 @@
|
||||
package advanceconfigmod
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"time"
|
||||
)
|
||||
|
||||
type QueryAllCond struct {
|
||||
Page int64 `form:"pageNumber" binding:"required"` // 查询页码
|
||||
Limit int64 `form:"pageSize" binding:"required"` // 页码大小
|
||||
Type *int `form:"type" json:"type" bson:"type,omitempty"` // 类型
|
||||
Status *int `form:"status" json:"status" bson:"status,omitempty"` // 配置状态
|
||||
}
|
||||
|
||||
type QueryAllRes struct {
|
||||
List []*AdvanceConfig `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
func (receiver *QueryAllCond) Filter() bson.M {
|
||||
var query = bson.M{}
|
||||
if receiver.Type != nil {
|
||||
query["type"] = receiver.Type
|
||||
}
|
||||
if receiver.Status != nil {
|
||||
query["status"] = receiver.Status
|
||||
}
|
||||
query["isDelete"] = false
|
||||
return query
|
||||
}
|
||||
|
||||
func (receiver QueryAllCond) Options() *options.FindOptions {
|
||||
return options.Find().SetSkip((receiver.Page - 1) * receiver.Limit).SetLimit(receiver.Limit).SetSort(bson.M{"sortCode": -1})
|
||||
}
|
||||
|
||||
type WebCreateReq struct {
|
||||
Name string `json:"name" bson:"name"` // 名称
|
||||
Cover string `json:"cover" bson:"cover"` // 封面
|
||||
SourceURL string `form:"sourceURL" json:"sourceURL"` // 视频资源链接
|
||||
Status int `json:"status" bson:"status"` // 配置状态 1:开启,2:关闭
|
||||
Type int `json:"type" bson:"type"` // 类型 1:宣传视频,2:游戏截图,3:盲盒展示,4:花絮视频,5:下载链接
|
||||
SortCode int `json:"sortCode" bson:"sortCode"` // 排序
|
||||
Url string `json:"url" bson:"url"` // 配置链接
|
||||
}
|
||||
|
||||
// Create 发布数据fi
|
||||
func (p *WebCreateReq) Create(manager string) *AdvanceConfig {
|
||||
now := time.Now()
|
||||
data := AdvanceConfig{
|
||||
Name: p.Name,
|
||||
Cover: p.Cover,
|
||||
Url: p.Url,
|
||||
Type: p.Type,
|
||||
SourceURL: p.SourceURL,
|
||||
SortCode: p.SortCode,
|
||||
Status: p.Status,
|
||||
IsDelete: false,
|
||||
UpdatedAct: manager,
|
||||
UpdateTime: now,
|
||||
CreatedAt: now,
|
||||
}
|
||||
return &data
|
||||
}
|
||||
|
||||
type WebUpdateReq struct {
|
||||
ID string `json:"id" bson:"id" binding:"required"`
|
||||
Name *string `json:"name" bson:"name,omitempty"` // 名称
|
||||
Cover *string `json:"cover" bson:"cover,omitempty"` // 封面图
|
||||
Type *int `json:"type" bson:"type,omitempty"` // 类型
|
||||
SourceURL *string `form:"sourceURL" json:"sourceURL"` // 视频资源链接
|
||||
SortCode *int `json:"sortCode" bson:"sortCode,omitempty"` // 排序
|
||||
Status *int `json:"status" bson:"status,omitempty"` // 是否开启
|
||||
Url *string `json:"url" bson:"url,omitempty"` // 配置链接
|
||||
}
|
||||
|
||||
func (p *WebUpdateReq) Filter() primitive.ObjectID {
|
||||
id, _ := primitive.ObjectIDFromHex(p.ID)
|
||||
return id
|
||||
}
|
||||
|
||||
func (p *WebUpdateReq) Update(updateAct string) bson.M {
|
||||
var data = bson.M{}
|
||||
if p.Name != nil {
|
||||
data["name"] = *p.Name
|
||||
}
|
||||
if p.Cover != nil {
|
||||
data["cover"] = *p.Cover
|
||||
}
|
||||
if p.SourceURL != nil {
|
||||
data["sourceURL"] = *p.SourceURL
|
||||
}
|
||||
if p.Type != nil {
|
||||
data["type"] = *p.Type
|
||||
}
|
||||
if p.SortCode != nil {
|
||||
data["sortCode"] = *p.SortCode
|
||||
}
|
||||
if p.Status != nil {
|
||||
data["status"] = *p.Status
|
||||
}
|
||||
if p.Url != nil {
|
||||
data["url"] = *p.Url
|
||||
}
|
||||
data["updatedAct"] = updateAct
|
||||
data["updateTime"] = time.Now()
|
||||
return bson.M{"$set": data}
|
||||
}
|
||||
|
||||
type WebDeleteReq struct {
|
||||
ID string `json:"id" bson:"id" binding:"required"` // ID
|
||||
}
|
||||
|
||||
func (p *WebDeleteReq) Filter() primitive.ObjectID {
|
||||
id, _ := primitive.ObjectIDFromHex(p.ID)
|
||||
return id
|
||||
}
|
||||
|
||||
func (p *WebDeleteReq) Del(updateAct string) bson.M {
|
||||
var data = bson.M{}
|
||||
data["isDelete"] = true
|
||||
data["updatedAct"] = updateAct
|
||||
data["updateTime"] = time.Now()
|
||||
return bson.M{"$set": data}
|
||||
}
|
||||
Reference in New Issue
Block a user