| | |
| | | "errors" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "sync" |
| | | ) |
| | | |
| | | type ( |
| | | // TimeSpent 花费时间 |
| | | TimeSpent 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:'';comment:名称"` |
| | | } |
| | | |
| | | // TimeSpentSearch 花费时间搜索条件 |
| | | TimeSpentSearch struct { |
| | | TimeSpent |
| | | Orm *gorm.DB |
| | | QueryClass constvar.TimeSpentQueryClass |
| | | KeywordType constvar.TimeSpentKeywordType |
| | | Keyword string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | QueryClass constvar.TimeSpentQueryClass |
| | | KeywordType constvar.TimeSpentKeywordType |
| | | Keyword string |
| | | PageNum int |
| | | PageSize int |
| | | } |
| | | ) |
| | | |
| | |
| | | } |
| | | |
| | | // InitDefaultData 初始化数据 |
| | | func (slf *TimeSpentSearch) InitDefaultData() error { |
| | | func (slf *TimeSpentSearch) 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 := []*TimeSpent{} |
| | | return slf.CreateBatch(records) |
| | | records := []*TimeSpent{ |
| | | {1, "1小时"}, |
| | | {2, "2小时"}, |
| | | {3, "0.5个工作日"}, |
| | | {4, "1个工作日"}, |
| | | {5, "2个工作日"}, |
| | | {6, "2个工作日以上"}, |
| | | } |
| | | err := slf.CreateBatch(records) |
| | | if err != nil { |
| | | errCh <- err |
| | | return |
| | | } |
| | | } |