init: 初始化 web_hgdjb_server 项目
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
package translationcategorymod
|
||||
|
||||
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.TranslationCategory)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.TranslationCategory.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.TranslationCategory.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initTranslationCategoryIndex) Create TranslationCategory Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneTranslationCategory 插入一个导航分类
|
||||
func InsertOneTranslationCategory(ctx context.Context, qa *TranslationCategory) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("TranslationCategorymod:InsertOneTranslationCategory db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneTranslationCategory 删除一个导航分类
|
||||
func DelOneTranslationCategory(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("TranslationCategorymod:DelOneTranslationCategory db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneTranslationCategory 查找一个导航分类
|
||||
func FindOneTranslationCategory(ctx context.Context, filter bson.M) (
|
||||
*TranslationCategory, *srvdef.SrvErr) {
|
||||
var TranslationCategory TranslationCategory
|
||||
if err := db.FindOneEx(ctx, &TranslationCategory, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("TranslationCategorymod:FindOneTranslationCategory db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &TranslationCategory, nil
|
||||
}
|
||||
|
||||
func FindManyTranslationCategorys(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (TranslationCategoryList, *srvdef.SrvErr) {
|
||||
data := make(TranslationCategoryList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyTranslationCategorys", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountTranslationCategorys 统计导航分类数量
|
||||
func CountTranslationCategorys(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountTranslationCategorys db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneTranslationCategory 更新一个导航分类
|
||||
func UpdateOneTranslationCategory(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneTranslationCategory db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneTranslationCategory db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
package translationcategorymod
|
||||
|
||||
type TagTranslationCategory struct {
|
||||
CategoryType string
|
||||
CreatedAt string
|
||||
Id string
|
||||
Name string
|
||||
Rank string
|
||||
Status string
|
||||
UpdatedAt string
|
||||
UrlValue string
|
||||
Icon string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
TranslationCategory TagTranslationCategory
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
TranslationCategory string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.TranslationCategory.CategoryType = "categoryType"
|
||||
FN.TranslationCategory.CreatedAt = "createdAt"
|
||||
FN.TranslationCategory.Id = "_id"
|
||||
FN.TranslationCategory.Name = "name"
|
||||
FN.TranslationCategory.Rank = "rank"
|
||||
FN.TranslationCategory.Status = "status"
|
||||
FN.TranslationCategory.UpdatedAt = "updatedAt"
|
||||
FN.TranslationCategory.UrlValue = "urlValue"
|
||||
FN.TranslationCategory.Icon = "icon"
|
||||
FN.TranslationCategory.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.TranslationCategory.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.TranslationCategory.SeoInfo.Title = "seoInfo.webTitle"
|
||||
TN.TranslationCategory = "translation_category"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package translationcategorymod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// @table:translation_category
|
||||
type TranslationCategory struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"` // Id
|
||||
Name string `json:"name" bson:"name"` // 分类名称
|
||||
Icon string `json:"icon" bson:"icon"` // Icon
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
CategoryType pubdef.TranslationType `json:"categoryType" bson:"categoryType"` // 导航类型 1:url 2:二级导航 3:底部导航
|
||||
UrlValue string `json:"urlValue" bson:"urlValue"` // 跳转URL
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type TranslationCategoryList []*TranslationCategory
|
||||
Reference in New Issue
Block a user