|
|
package service
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
...
|
...
|
@@ -231,6 +233,8 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
}
|
|
|
lastPlanCompletedAt := time.Time{}
|
|
|
newStageList := []*domain.TaskStage{}
|
|
|
//标记完成时间变更的里程碑
|
|
|
markStage := []domain.TaskStage{}
|
|
|
for i, val2 := range param.StageList {
|
|
|
t, err := time.ParseInLocation("2006-01-02", val2.PlanCompletedAt, time.Local)
|
|
|
if err != nil {
|
...
|
...
|
@@ -262,10 +266,30 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
oldStage.DeletedAt = nil
|
|
|
oldStage.SortBy = i + 1
|
|
|
oldStage.Name = val2.Name
|
|
|
oldStage.PlanCompleted(t)
|
|
|
|
|
|
if ok := oldStage.PlanCompleted(t); ok {
|
|
|
markStage = append(markStage, *oldStage)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
stageList = append(stageList, newStageList...)
|
|
|
//查询是否已经有每日评估
|
|
|
taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
cnt, _, err := taskRecordRepo.Find(map[string]interface{}{
|
|
|
"taskId": taskData.Id,
|
|
|
"limit": 1,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "相关联的任务反馈信息"+err.Error())
|
|
|
}
|
|
|
if cnt > 0 {
|
|
|
for _, v := range stageList {
|
|
|
if v.DeletedAt != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有日评数据,不能删除里程碑")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
err = taskStageRepo.Save(stageList)
|
|
|
if err != nil {
|
...
|
...
|
@@ -275,6 +299,33 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
//更具markStage 记录的里程碑数据生成通知
|
|
|
for _, val := range markStage {
|
|
|
for _, val2 := range taskData.RelatedUser {
|
|
|
t1 := time.Unix(val.PlanCompletedAt, 0).Format("2006-01-02")
|
|
|
s := fmt.Sprintf("【%s 任务里程碑 %s 完成时间变更为 %s,请知晓", taskData.Name, val.Name, t1)
|
|
|
payload := map[string]string{
|
|
|
"id": strconv.Itoa(val.Id),
|
|
|
}
|
|
|
payloadStr, _ := json.Marshal(payload)
|
|
|
newMessage := domain.MessagePersonal{
|
|
|
Id: 0,
|
|
|
Types: domain.MessageTypesTaskModify,
|
|
|
TargetUserId: val2,
|
|
|
ReadFlag: domain.MessageUnread,
|
|
|
Title: s,
|
|
|
Content: s,
|
|
|
Payload: string(payloadStr),
|
|
|
}
|
|
|
err = messageRepo.Save(&newMessage)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -420,7 +471,6 @@ func (srv TaskService) RunTask(param *command.RunTaskCommand) (map[string]interf |
|
|
if taskData.Status == domain.TaskRunning {
|
|
|
return map[string]interface{}{"id": param.TaskId}, nil
|
|
|
}
|
|
|
|
|
|
taskData.Status = domain.TaskRunning
|
|
|
taskData.RunAt = time.Now().Unix()
|
|
|
err = taskRepo.Save(taskData)
|
...
|
...
|
|