zhangqian
2023-08-11 ff3e203423f296965472d1f09347cda5cfe3a786
model/serviceType.go
@@ -9,13 +9,13 @@
)
type (
   // ServiceType 服务类型
   // ServiceType 服务方式
   ServiceType struct {
      Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
      Name   string    `json:"name" gorm:"column:name"`
   }
   // ServiceTypeSearch 服务类型搜索条件
   // ServiceTypeSearch 服务方式搜索条件
   ServiceTypeSearch struct {
      ServiceType
      Orm *gorm.DB
@@ -49,6 +49,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 +116,20 @@
   err := db.Find(&records).Error
   return records, total, err
}
}
// InitDefaultData 初始化数据
func (slf *ServiceTypeSearch) 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 := []*ServiceType{}
   return slf.CreateBatch(records)
}