From b331c9990a0396301e934daffe095f99d62d1c89 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 27 九月 2023 15:58:49 +0800
Subject: [PATCH] 任务获取修改,状态2只返回已开始和已结束的

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

diff --git a/model/procedures.go b/model/procedures.go
index cb8d660..425a192 100644
--- a/model/procedures.go
+++ b/model/procedures.go
@@ -7,6 +7,7 @@
 	"encoding/json"
 	"fmt"
 	"gorm.io/gorm"
+	"gorm.io/gorm/clause"
 )
 
 type (
@@ -215,6 +216,21 @@
 	return nil
 }
 
+func (slf *ProceduresSearch) Upsert(record *Procedures) error {
+	var db = slf.build()
+	old, err := slf.First()
+	if err != gorm.ErrRecordNotFound && old.ID != 0 {
+		record.ID = old.ID
+	}
+	if err := db.Clauses(clause.OnConflict{
+		UpdateAll: true,
+	}).Create(&record).Error; err != nil {
+		return fmt.Errorf("save err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}
+
 func (slf *ProceduresSearch) Updates(record *Procedures) error {
 	var db = slf.build()
 

--
Gitblit v1.8.0