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