feat 添加获取历史价格和更新exclude 的方法

This commit is contained in:
timerzz 2024-09-09 15:16:00 +08:00
parent fb9918e266
commit b2d0293648
2 changed files with 28 additions and 0 deletions

View File

@ -10,9 +10,11 @@ import (
type ProviderArticleApi interface { type ProviderArticleApi interface {
Get(query *GetProviderArticleQuery) (article v2.ProviderArticle, err error) Get(query *GetProviderArticleQuery) (article v2.ProviderArticle, err error)
Upsert(article v2.ProviderArticle) error Upsert(article v2.ProviderArticle) error
Update(providerArticle v2.ProviderArticle, selects ...string) error
BatchUpdate(articles []v2.ProviderArticle) error BatchUpdate(articles []v2.ProviderArticle) error
AutoMigrate() error AutoMigrate() error
FindInBatches(query *GetProviderArticleQuery, results *[]v2.ProviderArticle, f func(tx *gorm.DB, batch int) error) 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 { type providerArticleApi struct {
@ -110,3 +112,15 @@ func (p *providerArticleApi) BatchUpdate(articles []v2.ProviderArticle) error {
func (p *providerArticleApi) AutoMigrate() error { func (p *providerArticleApi) AutoMigrate() error {
return p.db.AutoMigrate(&v2.ProviderArticle{}, &v2.ProviderPrice{}) 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
}

View File

@ -10,8 +10,10 @@ import (
type SellerArticleApi interface { type SellerArticleApi interface {
Get(query *GetSellerArticleQuery) (article v2.SellerArticle, err error) Get(query *GetSellerArticleQuery) (article v2.SellerArticle, err error)
Upsert(article v2.SellerArticle) 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 FindInBatches(query *GetSellerArticleQuery, results *[]v2.SellerArticle, f func(tx *gorm.DB, batch int) error) error
AutoMigrate() error AutoMigrate() error
SellerPrice(query *GetSellerArticleQuery) (history v2.SellerPrice, err error)
} }
type sellerArticleApi struct { type sellerArticleApi struct {
@ -106,3 +108,15 @@ func (p *sellerArticleApi) BatchUpdate(articles []v2.SellerArticle) error {
func (p *sellerArticleApi) AutoMigrate() error { func (p *sellerArticleApi) AutoMigrate() error {
return p.db.AutoMigrate(&v2.SellerArticle{}, &v2.SellerPrice{}) 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
}