作者 tangxvhui

暂存

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