From 3ca8f1290232818ca2720fa3a9a736ca1d52a1a8 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期六, 07 十月 2023 20:42:32 +0800 Subject: [PATCH] gorm版本v2改成v1 --- model/procedures.go | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-) diff --git a/model/procedures.go b/model/procedures.go index 425a192..2d1cef2 100644 --- a/model/procedures.go +++ b/model/procedures.go @@ -6,14 +6,12 @@ "apsClient/pkg/sqlitex" "encoding/json" "fmt" - "gorm.io/gorm" - "gorm.io/gorm/clause" + "github.com/jinzhu/gorm" ) type ( Procedures struct { - gorm.Model `json:"-"` - ID int `gorm:"primarykey"` + gorm.Model WorkOrderID string `gorm:"index;type:varchar(191);not null;comment:宸ュ崟ID" json:"-"` OrderID string `gorm:"index;type:varchar(191);not null;comment:璁㈠崟ID" json:"-"` DeviceID string `gorm:"index;type:varchar(191);comment:璁惧ID" json:"deviceId"` @@ -105,7 +103,7 @@ return slf } -func (slf *ProceduresSearch) SetId(id int) *ProceduresSearch { +func (slf *ProceduresSearch) SetId(id uint) *ProceduresSearch { slf.ID = id return slf } @@ -221,10 +219,11 @@ old, err := slf.First() if err != gorm.ErrRecordNotFound && old.ID != 0 { record.ID = old.ID + err = db.Save(&record).Error + } else { + err = db.Create(&record).Error } - if err := db.Clauses(clause.OnConflict{ - UpdateAll: true, - }).Create(&record).Error; err != nil { + if err != nil { return fmt.Errorf("save err: %v, record: %+v", err, record) } -- Gitblit v1.8.0