|
|
package service
|
|
|
|
|
|
//TODO
|
|
|
//检查每日提交的任务里程碑反馈 |
|
|
import (
|
|
|
"fmt"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
|
|
|
|
|
|
"time"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
)
|
|
|
|
|
|
// 检查昨日提交的任务里程碑反馈
|
|
|
func CheckYesterdayTaskRecord() {
|
|
|
nowTime := time.Now()
|
|
|
y, m, d := nowTime.Date()
|
|
|
t1 := time.Date(y, m, d, 8, 30, 0, 0, time.Local) //今天的8点30分
|
|
|
interval := t1.Sub(nowTime)
|
|
|
if interval < 0 {
|
|
|
interval = (24 * time.Hour) + interval
|
|
|
}
|
|
|
timer := time.NewTimer(interval)
|
|
|
for {
|
|
|
<-timer.C
|
|
|
taskRecordList, err := getYesterdayTaskRecord()
|
|
|
if err != nil {
|
|
|
log.Logger.Info("获取每日任务反馈" + err.Error())
|
|
|
}
|
|
|
for _, val := range taskRecordList {
|
|
|
err = checkTaskRecord(val)
|
|
|
if err != nil {
|
|
|
log.Logger.Info("检查每日任务反馈" + err.Error())
|
|
|
}
|
|
|
}
|
|
|
timer.Reset(24 * time.Hour)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
if param.CanTaskAnomaly() {
|
|
|
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
|
|
|
}
|
|
|
|
|
|
func getYesterdayTaskRecord() ([]*domain.TaskRecord, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
nowDay := time.Now().Format("2006-01-02")
|
|
|
nowDayTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local)
|
|
|
yesterday := nowDayTime.Add(-23 * time.Hour).Format("2006-01-02")
|
|
|
|
|
|
taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
_, taskRacordList, err := taskRecordRepo.Find(map[string]interface{}{
|
|
|
"createdAtDay": yesterday,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return taskRacordList, nil
|
|
|
} |
...
|
...
|
|