From eba4eb850f0ecfb5839395aa125955ceaa2a454f Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 19 十月 2023 16:39:07 +0800
Subject: [PATCH] Merge branch 'feat-serf'

---
 model/procedures.go |   33 ++++++++++++++++-----------------
 1 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/model/procedures.go b/model/procedures.go
index 8a7f145..64d3cbb 100644
--- a/model/procedures.go
+++ b/model/procedures.go
@@ -6,22 +6,20 @@
 	"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"`
-		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"`
-		ProcedureID        string `gorm:"index;type:varchar(191);comment:宸ュ簭ID" json:"procedureId"`
-		Channel            int32  `gorm:"index;comment:閫氶亾" json:"channel"`                //閫氶亾
-		ProcessModelNumber string `gorm:"index;comment:宸ヨ壓妯″瀷缂栧彿" json:"processModelNumber"` //宸ヨ壓妯″瀷缂栧彿
-		StartTime          int64  `gorm:"comment:璁″垝寮�濮嬫椂闂�" json:"startTime"`
-		EndTime            int64  `gorm:"comment:璁″垝缁撴潫鏃堕棿" json:"endTime"`
+		WorkOrderID        string `gorm:"index;type:varchar(191);not null" json:"-"`
+		OrderID            string `gorm:"index;type:varchar(191);not null" json:"-"`
+		DeviceID           string `gorm:"index;type:varchar(191)" json:"deviceId"`
+		ProcedureID        string `gorm:"index;type:varchar(191)" json:"procedureId"`
+		Channel            int32  `gorm:"index;" json:"channel"`            //閫氶亾
+		ProcessModelNumber string `gorm:"index;" json:"processModelNumber"` //宸ヨ壓妯″瀷缂栧彿
+		StartTime          int64  `json:"startTime"`
+		EndTime            int64  `json:"endTime"`
 		Status             ProcedureStatus
 		ProcedureData      string                  `json:"-"`                  //common.ProductProcedure  json涓�
 		ProceduresInfo     common.ProductProcedure `json:"procedure" gorm:"-"` //common.ProductProcedure  瀵硅薄
@@ -106,7 +104,7 @@
 	return slf
 }
 
-func (slf *ProceduresSearch) SetId(id int) *ProceduresSearch {
+func (slf *ProceduresSearch) SetId(id uint) *ProceduresSearch {
 	slf.ID = id
 	return slf
 }
@@ -181,7 +179,7 @@
 	}
 
 	if len(slf.ProcedureIds) > 0 {
-		db = db.Where("procedure_id in ?", slf.ProcedureIds)
+		db = db.Where("procedure_id IN (?)", slf.ProcedureIds)
 	}
 
 	if slf.ProcedureID != "" {
@@ -189,7 +187,7 @@
 	}
 
 	if len(slf.Channels) > 0 {
-		db = db.Where("channel in ?", slf.Channels)
+		db = db.Where("channel IN (?)", slf.Channels)
 	}
 
 	return db
@@ -222,10 +220,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