diff --git a/structs/storage/provider-article.go b/structs/storage/provider-article.go index b548b2a..6f61270 100644 --- a/structs/storage/provider-article.go +++ b/structs/storage/provider-article.go @@ -10,9 +10,11 @@ import ( type ProviderArticleApi interface { Get(query *GetProviderArticleQuery) (article v2.ProviderArticle, err error) Upsert(article v2.ProviderArticle) error + Update(providerArticle v2.ProviderArticle, selects ...string) error BatchUpdate(articles []v2.ProviderArticle) error AutoMigrate() error FindInBatches(query *GetProviderArticleQuery, results *[]v2.ProviderArticle, f func(tx *gorm.DB, batch int) error) error + ProviderPrice(query *GetProviderArticleQuery) (history v2.ProviderPrice, err error) } type providerArticleApi struct { @@ -110,3 +112,15 @@ func (p *providerArticleApi) BatchUpdate(articles []v2.ProviderArticle) error { func (p *providerArticleApi) AutoMigrate() error { return p.db.AutoMigrate(&v2.ProviderArticle{}, &v2.ProviderPrice{}) } + +func (p *providerArticleApi) ProviderPrice(query *GetProviderArticleQuery) (history v2.ProviderPrice, err error) { + err = p.db.Scopes(query.Scope).Find(&history).Error + return +} + +func (p *providerArticleApi) Update(providerArticle v2.ProviderArticle, selects ...string) error { + if len(selects) == 0 { + selects = []string{"Exclude"} + } + return p.db.Model(&providerArticle).Select(selects).Omit(clause.Associations).Updates(&providerArticle).Error +} diff --git a/structs/storage/seller-article.go b/structs/storage/seller-article.go index cf0323d..cab65c5 100644 --- a/structs/storage/seller-article.go +++ b/structs/storage/seller-article.go @@ -10,8 +10,10 @@ import ( type SellerArticleApi interface { Get(query *GetSellerArticleQuery) (article v2.SellerArticle, err error) Upsert(article v2.SellerArticle) error + Update(sellerArticle v2.SellerArticle, selects ...string) error FindInBatches(query *GetSellerArticleQuery, results *[]v2.SellerArticle, f func(tx *gorm.DB, batch int) error) error AutoMigrate() error + SellerPrice(query *GetSellerArticleQuery) (history v2.SellerPrice, err error) } type sellerArticleApi struct { @@ -106,3 +108,15 @@ func (p *sellerArticleApi) BatchUpdate(articles []v2.SellerArticle) error { func (p *sellerArticleApi) AutoMigrate() error { return p.db.AutoMigrate(&v2.SellerArticle{}, &v2.SellerPrice{}) } + +func (p *sellerArticleApi) SellerPrice(query *GetSellerArticleQuery) (history v2.SellerPrice, err error) { + err = p.db.Scopes(query.Scope).Find(&history).Error + return +} + +func (p *sellerArticleApi) Update(sellerArticle v2.SellerArticle, selects ...string) error { + if len(selects) == 0 { + selects = []string{"Exclude"} + } + return p.db.Model(&sellerArticle).Select(selects).Omit(clause.Associations).Updates(&sellerArticle).Error +}