作者 tangxvhui

添加

@@ -6,9 +6,10 @@ import ( @@ -6,9 +6,10 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" 6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
7 7
8 "github.com/beego/beego/v2/server/web" 8 "github.com/beego/beego/v2/server/web"
9 - serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task" 9 + serviceNodeTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task"
10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
11 serviceSummary "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/service" 11 serviceSummary "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/service"
  12 + serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/service"
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" 13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
13 _ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego" 14 _ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego"
14 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer" 15 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer"
@@ -18,6 +19,7 @@ func main() { @@ -18,6 +19,7 @@ func main() {
18 startNodeTask() 19 startNodeTask()
19 startSummaryEvaluation() 20 startSummaryEvaluation()
20 startConfirmEvaluationScore() 21 startConfirmEvaluationScore()
  22 + go serviceTask.CheckYesterdayTaskRecord()
21 go notify.RunTaskSmsNotify() 23 go notify.RunTaskSmsNotify()
22 go notify.AppMessageRun() 24 go notify.AppMessageRun()
23 go consumer.Run() 25 go consumer.Run()
@@ -27,7 +29,7 @@ func main() { @@ -27,7 +29,7 @@ func main() {
27 // 定时任务-间隔发送评估环节 29 // 定时任务-间隔发送评估环节
28 func startNodeTask() { 30 func startNodeTask() {
29 go func() { 31 go func() {
30 - nodeTaskService := serviceTask.NewNodeTaskService() 32 + nodeTaskService := serviceNodeTask.NewNodeTaskService()
31 33
32 var duration time.Duration 34 var duration time.Duration
33 if constant.Env == "prd" { 35 if constant.Env == "prd" {
1 package service 1 package service
2 2
3 -//TODO  
4 -//检查每日提交的任务里程碑反馈 3 +import (
  4 + "fmt"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
  7 +
  8 + "time"
  9 +
  10 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  11 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  12 +)
  13 +
  14 +// 检查昨日提交的任务里程碑反馈
  15 +func CheckYesterdayTaskRecord() {
  16 + nowTime := time.Now()
  17 + y, m, d := nowTime.Date()
  18 + t1 := time.Date(y, m, d, 8, 30, 0, 0, time.Local) //今天的8点30分
  19 + interval := t1.Sub(nowTime)
  20 + if interval < 0 {
  21 + interval = (24 * time.Hour) + interval
  22 + }
  23 + timer := time.NewTimer(interval)
  24 + for {
  25 + <-timer.C
  26 + taskRecordList, err := getYesterdayTaskRecord()
  27 + if err != nil {
  28 + log.Logger.Info("获取每日任务反馈" + err.Error())
  29 + }
  30 + for _, val := range taskRecordList {
  31 + err = checkTaskRecord(val)
  32 + if err != nil {
  33 + log.Logger.Info("检查每日任务反馈" + err.Error())
  34 + }
  35 + }
  36 + timer.Reset(24 * time.Hour)
  37 + }
  38 +
  39 +}
  40 +
  41 +func checkTaskRecord(param *domain.TaskRecord) error {
  42 + transactionContext, err := factory.CreateTransactionContext(nil)
  43 + if err != nil {
  44 + return err
  45 + }
  46 + if err := transactionContext.StartTransaction(); err != nil {
  47 + return err
  48 + }
  49 + defer func() {
  50 + _ = transactionContext.RollbackTransaction()
  51 + }()
  52 + taskRepo := factory.CreateTaskRepository(map[string]interface{}{
  53 + "transactionContext": transactionContext,
  54 + })
  55 +
  56 + _, taskDataList, err := taskRepo.Find(map[string]interface{}{"id": param.TaskId})
  57 + if err != nil {
  58 + return fmt.Errorf("获取任务数据失败:%s", err)
  59 + }
  60 + if len(taskDataList) == 0 {
  61 + return nil
  62 + }
  63 + taskData := taskDataList[0]
  64 + if param.AnomalyState != domain.AnomalyState1 {
  65 + taskData.Anomaly += 1
  66 + }
  67 + if param.CanTaskAnomaly() {
  68 + taskData.Anomaly = 0
  69 + }
  70 + err = taskRepo.Save(taskData)
  71 + if err != nil {
  72 + return fmt.Errorf("保存任务数据:%s", err)
  73 + }
  74 + if err := transactionContext.CommitTransaction(); err != nil {
  75 + return err
  76 + }
  77 + return nil
  78 +}
  79 +
  80 +func getYesterdayTaskRecord() ([]*domain.TaskRecord, error) {
  81 + transactionContext, err := factory.CreateTransactionContext(nil)
  82 + if err != nil {
  83 + return nil, err
  84 + }
  85 + if err := transactionContext.StartTransaction(); err != nil {
  86 + return nil, err
  87 + }
  88 + defer func() {
  89 + _ = transactionContext.RollbackTransaction()
  90 + }()
  91 +
  92 + nowDay := time.Now().Format("2006-01-02")
  93 + nowDayTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local)
  94 + yesterday := nowDayTime.Add(-23 * time.Hour).Format("2006-01-02")
  95 +
  96 + taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{
  97 + "transactionContext": transactionContext,
  98 + })
  99 + _, taskRacordList, err := taskRecordRepo.Find(map[string]interface{}{
  100 + "createdAtDay": yesterday,
  101 + })
  102 + if err != nil {
  103 + return nil, err
  104 + }
  105 + if err := transactionContext.CommitTransaction(); err != nil {
  106 + return nil, err
  107 + }
  108 + return taskRacordList, nil
  109 +}
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "strings"
  5 + "time"
  6 +)
4 7
5 const ( 8 const (
6 AssistLevel1 int = 1 // 未辅导 9 AssistLevel1 int = 1 // 未辅导
@@ -41,3 +44,15 @@ type TaskRecordRepository interface { @@ -41,3 +44,15 @@ type TaskRecordRepository interface {
41 FindOne(queryOptions map[string]interface{}) (*TaskRecord, error) 44 FindOne(queryOptions map[string]interface{}) (*TaskRecord, error)
42 Find(queryOptions map[string]interface{}) (int, []*TaskRecord, error) 45 Find(queryOptions map[string]interface{}) (int, []*TaskRecord, error)
43 } 46 }
  47 +
  48 +// 是否取消任务的里程碑反馈异常记录
  49 +func (record *TaskRecord) CanTaskAnomaly() bool {
  50 + trimSpace := strings.TrimLeft(record.AssistContent, "\n") // 去掉前换行符
  51 + trimSpace = strings.TrimRight(trimSpace, "\n") // 去掉后换行符
  52 + trimSpace = strings.TrimSpace(trimSpace) // 去掉前后空格符
  53 + // 上级填写内容有值,选项是已辅导,变为正常
  54 + if !(len(trimSpace) == 0 || trimSpace == "无") && record.AssistLevel != AssistLevel1 {
  55 + return true
  56 + }
  57 + return false
  58 +}
@@ -159,7 +159,10 @@ func (repo *TaskRecordRepository) Find(queryOptions map[string]interface{}) (int @@ -159,7 +159,10 @@ func (repo *TaskRecordRepository) Find(queryOptions map[string]interface{}) (int
159 query.Offset(int(v)) 159 query.Offset(int(v))
160 } 160 }
161 161
162 - //// 按创建时间降序 162 + if v, ok := queryOptions["createdAtDay"]; ok {
  163 + query.Where(` to_char("created_at" at time zone 'PRC' ,'YYYY-MM-DD') =? `, v)
  164 + }
  165 + //按创建时间降序
163 //query.Order("created_at DESC") 166 //query.Order("created_at DESC")
164 167
165 count, err := query.SelectAndCount() 168 count, err := query.SelectAndCount()