From bedf3229b46d1591dfb158682f3dde3027ab0d65 Mon Sep 17 00:00:00 2001 From: timerzz Date: Tue, 14 May 2024 20:29:28 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=8E=BB=E9=87=8D=E5=AF=BC=E8=87=B4=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/coach-client/client.go | 4 ++-- product/controller.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/coach-client/client.go b/pkg/coach-client/client.go index 9fb3b8b..c847417 100644 --- a/pkg/coach-client/client.go +++ b/pkg/coach-client/client.go @@ -6,9 +6,9 @@ import ( "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" restry_pool "gitea.timerzz.com/kedaya_haitao/common/pkg/restry-pool" "github.com/go-resty/resty/v2" - "github.com/golang/glog" "github.com/pkg/errors" proxy2 "github.com/timerzz/proxypool/pkg/proxy" + "log/slog" "time" ) @@ -45,7 +45,7 @@ func tryRequest(ctx context.Context, urlPath string, respData any, proxyGetter f } _, err := callByProxy(ctx, p, urlPath, respData) if err != nil { - glog.Error(err) + slog.Debug(err.Error()) continue } return nil diff --git a/product/controller.go b/product/controller.go index 612e7a7..6253a9e 100644 --- a/product/controller.go +++ b/product/controller.go @@ -96,6 +96,10 @@ func (c *Controller) saveRespData(list []coach_client.Product) error { }) } } + // 去重 + products = lo.UniqBy(products, func(p database.Product) string { + return p.Pid + }) return c.db.Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "pid"}}, DoUpdates: clause.AssignmentColumns([]string{"name", "color", "link", "orderable", "us_price", "cny_price", "cal_mark", "freight", "rate"}),