| | |
| | | WorkshopManage struct { |
| | | gorm.Model |
| | | WorkshopNumber string `json:"workshopNumber" gorm:"type:varchar(255);comment:车间编号"` |
| | | WorkshopName string `json:"workshopName" gorm:"type:varchar(255);comment:车间名称"` |
| | | GroupNumber int `json:"groupNumber" gorm:"type:int(11);comment:组别"` |
| | | StartCarNumber int `json:"startCarNumber" gorm:"type:int(11);comment:组别"` |
| | | EndCarNumber int `json:"endCarNumber" gorm:"type:int(11);comment:组别"` |
| | | StartCarNumber int `json:"startCarNumber" gorm:"type:int(11);comment:开始车号"` |
| | | EndCarNumber int `json:"endCarNumber" gorm:"type:int(11);comment:结束车号"` |
| | | CarFlag constvar.CarFlag `json:"carFlag" gorm:"type:int(1);comment:半车标志"` |
| | | Notes string `json:"notes" gorm:"type:varchar(255);comment:备注"` |
| | | } |
| | |
| | | WorkshopManage |
| | | PageNum int |
| | | PageSize int |
| | | Order string |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | | |
| | | func (slf WorkshopManage) TableName() string { |
| | | return "workshop_manage" |
| | | return "silk_workshop_manage" |
| | | } |
| | | |
| | | func NewWorkshopManageSearch() *WorkshopManageSearch { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WorkshopManageSearch) SetWorkshopNumber(workshopNumber string) *WorkshopManageSearch { |
| | | slf.WorkshopNumber = workshopNumber |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WorkshopManageSearch) SetWorkshopName(workshopName string) *WorkshopManageSearch { |
| | | slf.WorkshopName = workshopName |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WorkshopManageSearch) SetGroupNumber(groupNumber int) *WorkshopManageSearch { |
| | | slf.GroupNumber = groupNumber |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WorkshopManageSearch) SetOrder(order string) *WorkshopManageSearch { |
| | | slf.Order = order |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WorkshopManageSearch) build() *gorm.DB { |
| | | db := slf.Orm.Table(slf.TableName()) |
| | | |
| | | if slf.ID > 0 { |
| | | db = db.Where("id = ?", slf.ID) |
| | | } |
| | | |
| | | if slf.WorkshopNumber != "" { |
| | | db = db.Where("workshop_number = ?", slf.WorkshopNumber) |
| | | } |
| | | |
| | | if slf.WorkshopName != "" { |
| | | db = db.Where("workshop_name = ?", slf.WorkshopName) |
| | | } |
| | | |
| | | if slf.GroupNumber != 0 { |
| | | db = db.Where("group_number = ?", slf.GroupNumber) |
| | | } |
| | | |
| | | return db |
| | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | if err := db.Order("updated_at desc").Find(&records).Error; err != nil { |
| | | return records, total, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, total, nil |
| | | } |
| | | |
| | | func (slf *WorkshopManageSearch) FindAll() ([]*WorkshopManage, error) { |
| | | var ( |
| | | records = make([]*WorkshopManage, 0) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | func (slf *WorkshopManageSearch) Save(record *WorkshopManage) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Save(record).Error; err != nil { |
| | | if err := db.Omit("CreatedAt").Save(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *WorkshopManageSearch) Count() (int64, error) { |
| | | var ( |
| | | total int64 |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return total, fmt.Errorf("find count err: %v", err) |
| | | } |
| | | return total, nil |
| | | } |