From ff3e203423f296965472d1f09347cda5cfe3a786 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 11 八月 2023 11:37:19 +0800 Subject: [PATCH] update --- model/serviceType.go | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-) diff --git a/model/serviceType.go b/model/serviceType.go index 7e6f686..e5f7214 100644 --- a/model/serviceType.go +++ b/model/serviceType.go @@ -9,13 +9,13 @@ ) type ( - // ServiceType 鏈嶅姟绫诲瀷 + // ServiceType 鏈嶅姟鏂瑰紡 ServiceType struct { Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` Name string `json:"name" gorm:"column:name"` } - // ServiceTypeSearch 鏈嶅姟绫诲瀷鎼滅储鏉′欢 + // ServiceTypeSearch 鏈嶅姟鏂瑰紡鎼滅储鏉′欢 ServiceTypeSearch struct { ServiceType Orm *gorm.DB @@ -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,20 @@ 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{} + return slf.CreateBatch(records) +} -- Gitblit v1.8.0