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/priorityLevel.go | 37 +++++++++++++++++++++++++------------ 1 files changed, 25 insertions(+), 12 deletions(-) diff --git a/model/priorityLevel.go b/model/priorityLevel.go index fad265d..b1902f4 100644 --- a/model/priorityLevel.go +++ b/model/priorityLevel.go @@ -6,24 +6,25 @@ "errors" "fmt" "gorm.io/gorm" + "sync" ) type ( // PriorityLevel 浼樺厛绾у埆 PriorityLevel 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"` } // PriorityLevelSearch 浼樺厛绾у埆鎼滅储鏉′欢 PriorityLevelSearch struct { PriorityLevel - Orm *gorm.DB - QueryClass constvar.PriorityLevelQueryClass - KeywordType constvar.PriorityLevelKeywordType - Keyword string - PageNum int - PageSize int + Orm *gorm.DB + QueryClass constvar.PriorityLevelQueryClass + KeywordType constvar.PriorityLevelKeywordType + Keyword string + PageNum int + PageSize int } ) @@ -119,17 +120,29 @@ } // InitDefaultData 鍒濆鍖栨暟鎹� -func (slf *PriorityLevelSearch) InitDefaultData() error { +func (slf *PriorityLevelSearch) 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 := []*PriorityLevel{} - return slf.CreateBatch(records) + records := []*PriorityLevel{ + {1, "浣�"}, + {2, "涓�鑸�"}, + {3, "楂�"}, + {4, "绱ф��"}, + } + err := slf.CreateBatch(records) + if err != nil { + errCh <- err + return + } } -- Gitblit v1.8.0