|
@@ -100,7 +100,7 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont |
|
@@ -100,7 +100,7 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont |
100
|
RunAt: nowTime.Unix(),
|
100
|
RunAt: nowTime.Unix(),
|
101
|
StopAt: 0,
|
101
|
StopAt: 0,
|
102
|
}
|
102
|
}
|
103
|
- newTask.ApplyLevelName("")
|
103
|
+ newTask.ApplyLevelName("战略任务")
|
104
|
err = taskRepo.Save(&newTask)
|
104
|
err = taskRepo.Save(&newTask)
|
105
|
if err != nil {
|
105
|
if err != nil {
|
106
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
|
106
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
|
|
@@ -144,6 +144,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont |
|
@@ -144,6 +144,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont |
144
|
return nil
|
144
|
return nil
|
145
|
}
|
145
|
}
|
146
|
|
146
|
|
|
|
147
|
+// 更新任务
|
|
|
148
|
+// TODO 检查是否可以修改,和通知
|
147
|
func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]interface{}, error) {
|
149
|
func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]interface{}, error) {
|
148
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
150
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
149
|
if err != nil {
|
151
|
if err != nil {
|
|
@@ -155,9 +157,22 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
@@ -155,9 +157,22 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
155
|
defer func() {
|
157
|
defer func() {
|
156
|
_ = transactionContext.RollbackTransaction()
|
158
|
_ = transactionContext.RollbackTransaction()
|
157
|
}()
|
159
|
}()
|
|
|
160
|
+ if len(param.StageList) < 3 {
|
|
|
161
|
+ return map[string]interface{}{
|
|
|
162
|
+ "id": param.Id,
|
|
|
163
|
+ }, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量至少3个")
|
|
|
164
|
+ }
|
|
|
165
|
+ if len(param.StageList) > 5 {
|
|
|
166
|
+ return map[string]interface{}{
|
|
|
167
|
+ "id": param.Id,
|
|
|
168
|
+ }, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量太多")
|
|
|
169
|
+ }
|
158
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
170
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
159
|
"transactionContext": transactionContext,
|
171
|
"transactionContext": transactionContext,
|
160
|
})
|
172
|
})
|
|
|
173
|
+ userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
174
|
+ "transactionContext": transactionContext,
|
|
|
175
|
+ })
|
161
|
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
|
176
|
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
|
162
|
"transactionContext": transactionContext,
|
177
|
"transactionContext": transactionContext,
|
163
|
})
|
178
|
})
|
|
@@ -173,6 +188,21 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
@@ -173,6 +188,21 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
173
|
if err != nil {
|
188
|
if err != nil {
|
174
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
189
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
175
|
}
|
190
|
}
|
|
|
191
|
+ //任务的相关人员
|
|
|
192
|
+ relatedUserIds := []int{}
|
|
|
193
|
+ for _, val := range param.RelatedUserId {
|
|
|
194
|
+ id, _ := strconv.Atoi(val)
|
|
|
195
|
+ relatedUserIds = append(relatedUserIds, id)
|
|
|
196
|
+ }
|
|
|
197
|
+ var relatedUser []*domain.User
|
|
|
198
|
+ if len(relatedUserIds) > 0 {
|
|
|
199
|
+ _, relatedUser, err = userRepo.Find(map[string]interface{}{
|
|
|
200
|
+ "ids": relatedUserIds,
|
|
|
201
|
+ })
|
|
|
202
|
+ if err != nil {
|
|
|
203
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务的相关人员"+err.Error())
|
|
|
204
|
+ }
|
|
|
205
|
+ }
|
176
|
ok, err := srv.canUpdateTask(taskData, stageList)
|
206
|
ok, err := srv.canUpdateTask(taskData, stageList)
|
177
|
if err != nil {
|
207
|
if err != nil {
|
178
|
return nil, err
|
208
|
return nil, err
|
|
@@ -180,6 +210,12 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
@@ -180,6 +210,12 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
180
|
if !ok {
|
210
|
if !ok {
|
181
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "日评数据已生成,任务不能再被编辑")
|
211
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "日评数据已生成,任务不能再被编辑")
|
182
|
}
|
212
|
}
|
|
|
213
|
+ //更新相关人员
|
|
|
214
|
+ taskData.RelatedUser = []int{}
|
|
|
215
|
+ for _, val := range relatedUser {
|
|
|
216
|
+ taskData.RelatedUser = append(taskData.RelatedUser, int(val.Id))
|
|
|
217
|
+ }
|
|
|
218
|
+ //更新任务名称
|
183
|
taskData.Alias = param.Alias
|
219
|
taskData.Alias = param.Alias
|
184
|
taskData.ApplyLevelName(param.LevelName)
|
220
|
taskData.ApplyLevelName(param.LevelName)
|
185
|
nowTime := time.Now()
|
221
|
nowTime := time.Now()
|
|
@@ -197,7 +233,7 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
@@ -197,7 +233,7 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
197
|
}
|
233
|
}
|
198
|
if i > 0 {
|
234
|
if i > 0 {
|
199
|
if lastPlanCompletedAt.After(t) {
|
235
|
if lastPlanCompletedAt.After(t) {
|
200
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑完成时间填写错误")
|
236
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑["+val2.Name+"]完成时间填写错误")
|
201
|
}
|
237
|
}
|
202
|
}
|
238
|
}
|
203
|
lastPlanCompletedAt = t
|
239
|
lastPlanCompletedAt = t
|
|
@@ -220,8 +256,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
@@ -220,8 +256,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
220
|
}
|
256
|
}
|
221
|
oldStage.DeletedAt = nil
|
257
|
oldStage.DeletedAt = nil
|
222
|
oldStage.SortBy = i + 1
|
258
|
oldStage.SortBy = i + 1
|
223
|
- oldStage.PlanCompletedAt = t.Unix()
|
|
|
224
|
oldStage.Name = val2.Name
|
259
|
oldStage.Name = val2.Name
|
|
|
260
|
+ oldStage.PlanCompletedAt = t.Unix()
|
|
|
261
|
+ //TODO 修改里程碑计划完成时间,特殊处理
|
225
|
}
|
262
|
}
|
226
|
stageList = append(stageList, newStageList...)
|
263
|
stageList = append(stageList, newStageList...)
|
227
|
|
264
|
|
|
@@ -331,6 +368,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task |
|
@@ -331,6 +368,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task |
331
|
Name: val.Name,
|
368
|
Name: val.Name,
|
332
|
PlanCompletedAt: t1,
|
369
|
PlanCompletedAt: t1,
|
333
|
RealCompletedAt: t2,
|
370
|
RealCompletedAt: t2,
|
|
|
371
|
+ SortBy: val.SortBy,
|
334
|
StatusDescript: val.StatusDescript(),
|
372
|
StatusDescript: val.StatusDescript(),
|
335
|
Status: int(val.Status),
|
373
|
Status: int(val.Status),
|
336
|
})
|
374
|
})
|
|
@@ -495,6 +533,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte |
|
@@ -495,6 +533,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte |
495
|
Name: val.Name,
|
533
|
Name: val.Name,
|
496
|
StatusDescript: val.StatusDescript(),
|
534
|
StatusDescript: val.StatusDescript(),
|
497
|
Status: int(val.Status),
|
535
|
Status: int(val.Status),
|
|
|
536
|
+ SortBy: val.SortBy,
|
498
|
}
|
537
|
}
|
499
|
switch val.SortBy {
|
538
|
switch val.SortBy {
|
500
|
case 1:
|
539
|
case 1:
|