package model import ( "aps_crm/pkg/mysqlx" "gorm.io/gorm" ) type ( Vetting struct { Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` // 审批意见 Opinion string `json:"opinion" gorm:"column:opinion;type:varchar(255);comment:审批意见"` // 审批状态 Status int `json:"status" gorm:"column:status;type:int;comment:审批状态"` // 审批人 UserId int `json:"userId" gorm:"column:user_id;type:int;comment:审批人"` // 审批类型 VettingType int `json:"vettingType" gorm:"column:vetting_type;type:int;comment:审批类型"` // 审批单号 VettingId int `json:"vettingId" gorm:"column:vetting_id;type:int;comment:审批单号"` gorm.Model `json:"-"` } VettingSearch struct { Vetting Orm *gorm.DB } ) func (Vetting) TableName() string { return "vetting" } func NewVettingSearch() *VettingSearch { return &VettingSearch{ Orm: mysqlx.GetDB(), } } func (slf *VettingSearch) build() *gorm.DB { var db = slf.Orm.Model(&Vetting{}) if slf.Id != 0 { db = db.Where("id = ?", slf.Id) } if slf.UserId != 0 { db = db.Where("user_id = ?", slf.UserId) } if slf.Status != 0 { db = db.Where("status = ?", slf.Status) } return db } func (slf *VettingSearch) Create(record *Vetting) error { var db = slf.build() return db.Create(record).Error } func (slf *VettingSearch) Delete() error { var db = slf.build() return db.Delete(&Vetting{}).Error } func (slf *VettingSearch) Update(record *Vetting) error { var db = slf.build() return db.Updates(record).Error } func (slf *VettingSearch) Get() (*Vetting, error) { var db = slf.build() var record = &Vetting{} err := db.First(record).Error return record, err } func (slf *VettingSearch) FindAll() ([]*Vetting, error) { var db = slf.build() var records = make([]*Vetting, 0) err := db.Find(&records).Error return records, err } func (slf *VettingSearch) SetId(id int) *VettingSearch { slf.Id = id return slf } func (slf *VettingSearch) SetUserId(userId int) *VettingSearch { slf.UserId = userId return slf } func (slf *VettingSearch) SetStatus(status int) *VettingSearch { slf.Status = status return slf }