From b2d029364843fdac6524b7ba8ad2d293f7e37eea Mon Sep 17 00:00:00 2001 From: timerzz Date: Mon, 9 Sep 2024 15:16:00 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E4=BB=B7=E6=A0=BC=E5=92=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?exclude=20=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- structs/storage/provider-article.go | 14 ++++++++++++++ structs/storage/seller-article.go | 14 ++++++++++++++ 2 files changed, 28 insertions(+) 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 +}