From 0a5b5de4910ee2ef2ea7290ea6c9ac0840c2ed59 Mon Sep 17 00:00:00 2001 From: timerzz Date: Fri, 28 Mar 2025 11:04:05 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BB=B7=E6=A0=BC=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E9=9C=80=E8=A6=81=E9=87=8D=E6=96=B0=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E5=88=A9=E6=B6=A6=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spider/controller.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spider/controller.go b/spider/controller.go index b8bcfe8..c611e5f 100644 --- a/spider/controller.go +++ b/spider/controller.go @@ -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 }