|
@@ -3,8 +3,11 @@ package service |
|
@@ -3,8 +3,11 @@ package service |
3
|
import (
|
3
|
import (
|
4
|
"github.com/linmadan/egglib-go/core/application"
|
4
|
"github.com/linmadan/egglib-go/core/application"
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
6
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
|
|
|
7
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/service"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
|
|
|
10
|
+ "strconv"
|
8
|
"time"
|
11
|
"time"
|
9
|
)
|
12
|
)
|
10
|
|
13
|
|
|
@@ -26,13 +29,15 @@ func (rs *NodeTaskService) SendEvaluationNode() error { |
|
@@ -26,13 +29,15 @@ func (rs *NodeTaskService) SendEvaluationNode() error { |
26
|
transactionContext.RollbackTransaction()
|
29
|
transactionContext.RollbackTransaction()
|
27
|
}()
|
30
|
}()
|
28
|
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
|
31
|
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
|
29
|
- projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
30
|
- //cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
31
|
-
|
|
|
32
|
tasks, err := taskRepository.Find(map[string]interface{}{"now": time.Now().Local()})
|
32
|
tasks, err := taskRepository.Find(map[string]interface{}{"now": time.Now().Local()})
|
33
|
if err != nil {
|
33
|
if err != nil {
|
34
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
34
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
35
|
}
|
35
|
}
|
|
|
36
|
+ if len(tasks) == 0 {
|
|
|
37
|
+ return nil
|
|
|
38
|
+ }
|
|
|
39
|
+ projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
40
|
+ cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
|
36
|
|
41
|
|
37
|
//ttaffAssessRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
|
42
|
//ttaffAssessRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
|
38
|
//
|
43
|
//
|
|
@@ -53,49 +58,114 @@ func (rs *NodeTaskService) SendEvaluationNode() error { |
|
@@ -53,49 +58,114 @@ func (rs *NodeTaskService) SendEvaluationNode() error { |
53
|
cycleIds = append(cycleIds, k)
|
58
|
cycleIds = append(cycleIds, k)
|
54
|
}
|
59
|
}
|
55
|
|
60
|
|
56
|
- _, projects, err := projectRepository.Find(map[string]interface{}{"ids": projectIds})
|
61
|
+ _, projects, err := projectRepository.Find(map[string]interface{}{"ids": projectIds}, "template")
|
|
|
62
|
+ if err != nil {
|
|
|
63
|
+ return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
64
|
+ }
|
|
|
65
|
+ _, cycles, err := cycleRepository.Find(map[string]interface{}{"ids": cycleIds})
|
57
|
if err != nil {
|
66
|
if err != nil {
|
58
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
67
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
59
|
}
|
68
|
}
|
60
|
- //_, cycles, err := cycleRepository.Find(map[string]interface{}{"ids": cycleIds})
|
|
|
61
|
- //if err != nil {
|
|
|
62
|
- // return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
63
|
- //}
|
|
|
64
|
|
69
|
|
65
|
for i := range projects {
|
70
|
for i := range projects {
|
66
|
projectIdsMap[projects[i].Id] = projects[i]
|
71
|
projectIdsMap[projects[i].Id] = projects[i]
|
67
|
}
|
72
|
}
|
|
|
73
|
+ for i := range cycles {
|
|
|
74
|
+ cycleIdsMap[cycles[i].Id] = cycles[i]
|
|
|
75
|
+ }
|
68
|
|
76
|
|
69
|
- //staffAssessService := service.NewStaffAssessServeice()
|
|
|
70
|
-
|
77
|
+ staffAssessTaskMap := map[int64]*command.CreateStaffAssessTask{}
|
71
|
for i := range tasks {
|
78
|
for i := range tasks {
|
72
|
task := tasks[i]
|
79
|
task := tasks[i]
|
73
|
-
|
|
|
74
|
- //if project, ok := projectIdsMap[task.ProjectId]; ok {
|
|
|
75
|
-
|
|
|
76
|
- //csat := &command.CreateStaffAssessTask{
|
|
|
77
|
- // CompanyId: project.CompanyId,
|
|
|
78
|
- // EvaluationProjectId: project.Id,
|
|
|
79
|
- // EvaluationProjectName: project.Name,
|
|
|
80
|
- // CycleId: project.CycleId,
|
|
|
81
|
- //}
|
|
|
82
|
- //
|
|
|
83
|
- //staffAssessService.CreateStaffAssessTask(csat)
|
|
|
84
|
- //}
|
|
|
85
|
-
|
|
|
86
|
- // 下一次发送时间
|
|
|
87
|
- nextTime := utils.NextTimeInc(task.NextSentAt, task.KpiCycle)
|
|
|
88
|
- task.NextSentAt = &nextTime
|
|
|
89
|
- // 如果超出截至时间,则周期置空
|
|
|
90
|
- if task.NextSentAt.After(*task.EndAt) {
|
80
|
+ // 项目
|
|
|
81
|
+ project, ok := projectIdsMap[task.ProjectId]
|
|
|
82
|
+ if ok {
|
|
|
83
|
+
|
|
|
84
|
+ // 环节截止时间
|
|
|
85
|
+ maxTime := time.Date(task.TimeEnd.Year(), task.TimeEnd.Month(), task.TimeEnd.Day(), task.TimeEnd.Hour(), task.TimeEnd.Minute(), 0, 0, time.Local)
|
|
|
86
|
+
|
|
|
87
|
+ // 当前周起始时间和截止时间
|
|
|
88
|
+ var cycleTimeStart = task.NextSentAt
|
|
|
89
|
+ var cycleTimeEnd *time.Time
|
|
|
90
|
+
|
|
|
91
|
+ // 下个周期起始时间
|
|
|
92
|
+ nextTime := utils.NextTimeInc(task.NextSentAt, task.KpiCycle)
|
|
|
93
|
+ // 超过截止时间
|
|
|
94
|
+ if nextTime.After(maxTime) {
|
|
|
95
|
+ task.NextSentAt = nil
|
|
|
96
|
+ } else {
|
|
|
97
|
+ task.NextSentAt = &nextTime
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ // 下个周期的起始时间=当前周期的截止时间
|
|
|
101
|
+ if task.NextSentAt == nil {
|
|
|
102
|
+ cycleTimeEnd = &maxTime
|
|
|
103
|
+ } else {
|
|
|
104
|
+ cycleTimeEnd = task.NextSentAt
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ // 格式化周期的起始和截止时间
|
|
|
108
|
+ fmCycleStartTime := cycleTimeStart.Format("2006-1-2 15:04:05")
|
|
|
109
|
+ fmCycleTimeEnd := cycleTimeEnd.Format("2006-1-2 15:04:05")
|
|
|
110
|
+
|
|
|
111
|
+ var csat, staffOk = staffAssessTaskMap[task.ProjectId]
|
|
|
112
|
+ if !staffOk {
|
|
|
113
|
+ csat = &command.CreateStaffAssessTask{
|
|
|
114
|
+ CompanyId: int(project.CompanyId),
|
|
|
115
|
+ EvaluationProjectId: int(project.Id),
|
|
|
116
|
+ EvaluationProjectName: project.Name,
|
|
|
117
|
+ CycleId: project.CycleId,
|
|
|
118
|
+ }
|
|
|
119
|
+
|
|
|
120
|
+ // 周期名称
|
|
|
121
|
+ if cycle, ok := cycleIdsMap[project.CycleId]; ok {
|
|
|
122
|
+ csat.CycleName = cycle.Name
|
|
|
123
|
+ }
|
|
|
124
|
+
|
|
|
125
|
+ // 接收人
|
|
|
126
|
+ csat.ExecutorId = make([]int, 0)
|
|
|
127
|
+ for rIndex := range project.Recipients {
|
|
|
128
|
+ vInt, _ := strconv.Atoi(project.Recipients[rIndex])
|
|
|
129
|
+ csat.ExecutorId = append(csat.ExecutorId, vInt)
|
|
|
130
|
+ }
|
|
|
131
|
+
|
|
|
132
|
+ // FIXME 这里设置时间可能会有歧义,目前原型设计时间均一致,所以直接选取第一个获取到的周期时间,作为本周期的起止和截止时间
|
|
|
133
|
+ csat.BeginTime = fmCycleStartTime
|
|
|
134
|
+ csat.EndTime = fmCycleTimeEnd
|
|
|
135
|
+
|
|
|
136
|
+ staffAssessTaskMap[task.ProjectId] = csat
|
|
|
137
|
+ }
|
|
|
138
|
+
|
|
|
139
|
+ if csat.StepList == nil {
|
|
|
140
|
+ csat.StepList = make([]command.AssessTaskStep, 0)
|
|
|
141
|
+ }
|
|
|
142
|
+ csat.StepList = append(csat.StepList, command.AssessTaskStep{
|
|
|
143
|
+ SortBy: i,
|
|
|
144
|
+ LinkNodeId: int(task.NodeId),
|
|
|
145
|
+ LinkNodeName: task.NodeName,
|
|
|
146
|
+ LinkNodeType: task.NodeType,
|
|
|
147
|
+ BeginTime: fmCycleStartTime,
|
|
|
148
|
+ EndTime: fmCycleTimeEnd,
|
|
|
149
|
+ })
|
|
|
150
|
+ } else {
|
91
|
task.NextSentAt = nil
|
151
|
task.NextSentAt = nil
|
92
|
}
|
152
|
}
|
|
|
153
|
+
|
93
|
task, err := taskRepository.Insert(task)
|
154
|
task, err := taskRepository.Insert(task)
|
94
|
if err != nil {
|
155
|
if err != nil {
|
95
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
156
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
96
|
}
|
157
|
}
|
97
|
}
|
158
|
}
|
98
|
|
159
|
|
|
|
160
|
+ staffAssessService := service.NewStaffAssessServeice()
|
|
|
161
|
+ for i := range staffAssessTaskMap {
|
|
|
162
|
+ staffAssessTask := staffAssessTaskMap[i]
|
|
|
163
|
+ _, err := staffAssessService.CreateStaffAssessTask(staffAssessTask)
|
|
|
164
|
+ if err != nil {
|
|
|
165
|
+ return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
166
|
+ }
|
|
|
167
|
+ }
|
|
|
168
|
+
|
99
|
if err := transactionContext.CommitTransaction(); err != nil {
|
169
|
if err := transactionContext.CommitTransaction(); err != nil {
|
100
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
170
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
101
|
}
|
171
|
}
|