|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
|
|
|
|
|
|
"time"
|
...
|
...
|
@@ -21,12 +19,18 @@ func CheckYesterdayTaskRecord() { |
|
|
interval = (24 * time.Hour) + interval
|
|
|
}
|
|
|
timer := time.NewTimer(interval)
|
|
|
var (
|
|
|
nowDay string
|
|
|
err error
|
|
|
taskRecordList []*domain.TaskRecord
|
|
|
)
|
|
|
for {
|
|
|
<-timer.C
|
|
|
nowDay := time.Now().Format("2006-01-02")
|
|
|
taskRecordList, err := getYesterdayTaskRecord(nowDay)
|
|
|
nowDay = time.Now().Format("2006-01-02")
|
|
|
taskRecordList, err = getYesterdayTaskRecord(nowDay)
|
|
|
if err != nil {
|
|
|
log.Logger.Info("获取每日任务反馈" + err.Error())
|
|
|
log.Logger.Error("获取每日任务反馈" + err.Error())
|
|
|
continue
|
|
|
}
|
|
|
for _, val := range taskRecordList {
|
|
|
err = checkTaskRecordV3(val)
|
...
|
...
|
@@ -39,44 +43,44 @@ func CheckYesterdayTaskRecord() { |
|
|
|
|
|
}
|
|
|
|
|
|
func checkTaskRecord(param *domain.TaskRecord) error {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
// func checkTaskRecord(param *domain.TaskRecord) error {
|
|
|
// transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
// if err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// _ = transactionContext.RollbackTransaction()
|
|
|
// }()
|
|
|
// taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
// })
|
|
|
|
|
|
_, taskDataList, err := taskRepo.Find(map[string]interface{}{"id": param.TaskId})
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("获取任务数据失败:%s", err)
|
|
|
}
|
|
|
if len(taskDataList) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
taskData := taskDataList[0]
|
|
|
if param.AnomalyState != domain.AnomalyState1 {
|
|
|
taskData.Anomaly += 1
|
|
|
} else {
|
|
|
taskData.Anomaly = 0
|
|
|
}
|
|
|
// _, taskDataList, err := taskRepo.Find(map[string]interface{}{"id": param.TaskId})
|
|
|
// if err != nil {
|
|
|
// return fmt.Errorf("获取任务数据失败:%s", err)
|
|
|
// }
|
|
|
// if len(taskDataList) == 0 {
|
|
|
// return nil
|
|
|
// }
|
|
|
// taskData := taskDataList[0]
|
|
|
// if param.AnomalyState != domain.AnomalyState1 {
|
|
|
// taskData.Anomaly += 1
|
|
|
// } else {
|
|
|
// taskData.Anomaly = 0
|
|
|
// }
|
|
|
|
|
|
err = taskRepo.Save(taskData)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("保存任务数据:%s", err)
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
// err = taskRepo.Save(taskData)
|
|
|
// if err != nil {
|
|
|
// return fmt.Errorf("保存任务数据:%s", err)
|
|
|
// }
|
|
|
// if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
// return nil
|
|
|
// }
|
|
|
|
|
|
func getYesterdayTaskRecord(nowDay string) ([]*domain.TaskRecord, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
|