作者 tangxvhui

暂存

... ... @@ -23,9 +23,10 @@ type UserData struct {
type TaskStage struct {
Id int `json:"id,string"`
Name string `json:"name"` //里程碑名称
StatusDescript string `json:"statusDescript"` //里程碑的完成情况
Status int `json:"status"` //里程碑名称状态
Name string `json:"name"` //里程碑名称
StatusDescript string `json:"statusDescript"` //里程碑的完成情况
Status int `json:"status"` //里程碑状态
SortBy int `json:"sortBy"`
PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02
RealCompletedAt string `json:"realCompletedAt"` //实际完成时间, 例:2006-01-02
}
... ...
package command
type UpdateTaskCommand struct {
Id int `json:"id,string"`
Alias string `json:"alias"` //任务名称
LevelName string `json:"levelName"` //优先级
StageList []struct {
Id int `json:"id,string"`
Alias string `json:"alias"` //任务名称
LevelName string `json:"levelName"` //优先级
RelatedUserId []string `json:"relatedUserId"` //相关人员id
StageList []struct {
Id int `json:"id,string"`
Name string `json:"name"` //里程碑名称
PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02
... ...
... ... @@ -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:
... ...
... ... @@ -119,7 +119,7 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d
query.Where("task.name like ?", val)
}
if val, ok := queryOptions["companyId"]; ok {
query.Where("task.company_id like ?", val)
query.Where("task.company_id = ?", val)
}
if val, ok := queryOptions["leaderId"]; ok {
... ...
... ... @@ -26,7 +26,7 @@ func NewTaskStageRepository(transactionContext *pgTransaction.TransactionContext
func (repo *TaskStageRepository) TransformToDomain(d *models.TaskStage) *domain.TaskStage {
return &domain.TaskStage{
Id: d.Id,
TaskId: 0,
TaskId: d.TaskId,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
... ...