package model import ( "aps_crm/pkg/mysqlx" "gorm.io/gorm" ) type ( // ServiceContractType 商机阶段 ServiceContractType struct { Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` Name string `json:"name" gorm:"column:name;type:varchar(255);comment:商机阶段名称"` } ServiceContractTypeSearch struct { ServiceContractType Orm *gorm.DB } ) func (ServiceContractType) TableName() string { return "service_contract_type" } func NewServiceContractTypeSearch() *ServiceContractTypeSearch { return &ServiceContractTypeSearch{ Orm: mysqlx.GetDB(), } } func (slf *ServiceContractTypeSearch) build() *gorm.DB { var db = slf.Orm.Model(&ServiceContractType{}) if slf.Id != 0 { db = db.Where("id = ?", slf.Id) } if slf.Name != "" { db = db.Where("name = ?", slf.Name) } return db } func (slf *ServiceContractTypeSearch) Create(record *ServiceContractType) error { var db = slf.build() return db.Create(record).Error } func (slf *ServiceContractTypeSearch) Delete() error { var db = slf.build() return db.Delete(&ServiceContractType{}).Error } func (slf *ServiceContractTypeSearch) Update(record *ServiceContractType) error { var db = slf.build() return db.Updates(record).Error } func (slf *ServiceContractTypeSearch) Find() (*ServiceContractType, error) { var db = slf.build() var record = new(ServiceContractType) err := db.First(record).Error return record, err } func (slf *ServiceContractTypeSearch) FindAll() ([]*ServiceContractType, error) { var db = slf.build() var records = make([]*ServiceContractType, 0) err := db.Find(&records).Error return records, err } func (slf *ServiceContractTypeSearch) SetId(id int) *ServiceContractTypeSearch { slf.Id = id return slf } func (slf *ServiceContractTypeSearch) SetName(name string) *ServiceContractTypeSearch { slf.Name = name return slf } func (slf *ServiceContractTypeSearch) Updates(data map[string]interface{}) error { var db = slf.build() return db.Updates(data).Error }