package model
|
|
import (
|
"aps_crm/pkg/mysqlx"
|
"gorm.io/gorm"
|
)
|
|
type (
|
// EnterpriseNature 企业性质
|
EnterpriseNature struct {
|
Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
|
Name string `json:"name" gorm:"column:name;type:varchar(255);comment:企业性质名称"`
|
}
|
|
// EnterpriseNatureSearch 企业性质搜索条件
|
EnterpriseNatureSearch struct {
|
EnterpriseNature
|
Orm *gorm.DB
|
}
|
)
|
|
func (EnterpriseNature) TableName() string {
|
return "enterprise_nature"
|
}
|
|
func NewEnterpriseNatureSearch() *EnterpriseNatureSearch {
|
return &EnterpriseNatureSearch{
|
Orm: mysqlx.GetDB(),
|
}
|
}
|
|
func (slf *EnterpriseNatureSearch) build() *gorm.DB {
|
var db = slf.Orm.Model(&EnterpriseNature{})
|
if slf.Id != 0 {
|
db = db.Where("id = ?", slf.Id)
|
}
|
if slf.Name != "" {
|
db = db.Where("name = ?", slf.Name)
|
}
|
|
return db
|
}
|
|
func (slf *EnterpriseNatureSearch) Create(record *EnterpriseNature) error {
|
var db = slf.build()
|
return db.Create(record).Error
|
}
|
|
func (slf *EnterpriseNatureSearch) Delete() error {
|
var db = slf.build()
|
return db.Delete(&EnterpriseNature{}).Error
|
}
|
|
func (slf *EnterpriseNatureSearch) Update(record *EnterpriseNature) error {
|
var db = slf.build()
|
return db.Updates(record).Error
|
}
|
|
func (slf *EnterpriseNatureSearch) Find() (*EnterpriseNature, error) {
|
var db = slf.build()
|
var result EnterpriseNature
|
err := db.First(&result).Error
|
return &result, err
|
}
|
|
func (slf *EnterpriseNatureSearch) FindAll() ([]*EnterpriseNature, error) {
|
var db = slf.build()
|
var result []*EnterpriseNature
|
err := db.Find(&result).Error
|
return result, err
|
}
|
|
func (slf *EnterpriseNatureSearch) SetId(id int) *EnterpriseNatureSearch {
|
slf.Id = id
|
return slf
|
}
|
|
func (slf *EnterpriseNatureSearch) SetName(name string) *EnterpriseNatureSearch {
|
slf.Name = name
|
return slf
|
}
|
|
func (slf *EnterpriseNatureSearch) Updates(data map[string]interface{}) error {
|
var db = slf.build()
|
return db.Updates(data).Error
|
}
|