From c58fe1e4b7d7619c92400d3928a557def484ebda Mon Sep 17 00:00:00 2001 From: timerzz Date: Tue, 21 May 2024 19:38:02 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E4=BF=9D=E5=AD=98detai?= =?UTF-8?q?l=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/model/watcher.go | 2 +- pkg/watcher/coach.go | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/model/watcher.go b/pkg/model/watcher.go index 431315d..e3f7686 100644 --- a/pkg/model/watcher.go +++ b/pkg/model/watcher.go @@ -14,7 +14,7 @@ type WatchInfo struct { DeletedAt gorm.DeletedAt `gorm:"index"` UpdateErr bool `json:"updateErr"` //更新出错了 - Uid string `json:"uid" gorm:"index:,unique"` + Uid string `json:"uid" gorm:"index:,unique,not null"` Pid string `json:"pid" gorm:"index:,not null"` //产品编号 Name string `json:"name"` Brand string `json:"brand"` diff --git a/pkg/watcher/coach.go b/pkg/watcher/coach.go index 6dc762c..b4422ed 100644 --- a/pkg/watcher/coach.go +++ b/pkg/watcher/coach.go @@ -8,7 +8,6 @@ import ( "gitea.timerzz.com/kedaya_haitao/pusher/rpc/pusher" "github.com/golang/glog" "gorm.io/gorm" - "gorm.io/gorm/clause" "haitao_watcher/pkg/model" "math/rand/v2" "time" @@ -42,6 +41,7 @@ func (c *CoachOutlet) SetOption(cfg model.WatchInfo) { func (c *CoachOutlet) Cancel() { c.cancel() + c.db.Where("uid = ?", c.cfg.Uid).Model(c.cfg).Update("watch", false) } func (c *CoachOutlet) Restart() { @@ -52,7 +52,7 @@ func (c *CoachOutlet) Restart() { func (c *CoachOutlet) Watch() { c.ctx, c.cancel = context.WithCancel(c.fCtx) c.cfg.Watch, c.cfg.Orderable = true, false - if err := c.db.Model(c.cfg).Where("uid", c.cfg.Uid).Updates(map[string]interface{}{"watch": true, "orderable": false}).Error; err != nil { + if err := c.db.Model(c.cfg).Where("uid = ?", c.cfg.Uid).Updates(map[string]interface{}{"watch": true, "orderable": false}).Error; err != nil { glog.Errorf("watch update db err: %v", err) err = nil } @@ -102,10 +102,8 @@ func (c *CoachOutlet) doWatch() bool { if c.cfg.Orderable { c.cfg.Watch = false } - err = c.db.Clauses(clause.OnConflict{ - Columns: []clause.Column{{Name: "uid"}}, - UpdateAll: true, - }).Create(c.cfg).Error + c.cfg.UpdatedAt = time.Now() + err = c.db.Where("uid = ?", c.cfg.Uid).Select("name", "brand", "watch", "orderable", "link", "remark", "has_detail", "allocation_reset_date", "updated_at").Updates(c.cfg).Error if err != nil { glog.Errorf("保存 %s detail失败:%v", c.cfg.Uid, err) c.cfg.HasDetail = false