...
|
...
|
@@ -100,7 +100,7 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont |
|
|
RunAt: nowTime.Unix(),
|
|
|
StopAt: 0,
|
|
|
}
|
|
|
newTask.ApplyLevelName("")
|
|
|
newTask.ApplyLevelName("战略任务")
|
|
|
err = taskRepo.Save(&newTask)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
|
...
|
...
|
@@ -144,6 +144,8 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 更新任务
|
|
|
// TODO 检查是否可以修改,和通知
|
|
|
func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]interface{}, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
...
|
...
|
@@ -155,9 +157,22 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
if len(param.StageList) < 3 {
|
|
|
return map[string]interface{}{
|
|
|
"id": param.Id,
|
|
|
}, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量至少3个")
|
|
|
}
|
|
|
if len(param.StageList) > 5 {
|
|
|
return map[string]interface{}{
|
|
|
"id": param.Id,
|
|
|
}, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑数量太多")
|
|
|
}
|
|
|
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
...
|
...
|
@@ -173,6 +188,21 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//任务的相关人员
|
|
|
relatedUserIds := []int{}
|
|
|
for _, val := range param.RelatedUserId {
|
|
|
id, _ := strconv.Atoi(val)
|
|
|
relatedUserIds = append(relatedUserIds, id)
|
|
|
}
|
|
|
var relatedUser []*domain.User
|
|
|
if len(relatedUserIds) > 0 {
|
|
|
_, relatedUser, err = userRepo.Find(map[string]interface{}{
|
|
|
"ids": relatedUserIds,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务的相关人员"+err.Error())
|
|
|
}
|
|
|
}
|
|
|
ok, err := srv.canUpdateTask(taskData, stageList)
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -180,6 +210,12 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
if !ok {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "日评数据已生成,任务不能再被编辑")
|
|
|
}
|
|
|
//更新相关人员
|
|
|
taskData.RelatedUser = []int{}
|
|
|
for _, val := range relatedUser {
|
|
|
taskData.RelatedUser = append(taskData.RelatedUser, int(val.Id))
|
|
|
}
|
|
|
//更新任务名称
|
|
|
taskData.Alias = param.Alias
|
|
|
taskData.ApplyLevelName(param.LevelName)
|
|
|
nowTime := time.Now()
|
...
|
...
|
@@ -197,7 +233,7 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
}
|
|
|
if i > 0 {
|
|
|
if lastPlanCompletedAt.After(t) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑完成时间填写错误")
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "里程碑["+val2.Name+"]完成时间填写错误")
|
|
|
}
|
|
|
}
|
|
|
lastPlanCompletedAt = t
|
...
|
...
|
@@ -220,8 +256,9 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
}
|
|
|
oldStage.DeletedAt = nil
|
|
|
oldStage.SortBy = i + 1
|
|
|
oldStage.PlanCompletedAt = t.Unix()
|
|
|
oldStage.Name = val2.Name
|
|
|
oldStage.PlanCompletedAt = t.Unix()
|
|
|
//TODO 修改里程碑计划完成时间,特殊处理
|
|
|
}
|
|
|
stageList = append(stageList, newStageList...)
|
|
|
|
...
|
...
|
@@ -331,6 +368,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task |
|
|
Name: val.Name,
|
|
|
PlanCompletedAt: t1,
|
|
|
RealCompletedAt: t2,
|
|
|
SortBy: val.SortBy,
|
|
|
StatusDescript: val.StatusDescript(),
|
|
|
Status: int(val.Status),
|
|
|
})
|
...
|
...
|
@@ -495,6 +533,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte |
|
|
Name: val.Name,
|
|
|
StatusDescript: val.StatusDescript(),
|
|
|
Status: int(val.Status),
|
|
|
SortBy: val.SortBy,
|
|
|
}
|
|
|
switch val.SortBy {
|
|
|
case 1:
|
...
|
...
|
|