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/severity.go |   52 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/model/severity.go b/model/severity.go
index 0fb1bc0..51284df 100644
--- a/model/severity.go
+++ b/model/severity.go
@@ -6,29 +6,30 @@
 	"errors"
 	"fmt"
 	"gorm.io/gorm"
+	"sync"
 )
 
 type (
 	// Severity 涓ラ噸绋嬪害
 	Severity 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"`
 	}
 
 	// SeveritySearch 涓ラ噸绋嬪害鎼滅储鏉′欢
 	SeveritySearch struct {
 		Severity
-		Orm *gorm.DB
-        QueryClass  constvar.SeverityQueryClass
-        KeywordType constvar.SeverityKeywordType
-        Keyword     string
-        PageNum  int
-        PageSize int
+		Orm         *gorm.DB
+		QueryClass  constvar.SeverityQueryClass
+		KeywordType constvar.SeverityKeywordType
+		Keyword     string
+		PageNum     int
+		PageSize    int
 	}
 )
 
 func (Severity) TableName() string {
-	return "severity"
+	return "severity_order"
 }
 
 func NewSeveritySearch() *SeveritySearch {
@@ -49,6 +50,11 @@
 func (slf *SeveritySearch) Create(record *Severity) error {
 	var db = slf.build()
 	return db.Create(record).Error
+}
+
+func (slf *SeveritySearch) CreateBatch(records []*Severity) error {
+	var db = slf.build()
+	return db.Create(records).Error
 }
 
 func (slf *SeveritySearch) Delete() error {
@@ -111,4 +117,32 @@
 
 	err := db.Find(&records).Error
 	return records, total, err
-}
\ No newline at end of file
+}
+
+// InitDefaultData 鍒濆鍖栨暟鎹�
+func (slf *SeveritySearch) 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 := []*Severity{
+		{1, "杞�"},
+		{2, "涓ラ噸"},
+		{3, "杈冧弗閲�"},
+		{4, "鐗逛弗閲�"},
+	}
+	err := slf.CreateBatch(records)
+	if err != nil {
+		errCh <- err
+		return
+	}
+}

--
Gitblit v1.8.0