Commit 5abdeeab authored by zhengyaoqiu's avatar zhengyaoqiu

feat(colorway): 代码调整

parent e715f459
...@@ -12,7 +12,7 @@ type siteGroupMarginConfigModel interface { ...@@ -12,7 +12,7 @@ type siteGroupMarginConfigModel interface {
type defaultSiteGroupMarginConfigModel struct { type defaultSiteGroupMarginConfigModel struct {
conn *mon.Model conn *mon.Model
model.Base[SiteGroupMarginConfig] *model.Base[SiteGroupMarginConfig]
} }
func newDefaultSiteGroupMarginConfigModel(conn *mon.Model) *defaultSiteGroupMarginConfigModel { func newDefaultSiteGroupMarginConfigModel(conn *mon.Model) *defaultSiteGroupMarginConfigModel {
......
...@@ -12,7 +12,7 @@ type brandDataModel interface { ...@@ -12,7 +12,7 @@ type brandDataModel interface {
type defaultBrandDataModel struct { type defaultBrandDataModel struct {
conn *mon.Model conn *mon.Model
model.Base[BrandData] *model.Base[BrandData]
} }
func newDefaultBrandDataModel(conn *mon.Model) *defaultBrandDataModel { func newDefaultBrandDataModel(conn *mon.Model) *defaultBrandDataModel {
......
...@@ -12,7 +12,7 @@ type siteComboMarginConfigModel interface { ...@@ -12,7 +12,7 @@ type siteComboMarginConfigModel interface {
type defaultSiteComboMarginConfigModel struct { type defaultSiteComboMarginConfigModel struct {
conn *mon.Model conn *mon.Model
model.Base[SiteComboMarginConfig] *model.Base[SiteComboMarginConfig]
} }
func newDefaultSiteComboMarginConfigModel(conn *mon.Model) *defaultSiteComboMarginConfigModel { func newDefaultSiteComboMarginConfigModel(conn *mon.Model) *defaultSiteComboMarginConfigModel {
......
...@@ -12,7 +12,7 @@ type siteFloatMarginConfigModel interface { ...@@ -12,7 +12,7 @@ type siteFloatMarginConfigModel interface {
type defaultSiteFloatMarginConfigModel struct { type defaultSiteFloatMarginConfigModel struct {
conn *mon.Model conn *mon.Model
model.Base[SiteFloatMarginConfig] *model.Base[SiteFloatMarginConfig]
} }
func newDefaultSiteFloatMarginConfigModel(conn *mon.Model) *defaultSiteFloatMarginConfigModel { func newDefaultSiteFloatMarginConfigModel(conn *mon.Model) *defaultSiteFloatMarginConfigModel {
......
...@@ -12,7 +12,7 @@ type subjectModel interface { ...@@ -12,7 +12,7 @@ type subjectModel interface {
type defaultSubjectModel struct { type defaultSubjectModel struct {
conn *mon.Model conn *mon.Model
model.Base[Subject] *model.Base[Subject]
} }
func newDefaultSubjectModel(conn *mon.Model) *defaultSubjectModel { func newDefaultSubjectModel(conn *mon.Model) *defaultSubjectModel {
......
...@@ -14,7 +14,7 @@ type {{.lowerType}}Model interface{ ...@@ -14,7 +14,7 @@ type {{.lowerType}}Model interface{
type default{{.Type}}Model struct { type default{{.Type}}Model struct {
conn {{if .Cache}}*monc.Model{{else}}*mon.Model{{end}} conn {{if .Cache}}*monc.Model{{else}}*mon.Model{{end}}
model.Base[{{.Type}}] *model.Base[{{.Type}}]
} }
func newDefault{{.Type}}Model(conn {{if .Cache}}*monc.Model{{else}}*mon.Model{{end}}) *default{{.Type}}Model { func newDefault{{.Type}}Model(conn {{if .Cache}}*monc.Model{{else}}*mon.Model{{end}}) *default{{.Type}}Model {
......
...@@ -16,7 +16,7 @@ type BrandRank struct { ...@@ -16,7 +16,7 @@ type BrandRank struct {
middleBrands []string middleBrands []string
} }
func NewBrandData(brandDataModel model.BrandDataModel) *BrandRank { func NewBrandRank(brandDataModel model.BrandDataModel) *BrandRank {
return &BrandRank{brandDataModel: brandDataModel, rwMutex: new(sync.RWMutex)} return &BrandRank{brandDataModel: brandDataModel, rwMutex: new(sync.RWMutex)}
} }
......
...@@ -20,12 +20,12 @@ type Cache struct { ...@@ -20,12 +20,12 @@ type Cache struct {
func InitCache(config Config) { func InitCache(config Config) {
s := NewSource(config.Source) s := NewSource(config.Source)
bd := NewBrandData(config.BrandDataModel) br := NewBrandRank(config.BrandDataModel)
// 注册缓存刷新 Map // 注册缓存刷新 Map
_cache = &Cache{ _cache = &Cache{
refreshMap: map[RefreshKey]Refresh{ refreshMap: map[RefreshKey]Refresh{
RefreshKeySource: s, RefreshKeySource: s,
RefreshKeyRankBrandIds: bd, RefreshKeyRankBrandIds: br,
}, },
Source: s, Source: s,
} }
......
...@@ -29,11 +29,11 @@ import ( ...@@ -29,11 +29,11 @@ import (
type PlatformStoreSku struct { type PlatformStoreSku struct {
mongoManager *mongo.Manager mongoManager *mongo.Manager
rate rate.Rate rate *rate.Rate
brandRankCache cache.BrandRank brandRankCache *cache.BrandRank
} }
func NewPlatformStoreSku(mongoManager *mongo.Manager, rate rate.Rate, brandRankCache cache.BrandRank) *PlatformStoreSku { func NewPlatformStoreSku(mongoManager *mongo.Manager, rate *rate.Rate, brandRankCache *cache.BrandRank) *PlatformStoreSku {
return &PlatformStoreSku{mongoManager: mongoManager, rate: rate, brandRankCache: brandRankCache} return &PlatformStoreSku{mongoManager: mongoManager, rate: rate, brandRankCache: brandRankCache}
} }
......
...@@ -18,11 +18,11 @@ import ( ...@@ -18,11 +18,11 @@ import (
type Product struct { type Product struct {
cache *cache.Cache cache *cache.Cache
mongoManager *mongo.Manager mongoManager *mongo.Manager
rate rate.Rate rate *rate.Rate
brandRankCache cache.BrandRank brandRankCache *cache.BrandRank
} }
func NewProduct(cache *cache.Cache, mongoManager *mongo.Manager, rate rate.Rate, brandRankCache cache.BrandRank) *Product { func NewProduct(cache *cache.Cache, mongoManager *mongo.Manager, rate *rate.Rate, brandRankCache *cache.BrandRank) *Product {
return &Product{cache: cache, mongoManager: mongoManager, rate: rate, brandRankCache: brandRankCache} return &Product{cache: cache, mongoManager: mongoManager, rate: rate, brandRankCache: brandRankCache}
} }
......
...@@ -10,6 +10,10 @@ type Rate struct { ...@@ -10,6 +10,10 @@ type Rate struct {
rateClient *rate.Client rateClient *rate.Client
} }
func NewRate(rateClient *rate.Client) *Rate {
return &Rate{rateClient: rateClient}
}
func (receiver *Rate) GetRate(store types.Store, from, to string) (float64, error) { func (receiver *Rate) GetRate(store types.Store, from, to string) (float64, error) {
switch store { switch store {
case types.StoreTmall2cStore1, types.StoreJDStoreGongxiao: case types.StoreTmall2cStore1, types.StoreJDStoreGongxiao:
......
...@@ -2,12 +2,14 @@ package svc ...@@ -2,12 +2,14 @@ package svc
import ( import (
"git.chillcy.com/golang/chillcy/pkg/etcd" "git.chillcy.com/golang/chillcy/pkg/etcd"
rate2 "git.chillcy.com/golang/chillcy/pkg/sdk/rate"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/client/product" "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/chillcy/project/pc4/pkg/rpc/client/source"
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo" "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/config"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache" "git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/convert" "git.chillcy.com/golang/colorway/internal/rpc/internal/svc/convert"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/rate"
"github.com/zeromicro/go-zero/zrpc" "github.com/zeromicro/go-zero/zrpc"
) )
...@@ -45,7 +47,9 @@ func NewServiceContext(c config.Config) *ServiceContext { ...@@ -45,7 +47,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
}) })
svc.Cache = cache.GetCache() svc.Cache = cache.GetCache()
svc.SpuConvert = convert.NewSpu(svc.Cache) svc.SpuConvert = convert.NewSpu(svc.Cache)
svc.ProductConvert = convert.NewProduct(svc.Cache) rateClient := rate2.NewClient(etcd.Get(etcd.KeyHttpRateApiUri))
brandRank := cache.NewBrandRank(svc.MongoManager.BrandDataModel)
svc.ProductConvert = convert.NewProduct(svc.Cache, svc.MongoManager, rate.NewRate(rateClient), brandRank)
return svc return svc
} }
......
...@@ -20,7 +20,8 @@ func MemberMethodCall(obj any, methodName string, in []reflect.Value) error { ...@@ -20,7 +20,8 @@ func MemberMethodCall(obj any, methodName string, in []reflect.Value) error {
// 检查是否有 methodName 方法 // 检查是否有 methodName 方法
method := field.MethodByName(methodName) method := field.MethodByName(methodName)
if !method.IsValid() { if !method.IsValid() {
return fmt.Errorf("字段 %s 没有 %s 方法\n", fieldType.Name, methodName) //log.Println(fmt.Errorf("字段 %s 没有 %s 方法\n", fieldType.Name, methodName))
return nil
} }
// 调用 methodName 方法 // 调用 methodName 方法
......
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