Commit f872e60b authored by zhengyaoqiu's avatar zhengyaoqiu

feat(database): mongodb

parent 37fa6718
package model
package base
import "go.mongodb.org/mongo-driver/mongo/options"
......
package model
package mongo
//go:generate goctl template init --home ./templates
......
package mongo
import productModel "git.chillcy.com/golang/colorway/internal/pkg/database/mongo/product"
const DatabasePc3 = "pc3"
type Manager struct {
ProductModel productModel.ProductModel
}
func NewManager(mongoUrl string) *Manager {
return &Manager{
ProductModel: productModel.NewProductModel(mongoUrl, DatabasePc3, productModel.Collection),
}
}
......@@ -2,7 +2,7 @@
package model
import (
model "git.chillcy.com/golang/colorway/internal/pkg/database/mongo"
model "git.chillcy.com/golang/colorway/internal/pkg/database/mongo/base"
"github.com/zeromicro/go-zero/core/stores/mon"
)
......
......@@ -6,9 +6,81 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
)
const Collection = "product"
type Product struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
// TODO: Fill your own fields
StyleNumber string `bson:"styleNumber"`
Title ProductTitle `bson:"title"`
Description string `bson:"description"`
Season string `bson:"season"`
Brand ProductBrand `bson:"brand"`
Care string `bson:"care"`
MadeIn string `bson:"madeIn"`
HsCode string `bson:"hsCode"`
InfoSelect string `bson:"infoSelect"` // 商品信息默认选择哪个商品
Colors []ProductColor `bson:"colors"`
Category ProductCategory `bson:"category"`
Compositions []ProductComposition `bson:"compositions"`
Fits []string `bson:"fits"`
Genders []ProductGender `bson:"genders"`
Models []string `bson:"models"`
UpdateAt time.Time `bson:"updateAt,omitempty" json:"updateAt,omitempty"`
CreateAt time.Time `bson:"createAt,omitempty" json:"createAt,omitempty"`
}
type ProductGender string
const (
GenderMan ProductGender = "man"
GenderWoman ProductGender = "woman"
GenderBaby ProductGender = "baby"
GenderGirl ProductGender = "girl"
GenderBoy ProductGender = "boy"
)
type ProductComposition struct {
Part string `bson:"part"`
Material string `bson:"material"`
Value string `bson:"value"`
}
type ProductCategory struct {
Id string `bson:"id"`
Name string `bson:"name"`
Children []ProductCategory `json:"children" bson:"children"`
}
type ProductColor struct {
ColorCode string `bson:"colorCode"`
Id string `bson:"id"`
Name string `bson:"name"`
BasicId string `bson:"basicId"`
BasicName string `bson:"basicName"`
InfoSelect string `bson:"infoSelect"` // 商品信息默认选择哪个商品
Skus []ProductColorSku `bson:"skus"`
Images []string `bson:"images"`
}
type ProductColorSku struct {
Pc3SkuId string `bson:"pc3SkuId"`
Pc3ProductId string `bson:"pc3ProductId"`
ColorSpuStyleNumber string `bson:"colorSpuStyleNumber"`
ColorSpuColorCode string `bson:"colorSpuColorCode"`
SourceId string `bson:"sourceId"`
SiteId string `bson:"siteId"`
Size string `bson:"size"`
Stock int `bson:"stock"`
Price float64 `bson:"price"`
Currency string `bson:"currency"`
}
type ProductTitle struct {
En string `bson:"en"`
Cn string `bson:"cn"`
}
type ProductBrand struct {
Id string `bson:"id"`
Name string `bson:"name"`
}
......@@ -2,7 +2,7 @@
package model
import (
model "git.chillcy.com/golang/colorway/internal/pkg/database/mongo"
model "git.chillcy.com/golang/colorway/internal/pkg/database/mongo/base"
{{if .Cache}}"github.com/zeromicro/go-zero/core/stores/monc"{{else}}"github.com/zeromicro/go-zero/core/stores/mon"{{end}}
)
......
......@@ -4,7 +4,7 @@ import (
"git.chillcy.com/golang/chillcy/pkg/etcd"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/client/product"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/client/source"
"git.chillcy.com/golang/colorway/internal/pkg/database"
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo"
"git.chillcy.com/golang/colorway/internal/rpc/internal/config"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/convert"
......@@ -13,7 +13,7 @@ import (
type ServiceContext struct {
Config config.Config
DatabaseManager *database.Manager
MongoManager *mongo.Manager
Pc4RpcService Pc4RpcService
Cache *cache.Cache
SpuConvert *convert.Spu
......@@ -21,19 +21,14 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext {
etcd.Init(etcd.Env(c.Mode))
// todo dsn etcd
dsn := "root:root@tcp(127.0.0.1:3306)/colorway?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=true&loc=Local"
manager, err := database.NewManager(dsn)
if err != nil {
panic(err)
}
pc4RpcProductServiceTarget := etcd.Get(etcd.KeyRpcPc4)
mongoManager := mongo.NewManager(etcd.Get(etcd.KeyMongoPlatformUri))
if etcd.GetEnv() == etcd.EnvDev {
pc4RpcProductServiceTarget = "127.0.0.1:5100"
}
svc := &ServiceContext{
Config: c,
DatabaseManager: manager,
MongoManager: mongoManager,
Pc4RpcService: Pc4RpcService{
Product: product.NewProduct(zrpc.MustNewClient(zrpc.RpcClientConf{Target: pc4RpcProductServiceTarget})),
Source: source.NewSource(zrpc.MustNewClient(zrpc.RpcClientConf{Target: pc4RpcProductServiceTarget})),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment