From b331c9990a0396301e934daffe095f99d62d1c89 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 27 九月 2023 15:58:49 +0800 Subject: [PATCH] 任务获取修改,状态2只返回已开始和已结束的 --- model/work_order.go | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 40 insertions(+), 4 deletions(-) diff --git a/model/work_order.go b/model/work_order.go index be00fec..076edef 100644 --- a/model/work_order.go +++ b/model/work_order.go @@ -34,18 +34,21 @@ Preload bool StartTimeMax int64 StartTimeMin int64 + StatusList []OrderStatus + WorkOrderIDs []string } ) type OrderStatus int const ( - OrderStatusUnFinished OrderStatus = 1 - OrderStatusFinished OrderStatus = 2 + OrderStatusWaitProcess OrderStatus = 1 + OrderStatusProcessing OrderStatus = 2 + OrderStatusFinished OrderStatus = 3 ) func (slf *Order) TableName() string { - return "Order" + return "work_order" } func NewOrderSearch(db *gorm.DB) *OrderSearch { @@ -84,6 +87,11 @@ return slf } +func (slf *OrderSearch) SetStatusList(statusList []OrderStatus) *OrderSearch { + slf.StatusList = statusList + return slf +} + func (slf *OrderSearch) SetPreload(preload bool) *OrderSearch { slf.Preload = preload return slf @@ -94,11 +102,25 @@ return slf } +func (slf *OrderSearch) SetWorkOrderIds(workOrderIds []string) *OrderSearch { + slf.WorkOrderIDs = workOrderIds + return slf +} + +func (slf *OrderSearch) SetId(id uint) *OrderSearch { + slf.ID = id + return slf +} + func (slf *OrderSearch) build() *gorm.DB { var db = slf.Orm.Model(&Order{}) if slf.OrderBy != "" { db = db.Order(slf.OrderBy) + } + + if slf.ID != 0 { + db = db.Where("id = ?", slf.ID) } if slf.WorkOrderID != "" { @@ -107,6 +129,10 @@ if slf.Status != 0 { db = db.Where("status = ?", slf.Status) + } + + if len(slf.StatusList) != 0 { + db = db.Where("status in ?", slf.StatusList) } if slf.StartTimeMax != 0 { @@ -146,7 +172,17 @@ return nil } -func (slf *OrderSearch) Save(record *Order) error { +func (slf *OrderSearch) Updates(record *Order) error { + var db = slf.build() + + if err := db.Updates(record).Error; err != nil { + return fmt.Errorf("save err: %v, record: %+v", err, record) + } + + return nil +} + +func (slf *OrderSearch) Upsert(record *Order) error { var db = slf.build() if err := db.Save(record).Error; err != nil { -- Gitblit v1.8.0