| | |
| | | "errors" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "sync" |
| | | ) |
| | | |
| | | type ( |
| | | // BankAccount 银行账户 |
| | | BankAccount 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"` |
| | | } |
| | | |
| | | // BankAccountSearch 银行账户搜索条件 |
| | | BankAccountSearch struct { |
| | | BankAccount |
| | | Orm *gorm.DB |
| | | QueryClass constvar.BankAccountQueryClass |
| | | KeywordType constvar.BankAccountKeywordType |
| | | Keyword string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | QueryClass constvar.BankAccountQueryClass |
| | | KeywordType constvar.BankAccountKeywordType |
| | | Keyword string |
| | | PageNum int |
| | | PageSize int |
| | | } |
| | | ) |
| | | |
| | |
| | | } |
| | | |
| | | // InitDefaultData 初始化数据 |
| | | func (slf *BankAccountSearch) InitDefaultData() error { |
| | | func (slf *BankAccountSearch) 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 := []*BankAccount{} |
| | | return slf.CreateBatch(records) |
| | | records := []*BankAccount{ |
| | | {1, "默认账户"}, |
| | | } |
| | | err := slf.CreateBatch(records) |
| | | if err != nil { |
| | | errCh <- err |
| | | return |
| | | } |
| | | } |