正在显示
5 个修改的文件
包含
125 行增加
和
6 行删除
@@ -277,7 +277,7 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. | @@ -277,7 +277,7 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. | ||
277 | "transactionContext": transactionContext, | 277 | "transactionContext": transactionContext, |
278 | }) | 278 | }) |
279 | cnt, _, err := messageRepo.Find(map[string]interface{}{ | 279 | cnt, _, err := messageRepo.Find(map[string]interface{}{ |
280 | - "types": domain.MessageTypesTaskStage, | 280 | + "types": domain.MessageTypesTaskRecord, |
281 | "targetUserId": param.UserId, | 281 | "targetUserId": param.UserId, |
282 | "limit": 1, | 282 | "limit": 1, |
283 | }) | 283 | }) |
@@ -415,3 +415,52 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. | @@ -415,3 +415,52 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. | ||
415 | } | 415 | } |
416 | return resp, nil | 416 | return resp, nil |
417 | } | 417 | } |
418 | + | ||
419 | +// TodayMessage 任务里程碑变更通知 | ||
420 | +func (srv *MessagePersonalService) TodayMessageTaskStageModify(param *command.GetUserMessageCommand) (map[string]interface{}, error) { | ||
421 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
422 | + if err != nil { | ||
423 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
424 | + } | ||
425 | + if err := transactionContext.StartTransaction(); err != nil { | ||
426 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
427 | + } | ||
428 | + defer func() { | ||
429 | + _ = transactionContext.RollbackTransaction() | ||
430 | + }() | ||
431 | + | ||
432 | + messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{ | ||
433 | + "transactionContext": transactionContext, | ||
434 | + }) | ||
435 | + _, messageList, err := messageRepo.Find(map[string]interface{}{ | ||
436 | + "types": domain.MessageTypesTaskModify, | ||
437 | + "targetUserId": param.UserId, | ||
438 | + }) | ||
439 | + if err != nil { | ||
440 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查个人消息的消息"+err.Error()) | ||
441 | + } | ||
442 | + for _, val := range messageList { | ||
443 | + val.ReadFlag = domain.MessageIsRead | ||
444 | + err = messageRepo.Save(val) | ||
445 | + if err != nil { | ||
446 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查个人消息的消息"+err.Error()) | ||
447 | + } | ||
448 | + } | ||
449 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
450 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
451 | + } | ||
452 | + msgList := []adapter.MessageListAdapter{} | ||
453 | + for _, val := range messageList { | ||
454 | + msgList = append(msgList, adapter.MessageListAdapter{ | ||
455 | + Content: val.Content, | ||
456 | + }) | ||
457 | + } | ||
458 | + resp := map[string]interface{}{ | ||
459 | + "needNotify": true, | ||
460 | + "list": msgList, | ||
461 | + } | ||
462 | + if len(msgList) == 0 { | ||
463 | + resp["needNotify"] = false | ||
464 | + } | ||
465 | + return resp, nil | ||
466 | +} |
1 | package service | 1 | package service |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "encoding/json" | ||
5 | + "fmt" | ||
4 | "strconv" | 6 | "strconv" |
5 | "time" | 7 | "time" |
6 | 8 | ||
@@ -231,6 +233,8 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | @@ -231,6 +233,8 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | ||
231 | } | 233 | } |
232 | lastPlanCompletedAt := time.Time{} | 234 | lastPlanCompletedAt := time.Time{} |
233 | newStageList := []*domain.TaskStage{} | 235 | newStageList := []*domain.TaskStage{} |
236 | + //标记完成时间变更的里程碑 | ||
237 | + markStage := []domain.TaskStage{} | ||
234 | for i, val2 := range param.StageList { | 238 | for i, val2 := range param.StageList { |
235 | t, err := time.ParseInLocation("2006-01-02", val2.PlanCompletedAt, time.Local) | 239 | t, err := time.ParseInLocation("2006-01-02", val2.PlanCompletedAt, time.Local) |
236 | if err != nil { | 240 | if err != nil { |
@@ -262,10 +266,30 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | @@ -262,10 +266,30 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | ||
262 | oldStage.DeletedAt = nil | 266 | oldStage.DeletedAt = nil |
263 | oldStage.SortBy = i + 1 | 267 | oldStage.SortBy = i + 1 |
264 | oldStage.Name = val2.Name | 268 | oldStage.Name = val2.Name |
265 | - oldStage.PlanCompleted(t) | ||
266 | - | 269 | + if ok := oldStage.PlanCompleted(t); ok { |
270 | + markStage = append(markStage, *oldStage) | ||
271 | + } | ||
267 | } | 272 | } |
273 | + | ||
268 | stageList = append(stageList, newStageList...) | 274 | stageList = append(stageList, newStageList...) |
275 | + //查询是否已经有每日评估 | ||
276 | + taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{ | ||
277 | + "transactionContext": transactionContext, | ||
278 | + }) | ||
279 | + cnt, _, err := taskRecordRepo.Find(map[string]interface{}{ | ||
280 | + "taskId": taskData.Id, | ||
281 | + "limit": 1, | ||
282 | + }) | ||
283 | + if err != nil { | ||
284 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "相关联的任务反馈信息"+err.Error()) | ||
285 | + } | ||
286 | + if cnt > 0 { | ||
287 | + for _, v := range stageList { | ||
288 | + if v.DeletedAt != nil { | ||
289 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有日评数据,不能删除里程碑") | ||
290 | + } | ||
291 | + } | ||
292 | + } | ||
269 | 293 | ||
270 | err = taskStageRepo.Save(stageList) | 294 | err = taskStageRepo.Save(stageList) |
271 | if err != nil { | 295 | if err != nil { |
@@ -275,6 +299,33 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | @@ -275,6 +299,33 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | ||
275 | if err != nil { | 299 | if err != nil { |
276 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 300 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
277 | } | 301 | } |
302 | + messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{ | ||
303 | + "transactionContext": transactionContext, | ||
304 | + }) | ||
305 | + //更具markStage 记录的里程碑数据生成通知 | ||
306 | + for _, val := range markStage { | ||
307 | + for _, val2 := range taskData.RelatedUser { | ||
308 | + t1 := time.Unix(val.PlanCompletedAt, 0).Format("2006-01-02") | ||
309 | + s := fmt.Sprintf("【%s 任务里程碑 %s 完成时间变更为 %s,请知晓", taskData.Name, val.Name, t1) | ||
310 | + payload := map[string]string{ | ||
311 | + "id": strconv.Itoa(val.Id), | ||
312 | + } | ||
313 | + payloadStr, _ := json.Marshal(payload) | ||
314 | + newMessage := domain.MessagePersonal{ | ||
315 | + Id: 0, | ||
316 | + Types: domain.MessageTypesTaskModify, | ||
317 | + TargetUserId: val2, | ||
318 | + ReadFlag: domain.MessageUnread, | ||
319 | + Title: s, | ||
320 | + Content: s, | ||
321 | + Payload: string(payloadStr), | ||
322 | + } | ||
323 | + err = messageRepo.Save(&newMessage) | ||
324 | + if err != nil { | ||
325 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
326 | + } | ||
327 | + } | ||
328 | + } | ||
278 | if err := transactionContext.CommitTransaction(); err != nil { | 329 | if err := transactionContext.CommitTransaction(); err != nil { |
279 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 330 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
280 | } | 331 | } |
@@ -420,7 +471,6 @@ func (srv TaskService) RunTask(param *command.RunTaskCommand) (map[string]interf | @@ -420,7 +471,6 @@ func (srv TaskService) RunTask(param *command.RunTaskCommand) (map[string]interf | ||
420 | if taskData.Status == domain.TaskRunning { | 471 | if taskData.Status == domain.TaskRunning { |
421 | return map[string]interface{}{"id": param.TaskId}, nil | 472 | return map[string]interface{}{"id": param.TaskId}, nil |
422 | } | 473 | } |
423 | - | ||
424 | taskData.Status = domain.TaskRunning | 474 | taskData.Status = domain.TaskRunning |
425 | taskData.RunAt = time.Now().Unix() | 475 | taskData.RunAt = time.Now().Unix() |
426 | err = taskRepo.Save(taskData) | 476 | err = taskRepo.Save(taskData) |
@@ -52,8 +52,17 @@ func (t TaskStage) StatusDescription() string { | @@ -52,8 +52,17 @@ func (t TaskStage) StatusDescription() string { | ||
52 | return str | 52 | return str |
53 | } | 53 | } |
54 | 54 | ||
55 | -func (t *TaskStage) PlanCompleted(now time.Time) { | ||
56 | - t.PlanCompletedAt = t.dayEndTime(now).Unix() | 55 | +// 计划完成是否变更 |
56 | +func (t *TaskStage) PlanCompleted(now time.Time) bool { | ||
57 | + if t.RealCompletedAt != 0 { | ||
58 | + return false | ||
59 | + } | ||
60 | + newTime := t.dayEndTime(now).Unix() | ||
61 | + if t.PlanCompletedAt == newTime { | ||
62 | + return false | ||
63 | + } | ||
64 | + t.PlanCompletedAt = newTime | ||
65 | + return true | ||
57 | } | 66 | } |
58 | 67 | ||
59 | func (t TaskStage) dayEndTime(now time.Time) time.Time { | 68 | func (t TaskStage) dayEndTime(now time.Time) time.Time { |
@@ -39,3 +39,12 @@ func (c *MessagePersonalController) TodayMessageTaskRecordAnomaly() { | @@ -39,3 +39,12 @@ func (c *MessagePersonalController) TodayMessageTaskRecordAnomaly() { | ||
39 | data, err := srv.TodayMessageTaskRecordAnomaly(¶m) | 39 | data, err := srv.TodayMessageTaskRecordAnomaly(¶m) |
40 | c.Response(data, err) | 40 | c.Response(data, err) |
41 | } | 41 | } |
42 | + | ||
43 | +func (c *MessagePersonalController) TodayMessageTaskStageModify() { | ||
44 | + srv := service.NewMessagePersonalService() | ||
45 | + userReq := middlewares.GetUser(c.Ctx) | ||
46 | + param := command.GetUserMessageCommand{} | ||
47 | + param.UserId = int(userReq.UserId) | ||
48 | + data, err := srv.TodayMessageTaskStageModify(¶m) | ||
49 | + c.Response(data, err) | ||
50 | +} |
@@ -13,6 +13,8 @@ func init() { | @@ -13,6 +13,8 @@ func init() { | ||
13 | web.NSCtrlGet("/summary-evaluation/self/today", (*controllers.MessagePersonalController).TodayMessageSummaryEvaluation), | 13 | web.NSCtrlGet("/summary-evaluation/self/today", (*controllers.MessagePersonalController).TodayMessageSummaryEvaluation), |
14 | web.NSCtrlGet("/summary-evaluation/task_stage/today", (*controllers.MessagePersonalController).TodayMessageTaskStageAnomaly), | 14 | web.NSCtrlGet("/summary-evaluation/task_stage/today", (*controllers.MessagePersonalController).TodayMessageTaskStageAnomaly), |
15 | web.NSCtrlGet("/summary-evaluation/task_record/today", (*controllers.MessagePersonalController).TodayMessageTaskRecordAnomaly), | 15 | web.NSCtrlGet("/summary-evaluation/task_record/today", (*controllers.MessagePersonalController).TodayMessageTaskRecordAnomaly), |
16 | + web.NSCtrlGet("/summary-evaluation/task_modify/today", (*controllers.MessagePersonalController).TodayMessageTaskStageModify), | ||
17 | + // | ||
16 | ) | 18 | ) |
17 | web.AddNamespace(ns) | 19 | web.AddNamespace(ns) |
18 | } | 20 | } |
-
请 注册 或 登录 后发表评论