This commit is contained in:
parent
0a5b5de491
commit
dd5b127681
@ -126,9 +126,15 @@ func (c *Controller) providerChange(ctx context.Context, message string) error {
|
||||
c.provider.CalculateProcess = provider.CalculateProcess
|
||||
|
||||
if needUpdate {
|
||||
logrus.Infof("供应商价格计算过程发生变化,重新计算所有商品价格")
|
||||
provider.Status = v2.ProviderStatus_Calculating
|
||||
_ = c.storage.Provider().UpdateStatus(provider)
|
||||
if err = c.storage.Provider().UpdateStatus(provider); err != nil {
|
||||
logrus.Errorf("更新供应商状态失败: %v", err)
|
||||
}
|
||||
|
||||
var results = make([]v2.ProviderArticle, 0, 20)
|
||||
|
||||
var processed = 0
|
||||
err = c.storage.ProviderArticle().FindInBatches(storage.NewGetProviderArticleQuery().SetProviderId(c.providerId), &results, func(tx *gorm.DB, batch int) error {
|
||||
for idx := range results {
|
||||
results[idx].Cost = utils.CalculateProviderPrice(append(provider.CalculateProcess, results[idx].CalculateProcess...), map[string]float64{
|
||||
@ -141,15 +147,19 @@ func (c *Controller) providerChange(ctx context.Context, message string) error {
|
||||
return err
|
||||
}
|
||||
ids := lo.Map(results, func(item v2.ProviderArticle, index int) string {
|
||||
return fmt.Sprintf("%d", item.ID)
|
||||
return fmt.Sprintf("%d", item.ArticleID)
|
||||
})
|
||||
if err = c.subscribeClient.Publish(c.ctx, utils.ProfitRate_Channel, strings.Join(ids, ",")); err != nil {
|
||||
logrus.Errorf("通知商品利润率失败: %v", err)
|
||||
}
|
||||
processed += len(results)
|
||||
return nil
|
||||
})
|
||||
provider.Status = v2.ProviderStatus_Normal
|
||||
_ = c.storage.Provider().UpdateStatus(provider)
|
||||
if err = c.storage.Provider().UpdateStatus(provider); err != nil {
|
||||
logrus.Errorf("更新供应商状态失败: %v", err)
|
||||
}
|
||||
logrus.Infof("重新计算所有商品价格完成共%d个", processed)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user