init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
package videocreatermod
|
||||
|
||||
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.VideoCreaterInfo)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCreaterInfo.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCreaterInfo.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCreaterInfo.Slug, Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initVideoCreaterInfoIndex) Create VideoCreaterInfo Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneVideoCreaterInfo 插入一个渠道统计
|
||||
func InsertOneVideoCreaterInfo(ctx context.Context, qa *VideoCreaterInfo) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
log.Warn("VideoCreaterInfomod:InsertOneVideoCreaterInfo db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneVideoCreaterInfo 删除一个渠道统计
|
||||
func DelOneVideoCreaterInfo(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoCreaterInfomod:DelOneVideoCreaterInfo db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneVideoCreaterInfo 查找一个渠道统计
|
||||
func FindOneVideoCreaterInfo(ctx context.Context, filter bson.M) (
|
||||
*VideoCreaterInfo, *srvdef.SrvErr) {
|
||||
var VideoCreaterInfo VideoCreaterInfo
|
||||
if err := db.FindOneEx(ctx, &VideoCreaterInfo, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("VideoCreaterInfomod:FindOneVideoCreaterInfo db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &VideoCreaterInfo, nil
|
||||
}
|
||||
|
||||
func FindManyVideoCreaterInfos(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoCreaterInfoList, *srvdef.SrvErr) {
|
||||
data := make(VideoCreaterInfoList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyVideoCreaterInfos", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountVideoCreaterInfos 统计渠道统计数量
|
||||
func CountVideoCreaterInfos(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountVideoCreaterInfos db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneVideoCreaterInfo 更新一个渠道统计
|
||||
func UpdateOneVideoCreaterInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneVideoCreaterInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneVideoCreaterInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateManyVideoCreaterInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateManyVideoCreaterInfo 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
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
package videocreatermod
|
||||
|
||||
type TagVideoCreaterInfo struct {
|
||||
CreatedAt string
|
||||
Id string
|
||||
IndexNow string
|
||||
Name string
|
||||
Slug string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
Sort string
|
||||
Status string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoCreaterInfo TagVideoCreaterInfo
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoCreaterInfo string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoCreaterInfo.CreatedAt = "createdAt"
|
||||
FN.VideoCreaterInfo.Id = "_id"
|
||||
FN.VideoCreaterInfo.IndexNow = "indexNow"
|
||||
FN.VideoCreaterInfo.Name = "name"
|
||||
FN.VideoCreaterInfo.Slug = "slug"
|
||||
FN.VideoCreaterInfo.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.VideoCreaterInfo.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.VideoCreaterInfo.SeoInfo.Title = "seoInfo.webTitle"
|
||||
FN.VideoCreaterInfo.Sort = "sort"
|
||||
FN.VideoCreaterInfo.Status = "status"
|
||||
FN.VideoCreaterInfo.UpdatedAt = "updatedAt"
|
||||
TN.VideoCreaterInfo = "video_creater"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package videocreatermod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// @table:video_creater
|
||||
type VideoCreaterInfo struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
Name string `json:"name" bson:"name"` // 帖子标题
|
||||
Slug string `json:"slug" bson:"slug"` // slug
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
Sort int64 `json:"sort" bson:"sort"` // 排序
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type VideoCreaterInfoList []*VideoCreaterInfo
|
||||
Reference in New Issue
Block a user