From 663db1dd160e759c9401289554543b1d1ea1e5cb Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期六, 05 八月 2023 12:17:17 +0800
Subject: [PATCH] 服务单管理故障类别增删改查,服务单管理花费时间增删改查,增加服务方式、花费时间、严重程度、优先级别初始化数据

---
 model/serviceType.go |   43 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/model/serviceType.go b/model/serviceType.go
index 7e6f686..402a9a5 100644
--- a/model/serviceType.go
+++ b/model/serviceType.go
@@ -12,18 +12,18 @@
 	// ServiceType 鏈嶅姟绫诲瀷
 	ServiceType struct {
 		Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		Name   string    `json:"name" gorm:"column:name"`
+		Name string `json:"name" gorm:"column:name"`
 	}
 
 	// ServiceTypeSearch 鏈嶅姟绫诲瀷鎼滅储鏉′欢
 	ServiceTypeSearch struct {
 		ServiceType
-		Orm *gorm.DB
-        QueryClass  constvar.ServiceTypeQueryClass
-        KeywordType constvar.ServiceTypeKeywordType
-        Keyword     string
-        PageNum  int
-        PageSize int
+		Orm         *gorm.DB
+		QueryClass  constvar.ServiceTypeQueryClass
+		KeywordType constvar.ServiceTypeKeywordType
+		Keyword     string
+		PageNum     int
+		PageSize    int
 	}
 )
 
@@ -49,6 +49,11 @@
 func (slf *ServiceTypeSearch) Create(record *ServiceType) error {
 	var db = slf.build()
 	return db.Create(record).Error
+}
+
+func (slf *ServiceTypeSearch) CreateBatch(records []*ServiceType) error {
+	var db = slf.build()
+	return db.Create(records).Error
 }
 
 func (slf *ServiceTypeSearch) Delete() error {
@@ -111,4 +116,26 @@
 
 	err := db.Find(&records).Error
 	return records, total, err
-}
\ No newline at end of file
+}
+
+// InitDefaultData 鍒濆鍖栨暟鎹�
+func (slf *ServiceTypeSearch) InitDefaultData() error {
+	var (
+		db          = slf.Orm.Table(slf.TableName())
+		total int64 = 0
+	)
+	if err := db.Count(&total).Error; err != nil {
+		return err
+	}
+	if total != 0 {
+		return nil
+	}
+	records := []*ServiceType{
+		{Name: "鐢佃瘽"},
+		{Name: "杩滅▼"},
+		{Name: "閫佷慨"},
+		{Name: "涓婇棬"},
+		{Name: "鍏朵粬"},
+	}
+	return slf.CreateBatch(records)
+}

--
Gitblit v1.8.0