From cb2f80a627413d6dda5b9071a2711cb03964ed15 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 25 九月 2023 10:06:55 +0800 Subject: [PATCH] 任务接口返回通道数量 --- service/task.go | 57 ++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 36 insertions(+), 21 deletions(-) diff --git a/service/task.go b/service/task.go index 64a72df..30f5a3c 100644 --- a/service/task.go +++ b/service/task.go @@ -23,8 +23,16 @@ return &TaskService{} } -// GetTask 鑾峰彇浠诲姟锛屾湭瀹屾垚鐨勫紑濮嬫椂闂存渶鏃╃殑浠诲姟 -func (slf TaskService) GetTask(page, pageSize int) (taskResp *response.TaskResponse, code int) { +type TaskMode int + +const ( + TaskModeUnStarted TaskMode = 1 //鏈紑濮嬬殑 + TaskModeCurrent TaskMode = 2 + TaskModeLastFinished TaskMode = 3 //涓婁竴涓粨鏉熺殑 +) + +// GetTask 鑾峰彇浠诲姟锛屾湭瀹屾垚鐨勫紑濮嬫椂闂村皬浜庣瓑浜庡綋鍓嶆椂闂达紝缁撴潫鏃堕棿澶т簬褰撳墠鏃堕棿鐨勪换鍔� +func (slf TaskService) GetTask(page, pageSize int, mode TaskMode) (taskResp *response.TaskResponse, code int) { var taskList []*response.TaskData var count int64 var workers []*common.ProcedureWorker @@ -35,19 +43,29 @@ procedures []*model.Procedures workOrderIds []string ) - procedures, err = model.NewProceduresSearch(nil).SetOrder("start_time asc"). - SetStartTimeMax(nowTs). + search := model.NewProceduresSearch(nil). SetDeviceId(conf.Conf.System.DeviceId). - SetStatusNot(model.ProcedureStatusFinished). - SetPage(page, pageSize). - FindNotTotal() + SetPage(page, pageSize) + + if mode == TaskModeUnStarted { + search.SetStatus(model.ProcedureStatusWaitProcess). + SetStartTimeMax(nowTs). + SetEndTimeMin(nowTs). + SetOrder("start_time asc") + } else if mode == TaskModeCurrent { + search.SetStatusNot(model.ProcedureStatusFinished). + SetStartTimeMax(nowTs). + SetEndTimeMin(nowTs). + SetOrder("start_time asc, status desc") + } else if mode == TaskModeLastFinished { + search.SetStatus(model.ProcedureStatusFinished).SetOrder("updated_at desc") + } + + procedures, err = search.FindNotTotal() if err != nil { return nil, ecode.DBErr } - count, err = model.NewProceduresSearch(nil). - SetDeviceId(conf.Conf.System.DeviceId). - SetStatusNot(model.ProcedureStatusFinished). - Count() + count, err = search.Count() if err != nil { return nil, ecode.DBErr } @@ -73,7 +91,7 @@ Procedure: procedure, AllProcedures: procedure.ProceduresInfo.AllProcedureNames, CurrentProcedureIndex: 0, - Position: procedure.Position, + Channel: procedure.Channel, } index := 0 for _, name := range procedure.ProceduresInfo.AllProcedureNames { @@ -114,19 +132,19 @@ return procedure, ecode.OK } -func (slf TaskService) UpdateProcedureStatusAndPosition(db *gorm.DB, id int, status model.ProcedureStatus, position int) error { +func (slf TaskService) UpdateProcedureStatusAndChannel(db *gorm.DB, id int, status model.ProcedureStatus, channel int32) error { if status == model.ProcedureStatusFinished { - ProgressCacheUnset(position) + ProgressCacheUnset(channel) } return model.NewProceduresSearch(db).SetId(id).UpdateByMap(map[string]interface{}{ - "status": status, - "position": position, + "status": status, + "channel": channel, }) } -func (slf TaskService) UpdateProcedureStatus(db *gorm.DB, id int, status model.ProcedureStatus, position int) error { +func (slf TaskService) UpdateProcedureStatus(db *gorm.DB, id int, status model.ProcedureStatus, channel int32) error { if status == model.ProcedureStatusFinished { - ProgressCacheUnset(position) + ProgressCacheUnset(channel) } return model.NewProceduresSearch(db).SetId(id).UpdateByMap(map[string]interface{}{ "status": status, @@ -145,9 +163,6 @@ func (slf TaskService) GetProcessParams(procedure *model.Procedures, order *model.Order) (processModel *model.ProcessModel, err error) { data, err := model.NewProcessModelSearch(). - SetWorkOrder(procedure.WorkOrderID). - SetDevice(procedure.ProceduresInfo.DeviceName). - SetOrderId(procedure.OrderID). SetProcedure(procedure.ProceduresInfo.ProcedureName). SetProduct(order.ProductName). SetOrder("id desc").First() -- Gitblit v1.8.0