作者 tangxvhui

添加

... ... @@ -6,9 +6,10 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"github.com/beego/beego/v2/server/web"
serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task"
serviceNodeTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
serviceSummary "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/service"
serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/service"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer"
... ... @@ -18,6 +19,7 @@ func main() {
startNodeTask()
startSummaryEvaluation()
startConfirmEvaluationScore()
go serviceTask.CheckYesterdayTaskRecord()
go notify.RunTaskSmsNotify()
go notify.AppMessageRun()
go consumer.Run()
... ... @@ -27,7 +29,7 @@ func main() {
// 定时任务-间隔发送评估环节
func startNodeTask() {
go func() {
nodeTaskService := serviceTask.NewNodeTaskService()
nodeTaskService := serviceNodeTask.NewNodeTaskService()
var duration time.Duration
if constant.Env == "prd" {
... ...
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
}
... ...
package domain
import "time"
import (
"strings"
"time"
)
const (
AssistLevel1 int = 1 // 未辅导
... ... @@ -41,3 +44,15 @@ type TaskRecordRepository interface {
FindOne(queryOptions map[string]interface{}) (*TaskRecord, error)
Find(queryOptions map[string]interface{}) (int, []*TaskRecord, error)
}
// 是否取消任务的里程碑反馈异常记录
func (record *TaskRecord) CanTaskAnomaly() bool {
trimSpace := strings.TrimLeft(record.AssistContent, "\n") // 去掉前换行符
trimSpace = strings.TrimRight(trimSpace, "\n") // 去掉后换行符
trimSpace = strings.TrimSpace(trimSpace) // 去掉前后空格符
// 上级填写内容有值,选项是已辅导,变为正常
if !(len(trimSpace) == 0 || trimSpace == "无") && record.AssistLevel != AssistLevel1 {
return true
}
return false
}
... ...
... ... @@ -159,7 +159,10 @@ func (repo *TaskRecordRepository) Find(queryOptions map[string]interface{}) (int
query.Offset(int(v))
}
//// 按创建时间降序
if v, ok := queryOptions["createdAtDay"]; ok {
query.Where(` to_char("created_at" at time zone 'PRC' ,'YYYY-MM-DD') =? `, v)
}
//按创建时间降序
//query.Order("created_at DESC")
count, err := query.SelectAndCount()
... ...