From 7d06c6472f1acea6b2e49e7b8837bf555e94e219 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 07 五月 2024 16:21:06 +0800 Subject: [PATCH] fox --- models/workshop_manage.go | 38 +++++++++++++++++++++++++++++++++----- 1 files changed, 33 insertions(+), 5 deletions(-) diff --git a/models/workshop_manage.go b/models/workshop_manage.go index dc5166b..ca05716 100644 --- a/models/workshop_manage.go +++ b/models/workshop_manage.go @@ -12,9 +12,10 @@ 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:澶囨敞"` } @@ -22,12 +23,13 @@ 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 { @@ -54,8 +56,18 @@ 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 } @@ -68,6 +80,10 @@ if slf.WorkshopNumber != "" { db = db.Where("workshop_number = ?", slf.WorkshopNumber) + } + + if slf.WorkshopName != "" { + db = db.Where("workshop_name = ?", slf.WorkshopName) } if slf.GroupNumber != 0 { @@ -100,7 +116,7 @@ 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) } @@ -123,7 +139,7 @@ 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) } @@ -139,3 +155,15 @@ 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 +} -- Gitblit v1.8.0