liujiandao
2023-11-18 115bd9b51f5d8eade4658f844de37516486c60e7
model/serviceType.go
@@ -6,24 +6,25 @@
   "errors"
   "fmt"
   "gorm.io/gorm"
   "sync"
)
type (
   // 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 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
   }
)
@@ -119,17 +120,29 @@
}
// InitDefaultData 初始化数据
func (slf *ServiceTypeSearch) InitDefaultData() error {
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 {
      return err
      errCh <- err
      return
   }
   if total != 0 {
      return nil
      return
   }
   records := []*ServiceType{}
   return slf.CreateBatch(records)
   records := []*ServiceType{
      {1, "电话"},
      {2, "远程"},
      {3, "送修"},
      {4, "上门"},
      {5, "其他"},
   }
   err := slf.CreateBatch(records)
   if err != nil {
      errCh <- err
      return
   }
}