| | |
| | | "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"` |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProceduresSearch) SetId(id int) *ProceduresSearch { |
| | | func (slf *ProceduresSearch) SetId(id uint) *ProceduresSearch { |
| | | slf.ID = id |
| | | return slf |
| | | } |
| | |
| | | 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) |
| | | } |
| | | |