zhangqian
2023-11-01 530fed8ec225453572d57b15c200ab062c335457
model/serviceType.go
@@ -6,24 +6,25 @@
   "errors"
   "fmt"
   "gorm.io/gorm"
   "sync"
)
type (
   // ServiceType 服务类型
   // ServiceType 服务方式
   ServiceType 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:''"`
   }
   // ServiceTypeSearch 服务类型搜索条件
   // ServiceTypeSearch 服务方式搜索条件
   ServiceTypeSearch struct {
      ServiceType
      Orm *gorm.DB
        QueryClass  constvar.ServiceTypeQueryClass
        KeywordType constvar.ServiceTypeKeywordType
        Keyword     string
        PageNum  int
        PageSize int
      Orm         *gorm.DB
      QueryClass  constvar.ServiceTypeQueryClass
      KeywordType constvar.ServiceTypeKeywordType
      Keyword     string
      PageNum     int
      PageSize    int
   }
)
@@ -49,6 +50,11 @@
func (slf *ServiceTypeSearch) Create(record *ServiceType) error {
   var db = slf.build()
   return db.Create(record).Error
}
func (slf *ServiceTypeSearch) CreateBatch(records []*ServiceType) error {
   var db = slf.build()
   return db.Create(records).Error
}
func (slf *ServiceTypeSearch) Delete() error {
@@ -111,4 +117,32 @@
   err := db.Find(&records).Error
   return records, total, err
}
}
// InitDefaultData 初始化数据
func (slf *ServiceTypeSearch) 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 := []*ServiceType{
      {1, "电话"},
      {2, "远程"},
      {3, "送修"},
      {4, "上门"},
      {5, "其他"},
   }
   err := slf.CreateBatch(records)
   if err != nil {
      errCh <- err
      return
   }
}