init: web_hgdjc_server
This commit is contained in:
Executable
+52
@@ -0,0 +1,52 @@
|
||||
package videotopicmod
|
||||
|
||||
type TagVideoTopicModel struct {
|
||||
Id string
|
||||
Name string
|
||||
Title string
|
||||
Desc string
|
||||
Status string
|
||||
Rank string
|
||||
Slug string
|
||||
Image string
|
||||
VideoCategoryId string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
Works string
|
||||
IndexNow string
|
||||
UpdatedAt string
|
||||
CreatedAt string
|
||||
VideoTopicType string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoTopicModel TagVideoTopicModel
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoTopicModel string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoTopicModel.CreatedAt = "createdAt"
|
||||
FN.VideoTopicModel.Desc = "desc"
|
||||
FN.VideoTopicModel.Id = "_id"
|
||||
FN.VideoTopicModel.IndexNow = "indexNow"
|
||||
FN.VideoTopicModel.Name = "name"
|
||||
FN.VideoTopicModel.Rank = "rank"
|
||||
FN.VideoTopicModel.Slug = "slug"
|
||||
FN.VideoTopicModel.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.VideoTopicModel.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.VideoTopicModel.SeoInfo.Title = "seoInfo.webTitle"
|
||||
FN.VideoTopicModel.Status = "status"
|
||||
FN.VideoTopicModel.Title = "title"
|
||||
FN.VideoTopicModel.UpdatedAt = "updatedAt"
|
||||
FN.VideoTopicModel.Works = "works"
|
||||
FN.VideoTopicModel.Image = "image"
|
||||
FN.VideoTopicModel.VideoCategoryId = "videoCategoryId"
|
||||
FN.VideoTopicModel.VideoTopicType = "videoTopicType"
|
||||
TN.VideoTopicModel = "video_topic"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package videotopicmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/models/videoinformationmod"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// @table:video_topic
|
||||
type VideoTopicModel struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"` // Id
|
||||
Name string `json:"name" bson:"name"` // 专题名称
|
||||
Slug string `json:"slug" bson:"slug"` // slug
|
||||
Title string `json:"title" bson:"title"` // APP显示
|
||||
Desc string `json:"desc" bson:"desc"` // 描述
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
Image string `json:"image" bson:"image"` // 背景
|
||||
VideoTopicType videoinformationmod.MediaType `json:"videoTopicType" bson:"videoTopicType"` // 视频类型
|
||||
VideoCategoryId int64 `json:"videoCategoryId" bson:"videoCategoryId"` // 视频分类id
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
Works int64 `json:"works" bson:"works"` // 作品数
|
||||
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type VideoTopicModelList []*VideoTopicModel
|
||||
@@ -0,0 +1,144 @@
|
||||
package videotopicmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"fmt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// 表名
|
||||
var db *mongos.Collection
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
// 获取数据库表
|
||||
db = mongos.Shop.Coll(TN.VideoTopicModel)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoTopicModel.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoTopicModel.Status, Value: 1},
|
||||
{Key: FN.VideoTopicModel.Rank, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoTopicModel.VideoCategoryId, Value: 1},
|
||||
{Key: FN.VideoTopicModel.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoTopicModel.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoTopicModel.Slug, Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initVideoTopicModelIndex) Create VideoTopicModel Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneVideoTopicModel 插入一个渠道统计
|
||||
func InsertOneVideoTopicModel(ctx context.Context, qa *VideoTopicModel) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("VideoTopicModelmod:InsertOneVideoTopicModel db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneVideoTopicModel 删除一个渠道统计
|
||||
func DelOneVideoTopicModel(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoTopicModelmod:DelOneVideoTopicModel db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneVideoTopicModel 查找一个渠道统计
|
||||
func FindOneVideoTopicModel(ctx context.Context, filter bson.M) (
|
||||
*VideoTopicModel, *srvdef.SrvErr) {
|
||||
var VideoTopicModel VideoTopicModel
|
||||
if err := db.FindOneEx(ctx, &VideoTopicModel, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("VideoTopicModelmod:FindOneVideoTopicModel db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &VideoTopicModel, nil
|
||||
}
|
||||
|
||||
func FindManyVideoTopicModels(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoTopicModelList, *srvdef.SrvErr) {
|
||||
data := make(VideoTopicModelList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyVideoTopicModels", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountVideoTopicModels 统计渠道统计数量
|
||||
func CountVideoTopicModels(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountVideoTopicModels db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneVideoTopicModel 更新一个渠道统计
|
||||
func UpdateOneVideoTopicModel(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneVideoTopicModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneVideoTopicModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateManyVideoTopicModel(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateManyVideoTopicModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount < 1 {
|
||||
log.Warn("post:UpdateManyVideoInfomation db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user