| | |
| | | // 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 (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 { |
| | |
| | | |
| | | err := db.Find(&records).Error |
| | | return records, total, err |
| | | } |
| | | } |
| | | |
| | | // InitDefaultData 初始化数据 |
| | | func (slf *SeveritySearch) 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 := []*Severity{ |
| | | {Name: "轻"}, |
| | | {Name: "严重"}, |
| | | {Name: "较严重"}, |
| | | {Name: "特严重"}, |
| | | } |
| | | return slf.CreateBatch(records) |
| | | } |