1
|
package service
|
1
|
package service
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
- "fmt"
|
|
|
5
|
-
|
|
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
|
4
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
|
7
|
|
5
|
|
8
|
"time"
|
6
|
"time"
|
|
@@ -21,12 +19,18 @@ func CheckYesterdayTaskRecord() { |
|
@@ -21,12 +19,18 @@ func CheckYesterdayTaskRecord() { |
21
|
interval = (24 * time.Hour) + interval
|
19
|
interval = (24 * time.Hour) + interval
|
22
|
}
|
20
|
}
|
23
|
timer := time.NewTimer(interval)
|
21
|
timer := time.NewTimer(interval)
|
|
|
22
|
+ var (
|
|
|
23
|
+ nowDay string
|
|
|
24
|
+ err error
|
|
|
25
|
+ taskRecordList []*domain.TaskRecord
|
|
|
26
|
+ )
|
24
|
for {
|
27
|
for {
|
25
|
<-timer.C
|
28
|
<-timer.C
|
26
|
- nowDay := time.Now().Format("2006-01-02")
|
|
|
27
|
- taskRecordList, err := getYesterdayTaskRecord(nowDay)
|
29
|
+ nowDay = time.Now().Format("2006-01-02")
|
|
|
30
|
+ taskRecordList, err = getYesterdayTaskRecord(nowDay)
|
28
|
if err != nil {
|
31
|
if err != nil {
|
29
|
- log.Logger.Info("获取每日任务反馈" + err.Error())
|
32
|
+ log.Logger.Error("获取每日任务反馈" + err.Error())
|
|
|
33
|
+ continue
|
30
|
}
|
34
|
}
|
31
|
for _, val := range taskRecordList {
|
35
|
for _, val := range taskRecordList {
|
32
|
err = checkTaskRecordV3(val)
|
36
|
err = checkTaskRecordV3(val)
|
|
@@ -39,44 +43,44 @@ func CheckYesterdayTaskRecord() { |
|
@@ -39,44 +43,44 @@ func CheckYesterdayTaskRecord() { |
39
|
|
43
|
|
40
|
}
|
44
|
}
|
41
|
|
45
|
|
42
|
-func checkTaskRecord(param *domain.TaskRecord) error {
|
|
|
43
|
- transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
44
|
- if err != nil {
|
|
|
45
|
- return err
|
|
|
46
|
- }
|
|
|
47
|
- if err := transactionContext.StartTransaction(); err != nil {
|
|
|
48
|
- return err
|
|
|
49
|
- }
|
|
|
50
|
- defer func() {
|
|
|
51
|
- _ = transactionContext.RollbackTransaction()
|
|
|
52
|
- }()
|
|
|
53
|
- taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
54
|
- "transactionContext": transactionContext,
|
|
|
55
|
- })
|
46
|
+// func checkTaskRecord(param *domain.TaskRecord) error {
|
|
|
47
|
+// transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
48
|
+// if err != nil {
|
|
|
49
|
+// return err
|
|
|
50
|
+// }
|
|
|
51
|
+// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
52
|
+// return err
|
|
|
53
|
+// }
|
|
|
54
|
+// defer func() {
|
|
|
55
|
+// _ = transactionContext.RollbackTransaction()
|
|
|
56
|
+// }()
|
|
|
57
|
+// taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
58
|
+// "transactionContext": transactionContext,
|
|
|
59
|
+// })
|
56
|
|
60
|
|
57
|
- _, taskDataList, err := taskRepo.Find(map[string]interface{}{"id": param.TaskId})
|
|
|
58
|
- if err != nil {
|
|
|
59
|
- return fmt.Errorf("获取任务数据失败:%s", err)
|
|
|
60
|
- }
|
|
|
61
|
- if len(taskDataList) == 0 {
|
|
|
62
|
- return nil
|
|
|
63
|
- }
|
|
|
64
|
- taskData := taskDataList[0]
|
|
|
65
|
- if param.AnomalyState != domain.AnomalyState1 {
|
|
|
66
|
- taskData.Anomaly += 1
|
|
|
67
|
- } else {
|
|
|
68
|
- taskData.Anomaly = 0
|
|
|
69
|
- }
|
61
|
+// _, taskDataList, err := taskRepo.Find(map[string]interface{}{"id": param.TaskId})
|
|
|
62
|
+// if err != nil {
|
|
|
63
|
+// return fmt.Errorf("获取任务数据失败:%s", err)
|
|
|
64
|
+// }
|
|
|
65
|
+// if len(taskDataList) == 0 {
|
|
|
66
|
+// return nil
|
|
|
67
|
+// }
|
|
|
68
|
+// taskData := taskDataList[0]
|
|
|
69
|
+// if param.AnomalyState != domain.AnomalyState1 {
|
|
|
70
|
+// taskData.Anomaly += 1
|
|
|
71
|
+// } else {
|
|
|
72
|
+// taskData.Anomaly = 0
|
|
|
73
|
+// }
|
70
|
|
74
|
|
71
|
- err = taskRepo.Save(taskData)
|
|
|
72
|
- if err != nil {
|
|
|
73
|
- return fmt.Errorf("保存任务数据:%s", err)
|
|
|
74
|
- }
|
|
|
75
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
76
|
- return err
|
|
|
77
|
- }
|
|
|
78
|
- return nil
|
|
|
79
|
-}
|
75
|
+// err = taskRepo.Save(taskData)
|
|
|
76
|
+// if err != nil {
|
|
|
77
|
+// return fmt.Errorf("保存任务数据:%s", err)
|
|
|
78
|
+// }
|
|
|
79
|
+// if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
80
|
+// return err
|
|
|
81
|
+// }
|
|
|
82
|
+// return nil
|
|
|
83
|
+// }
|
80
|
|
84
|
|
81
|
func getYesterdayTaskRecord(nowDay string) ([]*domain.TaskRecord, error) {
|
85
|
func getYesterdayTaskRecord(nowDay string) ([]*domain.TaskRecord, error) {
|
82
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
86
|
transactionContext, err := factory.CreateTransactionContext(nil)
|