From e8b6ad0c160a39b024b0f2b996d603bdd9b22db9 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 28 九月 2023 17:44:07 +0800 Subject: [PATCH] 工艺参数列表增加是否可以更新字段 --- service/task.go | 56 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 28 insertions(+), 28 deletions(-) diff --git a/service/task.go b/service/task.go index 30f5a3c..db15d10 100644 --- a/service/task.go +++ b/service/task.go @@ -10,7 +10,6 @@ "apsClient/pkg/ecode" "apsClient/pkg/logx" "apsClient/pkg/structx" - "encoding/json" "fmt" "gorm.io/gorm" "time" @@ -23,19 +22,18 @@ return &TaskService{} } -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) { +func (slf TaskService) GetTask(page, pageSize int, mode constvar.TaskMode, channels []int32) (taskResp *response.TaskResponse, code int) { var taskList []*response.TaskData var count int64 var workers []*common.ProcedureWorker + + taskResp = &response.TaskResponse{ + Tasks: taskList, + TaskCount: count, + Workers: slf.WorkerDistinct(workers), + } + nowTs := time.Now().Unix() var ( err error @@ -47,30 +45,33 @@ SetDeviceId(conf.Conf.System.DeviceId). SetPage(page, pageSize) - if mode == TaskModeUnStarted { + if mode == constvar.TaskModeUnStarted { search.SetStatus(model.ProcedureStatusWaitProcess). SetStartTimeMax(nowTs). SetEndTimeMin(nowTs). SetOrder("start_time asc") - } else if mode == TaskModeCurrent { - search.SetStatusNot(model.ProcedureStatusFinished). + } else if mode == constvar.TaskModeCurrent { + search.SetStatus(model.ProcedureStatusProcessing). SetStartTimeMax(nowTs). SetEndTimeMin(nowTs). - SetOrder("start_time asc, status desc") - } else if mode == TaskModeLastFinished { + SetOrder("status desc, start_time asc") + } else if mode == constvar.TaskModeLastFinished { search.SetStatus(model.ProcedureStatusFinished).SetOrder("updated_at desc") + if len(channels) > 0 { + search.SetChannels(channels) + } } procedures, err = search.FindNotTotal() if err != nil { - return nil, ecode.DBErr + return taskResp, ecode.DBErr } - count, err = search.Count() + if err != nil { - return nil, ecode.DBErr + return taskResp, ecode.DBErr } if len(procedures) == 0 { - return nil, ecode.OK + return taskResp, ecode.OK } for _, procedure := range procedures { @@ -78,7 +79,7 @@ } orders, err = model.NewOrderSearch(nil).SetWorkOrderIds(workOrderIds).FindNotTotal() //鐢卞伐搴忓弽鎺ㄥ伐鍗� if err != nil { - return nil, ecode.DBErr + return taskResp, ecode.DBErr } orderMap := make(map[string]*model.Order, len(workOrderIds)) @@ -105,11 +106,15 @@ workers = append(workers, procedure.ProceduresInfo.Workers...) } taskResp = &response.TaskResponse{ - Tasks: taskList, - TaskCount: count, - Workers: slf.WorkerDistinct(workers), + Tasks: taskList, + Workers: slf.WorkerDistinct(workers), } return taskResp, ecode.OK +} +func (slf TaskService) NewTaskCount() (count int64) { + nowTs := time.Now().Unix() + count, _ = model.NewProceduresSearch(nil).SetDeviceId(conf.Conf.System.DeviceId).SetStatus(model.ProcedureStatusWaitProcess).SetStartTimeMax(nowTs).SetEndTimeMin(nowTs).Count() + return count } func (slf TaskService) WorkerDistinct(workers []*common.ProcedureWorker) (NoRepeatedWorkers []*common.ProcedureWorker) { @@ -171,11 +176,6 @@ return nil, err } if err == nil { - err = json.Unmarshal([]byte(data.Params), &data.ParamsMap) - if err != nil { - logx.Errorf("process model json.Unmarshal:%v", err) - return - } return data, nil } -- Gitblit v1.8.0