From d4243f398b84a8b8cdcd27c35ace72f6a30a6452 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期日, 08 十月 2023 10:45:09 +0800
Subject: [PATCH] 是否可以开始增加开始时间判断,考虑进程退出和断电情况

---
 service/task.go |   25 +++++++------------------
 1 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/service/task.go b/service/task.go
index dd1c11c..f9413cc 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"
@@ -35,7 +34,6 @@
 		Workers:   slf.WorkerDistinct(workers),
 	}
 
-	nowTs := time.Now().Unix()
 	var (
 		err          error
 		orders       []*model.Order
@@ -48,14 +46,10 @@
 
 	if mode == constvar.TaskModeUnStarted {
 		search.SetStatus(model.ProcedureStatusWaitProcess).
-			SetStartTimeMax(nowTs).
-			SetEndTimeMin(nowTs).
 			SetOrder("start_time asc")
 	} else if mode == constvar.TaskModeCurrent {
 		search.SetStatus(model.ProcedureStatusProcessing).
-			SetStartTimeMax(nowTs).
-			SetEndTimeMin(nowTs).
-			SetOrder("status desc, start_time asc")
+			SetOrder("start_time asc")
 	} else if mode == constvar.TaskModeLastFinished {
 		search.SetStatus(model.ProcedureStatusFinished).SetOrder("updated_at desc")
 		if len(channels) > 0 {
@@ -106,15 +100,15 @@
 		taskList = append(taskList, &taskData)
 		workers = append(workers, procedure.ProceduresInfo.Workers...)
 	}
-
-	count, _ = search.SetStatus(model.ProcedureStatusWaitProcess).SetStartTimeMax(nowTs).SetEndTimeMin(nowTs).Count()
-
 	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) {
+	count, _ = model.NewProceduresSearch(nil).SetDeviceId(conf.Conf.System.DeviceId).SetStatus(model.ProcedureStatusWaitProcess).Count()
+	return count
 }
 
 func (slf TaskService) WorkerDistinct(workers []*common.ProcedureWorker) (NoRepeatedWorkers []*common.ProcedureWorker) {
@@ -176,11 +170,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