From 8dfb8feb32bb5e4e460e23dcde42612a26fa2bcb Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期日, 27 八月 2023 01:11:28 +0800 Subject: [PATCH] fix --- service/task.go | 85 +++++++++++++++++++++++++++++++++++++----- 1 files changed, 75 insertions(+), 10 deletions(-) diff --git a/service/task.go b/service/task.go index bf65ebf..5a1634e 100644 --- a/service/task.go +++ b/service/task.go @@ -2,7 +2,10 @@ import ( "apsClient/model" + "apsClient/model/response" "apsClient/pkg/ecode" + "gorm.io/gorm" + "time" ) type TaskService struct { @@ -12,16 +15,78 @@ return &TaskService{} } -func (slf TaskService) GetTaskList(page, pageSize int) (taskList []*model.ScheduleTask, total int64, code int) { - search := model.NewScheduleTaskSearch(nil) - search.SetPage(page, pageSize). - SetPreload(true) - //SetEndTime(time.Now().Unix()) - var err error - taskList, total, err = search.Find() - if err != nil { - return +// GetTask 鑾峰彇浠诲姟锛屾湭瀹屾垚鐨勫紑濮嬫椂闂存渶鏃╃殑浠诲姟 +func (slf TaskService) GetTask() (taskData *response.TaskData, code int) { + nowTs := time.Now().Unix() + orderSearch := model.NewOrderSearch(nil) + orderSearch.SetOrder("start_time asc"). + SetStartTimeMax(nowTs). + SetStatusList([]model.OrderStatus{model.OrderStatusWaitProcess, model.OrderStatusProcessing}) + var ( + err error + order *model.Order + ) + order, err = orderSearch.First() //鍏堝彇杩涜涓殑浠诲姟 + if err == gorm.ErrRecordNotFound { + err = nil + return nil, ecode.OK } - return taskList, total, ecode.OK + if err != nil { + return nil, ecode.DBErr + } + procedure, err := model.NewProceduresSearch(nil).SetOrder("start_time asc"). + SetWorkOrderId(order.WorkOrderID). + SetStartTimeMax(nowTs). + SetStatusNot(model.ProcedureStatusFinished). + First() + if err == gorm.ErrRecordNotFound { //璇ヨ鍗曟湰璁惧鍏ㄩ儴宸ュ簭瀹屾垚锛屾妸璁㈠崟缃负瀹屾垚鐘舵�侊紙鍙槸瀵规湰璁惧瀹屾垚锛� + err = nil + err = model.NewOrderSearch(nil).SetWorkOrderId(order.WorkOrderID).UpdateByMap(map[string]interface{}{ + "status": model.OrderStatusFinished, + }) + if err != nil { + return nil, ecode.DBErr + } + return slf.GetTask() //褰撳墠璁㈠崟宸插畬鎴愶紝缁х画鏌ヨ鏈畬鎴愯鍗� + } + if err != nil { + return nil, ecode.DBErr + } + taskData = new(response.TaskData) + taskData.Order = order + taskData.Procedure = procedure + return taskData, ecode.OK +} +func (slf TaskService) GetProcedureById(id int) (*model.Procedures, int) { + procedure, err := model.NewProceduresSearch(nil).SetId(id).First() + if err != nil { + return nil, ecode.DBErr + } + return procedure, ecode.OK +} + +func (slf TaskService) UpdateProcedureStatus(db *gorm.DB, id int, status model.ProcedureStatus) error { + return model.NewProceduresSearch(db).SetId(id).UpdateByMap(map[string]interface{}{ + "status": status, + }) +} + +func (slf TaskService) UpdateOrderStatus(db *gorm.DB, id uint, status model.OrderStatus) error { + return model.NewOrderSearch(db).SetId(id).UpdateByMap(map[string]interface{}{ + "status": status, + }) +} + +func (slf TaskService) GetOrderByWorkOrderId(workOrderId string) (order *model.Order, err error) { + return model.NewOrderSearch(nil).SetWorkOrderId(workOrderId).First() +} + +// GetCurrentTask 鑾峰彇寰呭畬鎴愭垨杩涜涓殑浠诲姟锛� 姣忎釜宸ュ崟鍙湁涓�涓伐搴� +func (slf TaskService) GetCurrentTask() (workOrder *model.Order, err error) { + nowTs := time.Now().Unix() + orderSearch := model.NewOrderSearch(nil) + return orderSearch.SetOrder("start_time asc"). + SetStartTimeMin(nowTs). + SetStatusList([]model.OrderStatus{model.OrderStatusWaitProcess, model.OrderStatusProcessing}).First() } -- Gitblit v1.8.0