node_task_service.go
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type NodeTaskService struct {
}
func NewNodeTaskService() *NodeTaskService {
newRoleService := &NodeTaskService{}
return newRoleService
}
// SendEvaluationNode 发送评估环节
func (rs *NodeTaskService) SendEvaluationNode() error {
transactionContext, err := factory.StartTransaction()
if err != nil {
return err
}
defer func() {
transactionContext.RollbackTransaction()
}()
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
//cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
tasks, err := taskRepository.Find(map[string]interface{}{"now": time.Now().Local()})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//ttaffAssessRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
//
projectIdsMap := map[int64]*domain.EvaluationProject{}
cycleIdsMap := map[int64]*domain.EvaluationCycle{}
for i := range tasks {
task := tasks[i]
projectIdsMap[task.ProjectId] = nil
cycleIdsMap[task.CycleId] = nil
}
projectIds := make([]int64, 0)
cycleIds := make([]int64, 0)
for k := range projectIdsMap {
projectIds = append(projectIds, k)
}
for k := range cycleIdsMap {
cycleIds = append(cycleIds, k)
}
_, projects, err := projectRepository.Find(map[string]interface{}{"ids": projectIds})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//_, cycles, err := cycleRepository.Find(map[string]interface{}{"ids": cycleIds})
//if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
for i := range projects {
projectIdsMap[projects[i].Id] = projects[i]
}
//staffAssessService := service.NewStaffAssessServeice()
for i := range tasks {
task := tasks[i]
//if project, ok := projectIdsMap[task.ProjectId]; ok {
//csat := &command.CreateStaffAssessTask{
// CompanyId: project.CompanyId,
// EvaluationProjectId: project.Id,
// EvaluationProjectName: project.Name,
// CycleId: project.CycleId,
//}
//
//staffAssessService.CreateStaffAssessTask(csat)
//}
// 下一次发送时间
nextTime := utils.NextTimeInc(task.NextSentAt, task.KpiCycle)
task.NextSentAt = &nextTime
// 如果超出截至时间,则周期置空
if task.NextSentAt.After(*task.EndAt) {
task.NextSentAt = nil
}
task, err := taskRepository.Insert(task)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil
}