update 价格更新后,需要重新计算利润率
All checks were successful
Build image / build (push) Successful in 2m23s

This commit is contained in:
timerzz 2025-03-28 11:04:05 +08:00
parent 764c144f86
commit 0a5b5de491

View File

@ -126,6 +126,8 @@ func (c *Controller) providerChange(ctx context.Context, message string) error {
c.provider.CalculateProcess = provider.CalculateProcess
if needUpdate {
provider.Status = v2.ProviderStatus_Calculating
_ = c.storage.Provider().UpdateStatus(provider)
var results = make([]v2.ProviderArticle, 0, 20)
err = c.storage.ProviderArticle().FindInBatches(storage.NewGetProviderArticleQuery().SetProviderId(c.providerId), &results, func(tx *gorm.DB, batch int) error {
for idx := range results {
@ -135,8 +137,19 @@ func (c *Controller) providerChange(ctx context.Context, message string) error {
"exchangeRate": c.provider.Config.ExchangeRate,
})
}
return tx.Select("id", "cost").Save(&results).Error
if err = tx.Select("id", "cost").Save(&results).Error; err != nil {
return err
}
ids := lo.Map(results, func(item v2.ProviderArticle, index int) string {
return fmt.Sprintf("%d", item.ID)
})
if err = c.subscribeClient.Publish(c.ctx, utils.ProfitRate_Channel, strings.Join(ids, ",")); err != nil {
logrus.Errorf("通知商品利润率失败: %v", err)
}
return nil
})
provider.Status = v2.ProviderStatus_Normal
_ = c.storage.Provider().UpdateStatus(provider)
}
return err
}