From c0305be973254bd1b5a351064f8639d490564b30 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 18 八月 2023 10:13:09 +0800 Subject: [PATCH] 增加一些表的数据初始化 --- model/serviceContractType.go | 32 +++++++++++++++++++++++++++++--- 1 files changed, 29 insertions(+), 3 deletions(-) diff --git a/model/serviceContractType.go b/model/serviceContractType.go index 086ca06..3524737 100644 --- a/model/serviceContractType.go +++ b/model/serviceContractType.go @@ -6,12 +6,12 @@ ) type ( - // ServiceContractType 鍟嗘満闃舵 + // ServiceContractType 鏈嶅姟鍚堝悓绫诲瀷 ServiceContractType struct { Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - Name string `json:"name" gorm:"column:name;type:varchar(255);comment:鍟嗘満闃舵鍚嶇О"` + Name string `json:"name" gorm:"column:name;type:varchar(255);comment:鏈嶅姟鍚堝悓绫诲瀷鍚嶇О"` } - + ServiceContractTypeSearch struct { ServiceContractType Orm *gorm.DB @@ -83,3 +83,29 @@ var db = slf.build() return db.Updates(data).Error } + +func (slf *ServiceContractTypeSearch) CreateBatch(records []*ServiceContractType) error { + var db = slf.build() + return db.Create(records).Error +} + +// InitDefaultData 鍒濆鍖栨暟鎹� +func (slf *ServiceContractTypeSearch) 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 := []*ServiceContractType{ + {1, "鎸夊勾"}, + {2, "鎸夋"}, + {3, "鍏朵粬"}, + {4, "铏氭嫙鍚堝悓"}, + } + return slf.CreateBatch(records) +} -- Gitblit v1.8.0