From 115bd9b51f5d8eade4658f844de37516486c60e7 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期六, 18 十一月 2023 17:25:25 +0800 Subject: [PATCH] crm获取aps项目模块信息 --- model/serviceType.go | 31 +++++++++++++++++++------------ 1 files changed, 19 insertions(+), 12 deletions(-) diff --git a/model/serviceType.go b/model/serviceType.go index 402a9a5..b3e6348 100644 --- a/model/serviceType.go +++ b/model/serviceType.go @@ -6,16 +6,17 @@ "errors" "fmt" "gorm.io/gorm" + "sync" ) type ( - // ServiceType 鏈嶅姟绫诲瀷 + // 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;type:varchar(255);not null;default:''"` } - // ServiceTypeSearch 鏈嶅姟绫诲瀷鎼滅储鏉′欢 + // ServiceTypeSearch 鏈嶅姟鏂瑰紡鎼滅储鏉′欢 ServiceTypeSearch struct { ServiceType Orm *gorm.DB @@ -119,23 +120,29 @@ } // InitDefaultData 鍒濆鍖栨暟鎹� -func (slf *ServiceTypeSearch) InitDefaultData() error { +func (slf *ServiceTypeSearch) 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 { - return err + errCh <- err + return } if total != 0 { - return nil + return } records := []*ServiceType{ - {Name: "鐢佃瘽"}, - {Name: "杩滅▼"}, - {Name: "閫佷慨"}, - {Name: "涓婇棬"}, - {Name: "鍏朵粬"}, + {1, "鐢佃瘽"}, + {2, "杩滅▼"}, + {3, "閫佷慨"}, + {4, "涓婇棬"}, + {5, "鍏朵粬"}, } - return slf.CreateBatch(records) + err := slf.CreateBatch(records) + if err != nil { + errCh <- err + return + } } -- Gitblit v1.8.0