正在显示
11 个修改的文件
包含
147 行增加
和
27 行删除
@@ -231,3 +231,11 @@ func CreateTaskStageRepository(options map[string]interface{}) domain.TaskStageR | @@ -231,3 +231,11 @@ func CreateTaskStageRepository(options map[string]interface{}) domain.TaskStageR | ||
231 | } | 231 | } |
232 | return repository.NewTaskStageRepository(transactionContext) | 232 | return repository.NewTaskStageRepository(transactionContext) |
233 | } | 233 | } |
234 | + | ||
235 | +func CreateTaskIgnoreRepository(options map[string]interface{}) domain.TaskIgnoreRepository { | ||
236 | + var transactionContext *pg.TransactionContext | ||
237 | + if value, ok := options["transactionContext"]; ok { | ||
238 | + transactionContext = value.(*pg.TransactionContext) | ||
239 | + } | ||
240 | + return repository.NewTaskIgnoreRepository(transactionContext) | ||
241 | +} |
@@ -22,7 +22,8 @@ type UserData struct { | @@ -22,7 +22,8 @@ type UserData struct { | ||
22 | type TaskStage struct { | 22 | type TaskStage struct { |
23 | Id int `json:"id,string"` | 23 | Id int `json:"id,string"` |
24 | Name string `json:"name"` //里程碑名称 | 24 | Name string `json:"name"` //里程碑名称 |
25 | - StatusCompleted string `json:"statusCompleted"` //里程碑的完成情况 | 25 | + StatusDescript string `json:"statusDescript"` //里程碑的完成情况 |
26 | + Status int `json:"status"` //里程碑名称状态 | ||
26 | PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02 | 27 | PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02 |
27 | RealCompletedAt string `json:"realCompletedAt"` //实际完成时间, 例:2006-01-02 | 28 | RealCompletedAt string `json:"realCompletedAt"` //实际完成时间, 例:2006-01-02 |
28 | } | 29 | } |
@@ -8,9 +8,9 @@ type TaskItem struct { | @@ -8,9 +8,9 @@ type TaskItem struct { | ||
8 | Status int `json:"status"` // 任务的状态 | 8 | Status int `json:"status"` // 任务的状态 |
9 | Level int `json:"level"` // 优先级,值越小优先级越高 | 9 | Level int `json:"level"` // 优先级,值越小优先级越高 |
10 | LevelName string `json:"levelName"` // 优先级名称 | 10 | LevelName string `json:"levelName"` // 优先级名称 |
11 | - StageA string `json:"stageA"` // 里程碑1 | ||
12 | - StageB string `json:"stageB"` // 里程碑2 | ||
13 | - StageC string `json:"stageC"` // 里程碑3 | ||
14 | - StageD string `json:"stageD"` // 里程碑4 | ||
15 | - StageE string `json:"stageE"` // 里程碑5 | 11 | + StageA TaskStage `json:"stageA"` // 里程碑1 |
12 | + StageB TaskStage `json:"stageB"` // 里程碑2 | ||
13 | + StageC TaskStage `json:"stageC"` // 里程碑3 | ||
14 | + StageD TaskStage `json:"stageD"` // 里程碑4 | ||
15 | + StageE TaskStage `json:"stageE"` // 里程碑5 | ||
16 | } | 16 | } |
@@ -2,5 +2,5 @@ package command | @@ -2,5 +2,5 @@ package command | ||
2 | 2 | ||
3 | type CreateTaskCommand struct { | 3 | type CreateTaskCommand struct { |
4 | Name string `json:"name"` //任务名称 | 4 | Name string `json:"name"` //任务名称 |
5 | - LeaderId int `json:"leaderId"` //赋值人id | 5 | + LeaderId int `json:"leaderId,string"` //赋值人id |
6 | } | 6 | } |
@@ -25,6 +25,27 @@ func dayEndTime(t time.Time) time.Time { | @@ -25,6 +25,27 @@ func dayEndTime(t time.Time) time.Time { | ||
25 | return t2 | 25 | return t2 |
26 | } | 26 | } |
27 | 27 | ||
28 | +func (srv TaskService) CreateTaskTest(param *command.CreateTaskCommand) error { | ||
29 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
30 | + if err != nil { | ||
31 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
32 | + } | ||
33 | + if err := transactionContext.StartTransaction(); err != nil { | ||
34 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
35 | + } | ||
36 | + defer func() { | ||
37 | + _ = transactionContext.RollbackTransaction() | ||
38 | + }() | ||
39 | + err = srv.CreateTask(transactionContext, param) | ||
40 | + if err != nil { | ||
41 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) | ||
42 | + } | ||
43 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
44 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
45 | + } | ||
46 | + return nil | ||
47 | +} | ||
48 | + | ||
28 | func (srv TaskService) CreateTask(transactionContext application.TransactionContext, param *command.CreateTaskCommand) error { | 49 | func (srv TaskService) CreateTask(transactionContext application.TransactionContext, param *command.CreateTaskCommand) error { |
29 | taskRepo := factory.CreateTaskRepository(map[string]interface{}{ | 50 | taskRepo := factory.CreateTaskRepository(map[string]interface{}{ |
30 | "transactionContext": transactionContext, | 51 | "transactionContext": transactionContext, |
@@ -44,16 +65,40 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont | @@ -44,16 +65,40 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont | ||
44 | //任务已存在 | 65 | //任务已存在 |
45 | return nil | 66 | return nil |
46 | } | 67 | } |
68 | + userRepo := factory.CreateUserRepository(map[string]interface{}{ | ||
69 | + "transactionContext": transactionContext, | ||
70 | + }) | ||
71 | + | ||
72 | + _, leaderList, err := userRepo.Find(map[string]interface{}{ | ||
73 | + "id": param.LeaderId, | ||
74 | + }) | ||
75 | + if err != nil { | ||
76 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询人员失败:"+err.Error()) | ||
77 | + } | ||
78 | + if len(leaderList) == 0 { | ||
79 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有查询到人员") | ||
80 | + } | ||
81 | + leaderData := leaderList[0] | ||
47 | nowTime := time.Now() | 82 | nowTime := time.Now() |
48 | newTask := domain.Task{ | 83 | newTask := domain.Task{ |
49 | Id: 0, | 84 | Id: 0, |
85 | + CreatedAt: time.Time{}, | ||
86 | + UpdatedAt: time.Time{}, | ||
87 | + DeletedAt: nil, | ||
88 | + CompanyId: int(leaderData.CompanyId), | ||
50 | Name: param.Name, | 89 | Name: param.Name, |
51 | Alias: param.Name, | 90 | Alias: param.Name, |
91 | + Leader: domain.TaskLeader{ | ||
92 | + Id: leaderData.Id, | ||
93 | + Account: leaderData.Account, | ||
94 | + Name: leaderData.Name, | ||
95 | + }, | ||
52 | Status: domain.TaskWait, | 96 | Status: domain.TaskWait, |
53 | Level: 0, | 97 | Level: 0, |
54 | LevelName: "", | 98 | LevelName: "", |
55 | RelatedUser: []int{}, | 99 | RelatedUser: []int{}, |
56 | RunAt: nowTime.Unix(), | 100 | RunAt: nowTime.Unix(), |
101 | + StopAt: 0, | ||
57 | } | 102 | } |
58 | newTask.ApplyLevelName("") | 103 | newTask.ApplyLevelName("") |
59 | err = taskRepo.Save(&newTask) | 104 | err = taskRepo.Save(&newTask) |
@@ -297,7 +342,8 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task | @@ -297,7 +342,8 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task | ||
297 | Name: val.Name, | 342 | Name: val.Name, |
298 | PlanCompletedAt: t1, | 343 | PlanCompletedAt: t1, |
299 | RealCompletedAt: t2, | 344 | RealCompletedAt: t2, |
300 | - StatusCompleted: val.DescriptStatus(), | 345 | + StatusDescript: val.StatusDescript(), |
346 | + Status: int(val.Status), | ||
301 | }) | 347 | }) |
302 | } | 348 | } |
303 | return &result, nil | 349 | return &result, nil |
@@ -441,11 +487,11 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | @@ -441,11 +487,11 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | ||
441 | Status: int(val.Status), | 487 | Status: int(val.Status), |
442 | Level: val.Level, | 488 | Level: val.Level, |
443 | LevelName: val.LevelName, | 489 | LevelName: val.LevelName, |
444 | - StageA: "", | ||
445 | - StageB: "", | ||
446 | - StageC: "", | ||
447 | - StageD: "", | ||
448 | - StageE: "", | 490 | + // StageA: adapter.TaskStage{}, |
491 | + // StageB: adapter.TaskStage{}, | ||
492 | + // StageC: adapter.TaskStage{}, | ||
493 | + // StageD: adapter.TaskStage{}, | ||
494 | + // StageE: adapter.TaskStage{}, | ||
449 | } | 495 | } |
450 | taskResult = append(taskResult, &tk) | 496 | taskResult = append(taskResult, &tk) |
451 | taskMapResult[val.Id] = &tk | 497 | taskMapResult[val.Id] = &tk |
@@ -455,17 +501,23 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | @@ -455,17 +501,23 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte | ||
455 | if !ok { | 501 | if !ok { |
456 | continue | 502 | continue |
457 | } | 503 | } |
504 | + stage := adapter.TaskStage{ | ||
505 | + Id: val.Id, | ||
506 | + Name: val.Name, | ||
507 | + StatusDescript: val.StatusDescript(), | ||
508 | + Status: int(val.Status), | ||
509 | + } | ||
458 | switch val.SortBy { | 510 | switch val.SortBy { |
459 | case 1: | 511 | case 1: |
460 | - taskData.StageA = val.Name | 512 | + taskData.StageA = stage |
461 | case 2: | 513 | case 2: |
462 | - taskData.StageB = val.Name | 514 | + taskData.StageB = stage |
463 | case 3: | 515 | case 3: |
464 | - taskData.StageC = val.Name | 516 | + taskData.StageC = stage |
465 | case 4: | 517 | case 4: |
466 | - taskData.StageD = val.Name | 518 | + taskData.StageD = stage |
467 | case 5: | 519 | case 5: |
468 | - taskData.StageE = val.Name | 520 | + taskData.StageE = stage |
469 | } | 521 | } |
470 | } | 522 | } |
471 | result := tool_funs.SimpleWrapGridMap(int64(taskCnt), taskResult) | 523 | result := tool_funs.SimpleWrapGridMap(int64(taskCnt), taskResult) |
@@ -492,8 +544,19 @@ func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) erro | @@ -492,8 +544,19 @@ func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) erro | ||
492 | defer func() { | 544 | defer func() { |
493 | _ = transactionContext.RollbackTransaction() | 545 | _ = transactionContext.RollbackTransaction() |
494 | }() | 546 | }() |
495 | - //0 | ||
496 | - //0 | 547 | + taskIgnoreRepo := factory.CreateTaskIgnoreRepository(map[string]interface{}{ |
548 | + "transactionContext": transactionContext, | ||
549 | + }) | ||
550 | + taskIgnore := domain.TaskIgnore{ | ||
551 | + Id: 0, | ||
552 | + TaskId: param.TaskId, | ||
553 | + UserId: param.UserId, | ||
554 | + CreatedAt: time.Time{}, | ||
555 | + } | ||
556 | + err = taskIgnoreRepo.Save(&taskIgnore) | ||
557 | + if err != nil { | ||
558 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
559 | + } | ||
497 | if err := transactionContext.CommitTransaction(); err != nil { | 560 | if err := transactionContext.CommitTransaction(); err != nil { |
498 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 561 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
499 | } | 562 | } |
@@ -32,7 +32,7 @@ type TaskStageRepository interface { | @@ -32,7 +32,7 @@ type TaskStageRepository interface { | ||
32 | } | 32 | } |
33 | 33 | ||
34 | // 描述里程碑完成情况 | 34 | // 描述里程碑完成情况 |
35 | -func (t TaskStage) DescriptStatus() string { | 35 | +func (t TaskStage) StatusDescript() string { |
36 | nowDay := time.Now().Format("2006-01-02") | 36 | nowDay := time.Now().Format("2006-01-02") |
37 | nowTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local) | 37 | nowTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local) |
38 | 38 |
@@ -19,6 +19,10 @@ type TaskIgnoreRepository struct { | @@ -19,6 +19,10 @@ type TaskIgnoreRepository struct { | ||
19 | 19 | ||
20 | var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil) | 20 | var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil) |
21 | 21 | ||
22 | +func NewTaskIgnoreRepository(transactionContext *pgTransaction.TransactionContext) *TaskIgnoreRepository { | ||
23 | + return &TaskIgnoreRepository{transactionContext: transactionContext} | ||
24 | +} | ||
25 | + | ||
22 | func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domain.TaskIgnore { | 26 | func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domain.TaskIgnore { |
23 | return &domain.TaskIgnore{ | 27 | return &domain.TaskIgnore{ |
24 | Id: d.Id, | 28 | Id: d.Id, |
@@ -31,7 +35,6 @@ func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domai | @@ -31,7 +35,6 @@ func (repo *TaskIgnoreRepository) TransformToDomain(d *models.TaskIgnore) *domai | ||
31 | func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error { | 35 | func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error { |
32 | if param.Id == 0 { | 36 | if param.Id == 0 { |
33 | param.CreatedAt = time.Now() | 37 | param.CreatedAt = time.Now() |
34 | - return nil | ||
35 | } | 38 | } |
36 | m := models.TaskIgnore{ | 39 | m := models.TaskIgnore{ |
37 | Id: param.Id, | 40 | Id: param.Id, |
@@ -46,7 +46,6 @@ func (repo *TaskRepository) Save(param *domain.Task) error { | @@ -46,7 +46,6 @@ func (repo *TaskRepository) Save(param *domain.Task) error { | ||
46 | param.UpdatedAt = time.Now() | 46 | param.UpdatedAt = time.Now() |
47 | if param.Id == 0 { | 47 | if param.Id == 0 { |
48 | param.CreatedAt = time.Now() | 48 | param.CreatedAt = time.Now() |
49 | - return nil | ||
50 | } | 49 | } |
51 | m := models.Task{ | 50 | m := models.Task{ |
52 | Id: param.Id, | 51 | Id: param.Id, |
@@ -124,7 +123,7 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d | @@ -124,7 +123,7 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d | ||
124 | } | 123 | } |
125 | 124 | ||
126 | if val, ok := queryOptions["leaderId"]; ok { | 125 | if val, ok := queryOptions["leaderId"]; ok { |
127 | - query.Where("task.leader->>'userId'='?'", val) | 126 | + query.Where("task.leader->>'id'='?'", val) |
128 | } | 127 | } |
129 | if val, ok := queryOptions["aliasOrLeader"]; ok { | 128 | if val, ok := queryOptions["aliasOrLeader"]; ok { |
130 | query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val) | 129 | query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val) |
@@ -39,11 +39,26 @@ func (c *TaskController) UpdateTask() { | @@ -39,11 +39,26 @@ func (c *TaskController) UpdateTask() { | ||
39 | c.Response(nil, e) | 39 | c.Response(nil, e) |
40 | return | 40 | return |
41 | } | 41 | } |
42 | - // userReq := middlewares.GetUser(c.Ctx) | 42 | + |
43 | data, err := srv.UpdateTask(paramReq) | 43 | data, err := srv.UpdateTask(paramReq) |
44 | c.Response(data, err) | 44 | c.Response(data, err) |
45 | } | 45 | } |
46 | 46 | ||
47 | +// 更新任务 | ||
48 | +func (c *TaskController) CreateTask() { | ||
49 | + srv := service.NewTaskService() | ||
50 | + paramReq := &command.CreateTaskCommand{} | ||
51 | + err := c.BindJSON(paramReq) | ||
52 | + if err != nil { | ||
53 | + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error()) | ||
54 | + c.Response(nil, e) | ||
55 | + return | ||
56 | + } | ||
57 | + | ||
58 | + err = srv.CreateTaskTest(paramReq) | ||
59 | + c.Response(nil, err) | ||
60 | +} | ||
61 | + | ||
47 | // 启动任务 | 62 | // 启动任务 |
48 | func (c *TaskController) RunTask() { | 63 | func (c *TaskController) RunTask() { |
49 | srv := service.NewTaskService() | 64 | srv := service.NewTaskService() |
@@ -54,6 +69,8 @@ func (c *TaskController) RunTask() { | @@ -54,6 +69,8 @@ func (c *TaskController) RunTask() { | ||
54 | c.Response(nil, e) | 69 | c.Response(nil, e) |
55 | return | 70 | return |
56 | } | 71 | } |
72 | + userReq := middlewares.GetUser(c.Ctx) | ||
73 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
57 | data, err := srv.RunTask(paramReq) | 74 | data, err := srv.RunTask(paramReq) |
58 | c.Response(data, err) | 75 | c.Response(data, err) |
59 | } | 76 | } |
@@ -68,6 +85,8 @@ func (c *TaskController) StopTask() { | @@ -68,6 +85,8 @@ func (c *TaskController) StopTask() { | ||
68 | c.Response(nil, e) | 85 | c.Response(nil, e) |
69 | return | 86 | return |
70 | } | 87 | } |
88 | + userReq := middlewares.GetUser(c.Ctx) | ||
89 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
71 | data, err := srv.StopTask(paramReq) | 90 | data, err := srv.StopTask(paramReq) |
72 | c.Response(data, err) | 91 | c.Response(data, err) |
73 | } | 92 | } |
@@ -82,6 +101,24 @@ func (c *TaskController) ListTask() { | @@ -82,6 +101,24 @@ func (c *TaskController) ListTask() { | ||
82 | c.Response(nil, e) | 101 | c.Response(nil, e) |
83 | return | 102 | return |
84 | } | 103 | } |
104 | + userReq := middlewares.GetUser(c.Ctx) | ||
105 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
85 | data, err := srv.ListTask(paramReq) | 106 | data, err := srv.ListTask(paramReq) |
86 | c.Response(data, err) | 107 | c.Response(data, err) |
87 | } | 108 | } |
109 | + | ||
110 | +// CancelAttention 取消关注的任务 | ||
111 | +func (c *TaskController) CancelAttention() { | ||
112 | + srv := service.NewTaskService() | ||
113 | + paramReq := &command.CancelAttentionCommand{} | ||
114 | + err := c.BindJSON(paramReq) | ||
115 | + if err != nil { | ||
116 | + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error()) | ||
117 | + c.Response(nil, e) | ||
118 | + return | ||
119 | + } | ||
120 | + userReq := middlewares.GetUser(c.Ctx) | ||
121 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
122 | + err = srv.CancelAttention(paramReq) | ||
123 | + c.Response(nil, err) | ||
124 | +} |
@@ -20,6 +20,14 @@ func init() { | @@ -20,6 +20,14 @@ func init() { | ||
20 | web.AddNamespace(taskAdminNS) | 20 | web.AddNamespace(taskAdminNS) |
21 | 21 | ||
22 | taskFontNS := web.NewNamespace("/v1/font/task", | 22 | taskFontNS := web.NewNamespace("/v1/font/task", |
23 | - web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken())) | 23 | + web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()), |
24 | + web.NSCtrlPost("/attention/cancel", (*controllers.TaskController).CancelAttention), | ||
25 | + web.NSCtrlPost("/list", (*controllers.TaskController).ListTask), //TODO | ||
26 | + ) | ||
24 | web.AddNamespace(taskFontNS) | 27 | web.AddNamespace(taskFontNS) |
28 | + | ||
29 | + t := web.NewNamespace("/test/task", | ||
30 | + web.NSCtrlPost("/", (*controllers.TaskController).CreateTask), | ||
31 | + ) | ||
32 | + web.AddNamespace(t) | ||
25 | } | 33 | } |
-
请 注册 或 登录 后发表评论