From 530fed8ec225453572d57b15c200ab062c335457 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 01 十一月 2023 19:20:21 +0800 Subject: [PATCH] 公海member_id使用0 --- model/clientLevel.go | 38 ++++++++++++++++++++++++++++++++++++-- 1 files changed, 36 insertions(+), 2 deletions(-) diff --git a/model/clientLevel.go b/model/clientLevel.go index 6070b40..23ce754 100644 --- a/model/clientLevel.go +++ b/model/clientLevel.go @@ -3,12 +3,13 @@ import ( "aps_crm/pkg/mysqlx" "gorm.io/gorm" + "sync" ) type ( ClientLevel struct { - ID int `json:"id"` - Name string `json:"name"` + ID int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + Name string `json:"name" gorm:"column:name;type:varchar(255);comment:瀹㈡埛绛夌骇鍚嶇О"` } ClientLevelSearch struct { @@ -82,3 +83,36 @@ var db = slf.build() return db.Updates(data).Error } + +func (slf *ClientLevelSearch) CreateBatch(records []*ClientLevel) error { + var db = slf.build() + return db.Create(records).Error +} + +// InitDefaultData 鍒濆鍖栨暟鎹� +func (slf *ClientLevelSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) { + var ( + db = slf.Orm.Table(slf.TableName()) + total int64 = 0 + ) + defer wg.Done() + + if err := db.Count(&total).Error; err != nil { + errCh <- err + return + } + if total != 0 { + return + } + records := []*ClientLevel{ + {1, "閲嶇偣鍏虫敞瀹㈡埛"}, + {2, "浼樿川瀹㈡埛"}, + {3, "鏅�氬鎴�"}, + {4, "鍏朵粬"}, + } + err := slf.CreateBatch(records) + if err != nil { + errCh <- err + return + } +} -- Gitblit v1.8.0