fix 修复保存detail的问题
All checks were successful
Build image / build (push) Successful in 2m45s

This commit is contained in:
timerzz 2024-05-21 19:38:02 +08:00
parent 4d21eb72d5
commit c58fe1e4b7
2 changed files with 5 additions and 7 deletions

View File

@ -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"`

View File

@ -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