Compare commits

..

No commits in common. "eb8632ab443501d3ea3acbe35e13806d78aa53d2" and "35ca258311ca0db3c8f95782152d38b1d44dcdf3" have entirely different histories.

4 changed files with 1 additions and 55 deletions

View File

@ -10,9 +10,7 @@ import (
type ProviderArticleApi interface {
Get(query *GetProviderArticleQuery) (article v2.ProviderArticle, err error)
Upsert(article v2.ProviderArticle) error
BatchUpdate(articles []v2.ProviderArticle) error
AutoMigrate() error
FindInBatches(query *GetProviderArticleQuery, results *[]v2.ProviderArticle, f func(tx *gorm.DB, batch int) error) error
}
type providerArticleApi struct {
@ -91,16 +89,6 @@ func (p *providerArticleApi) Upsert(article v2.ProviderArticle) error {
}).Create(&article).Error
}
func (p *providerArticleApi) FindInBatches(query *GetProviderArticleQuery, results *[]v2.ProviderArticle, f func(tx *gorm.DB, batch int) error) error {
err := p.db.Scopes(query.Scope).Preload("CalculateProcess").FindInBatches(results, 20, f).Error
return err
}
// 批量更新,更新价格时用到
func (p *providerArticleApi) BatchUpdate(articles []v2.ProviderArticle) error {
return p.db.Select("id", "cost").Save(&articles).Error
}
func (p *providerArticleApi) AutoMigrate() error {
return p.db.AutoMigrate(&v2.ProviderArticle{})
}

View File

@ -1,11 +1,9 @@
package storage
import (
"fmt"
"testing"
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
"gorm.io/gorm"
)
var providerArticle = v2.ProviderArticle{
@ -32,23 +30,3 @@ func TestProviderArticleApi_Upsert(t *testing.T) {
storage := NewStorage(db)
storage.ProviderArticle().Upsert(providerArticle)
}
func TestProviderArticleApi_FindInBatches(t *testing.T) {
db, err := GetDevDB()
if err != nil {
t.Fatal(err)
}
storage := NewStorage(db)
var results = make([]v2.ProviderArticle, 0)
err = storage.ProviderArticle().FindInBatches(&GetProviderArticleQuery{ProviderId: "1"}, &results, func(tx *gorm.DB, batch int) error {
for idx := range results {
results[idx].Link = fmt.Sprintf("test_%d", idx)
results[idx].SkuID = fmt.Sprintf("sku_%d", idx)
}
return db.Select("id", "link").Save(&results).Error
})
if err != nil {
t.Fatal(err)
}
}

View File

@ -8,9 +8,8 @@ import (
// SellerArticleApi 管理供应商商品的接口
type SellerArticleApi interface {
Get(query *GetSellerArticleQuery) (article v2.SellerArticle, err error)
Get(query *GetProviderArticleQuery) (article v2.ProviderArticle, err error)
Upsert(article v2.SellerArticle) error
FindInBatches(query *GetSellerArticleQuery, results *[]v2.SellerArticle, f func(tx *gorm.DB, batch int) error) error
AutoMigrate() error
}
@ -18,10 +17,6 @@ type sellerArticleApi struct {
db *gorm.DB
}
func NewSellerArticleApi(db *gorm.DB) SellerArticleApi {
return &sellerArticleApi{db: db}
}
type GetSellerArticleQuery struct {
ID uint `query:"id"`
Brand v2.Brand `query:"brand"`
@ -87,16 +82,6 @@ func (p *sellerArticleApi) Upsert(article v2.SellerArticle) error {
}).Create(&article).Error
}
func (p *sellerArticleApi) FindInBatches(query *GetSellerArticleQuery, results *[]v2.SellerArticle, f func(tx *gorm.DB, batch int) error) error {
err := p.db.Scopes(query.Scope).Preload("CalculateProcess").FindInBatches(results, 20, f).Error
return err
}
// 批量更新,更新价格时用到
func (p *sellerArticleApi) BatchUpdate(articles []v2.SellerArticle) error {
return p.db.Select("id", "sell").Save(&articles).Error
}
func (p *sellerArticleApi) AutoMigrate() error {
return p.db.AutoMigrate(&v2.SellerArticle{})
}

View File

@ -16,7 +16,6 @@ func NewStorage(db *gorm.DB) *Storage {
providerApi: NewProviderApi(db),
providerArticleApi: NewProviderArticleApi(db),
sellerApi: NewSellerApi(db),
sellerArticleApi: NewSellerArticleApi(db),
}
}
@ -34,7 +33,3 @@ func (s *Storage) ProviderArticle() ProviderArticleApi {
func (s *Storage) Seller() SellerApi {
return s.sellerApi
}
func (s *Storage) SellerArticle() SellerArticleApi {
return s.sellerArticleApi
}