正在显示
12 个修改的文件
包含
227 行增加
和
4 行删除
@@ -247,3 +247,11 @@ func CreateTaskRecordRepository(options map[string]interface{}) domain.TaskRecor | @@ -247,3 +247,11 @@ func CreateTaskRecordRepository(options map[string]interface{}) domain.TaskRecor | ||
247 | } | 247 | } |
248 | return repository.NewTaskRecordRepository(transactionContext) | 248 | return repository.NewTaskRecordRepository(transactionContext) |
249 | } | 249 | } |
250 | + | ||
251 | +func CreateTaskLevelRepository(options map[string]interface{}) domain.TaskLevelRepository { | ||
252 | + var transactionContext *pg.TransactionContext | ||
253 | + if value, ok := options["transactionContext"]; ok { | ||
254 | + transactionContext = value.(*pg.TransactionContext) | ||
255 | + } | ||
256 | + return repository.NewTaskLevelRepository(transactionContext) | ||
257 | +} |
@@ -45,7 +45,9 @@ func messageTaskStageAnomaly(companyId int) ([]*domain.MessagePersonal, error) { | @@ -45,7 +45,9 @@ func messageTaskStageAnomaly(companyId int) ([]*domain.MessagePersonal, error) { | ||
45 | if len(userList) == 0 { | 45 | if len(userList) == 0 { |
46 | continue | 46 | continue |
47 | } | 47 | } |
48 | + //通知相关人员 | ||
48 | 49 | ||
50 | + //通知负责人 | ||
49 | for _, val2 := range userList { | 51 | for _, val2 := range userList { |
50 | content := "" | 52 | content := "" |
51 | if val2.Level == 1 { | 53 | if val2.Level == 1 { |
@@ -351,7 +351,7 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. | @@ -351,7 +351,7 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. | ||
351 | taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext}) | 351 | taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext}) |
352 | // 我作为任务负责人 | 352 | // 我作为任务负责人 |
353 | leaderIds := []string{strconv.Itoa(param.UserId)} | 353 | leaderIds := []string{strconv.Itoa(param.UserId)} |
354 | - taskStageList, err := taskDao.TaskAnomalyByLeader(leaderIds, 2) | 354 | + taskStageList, err := taskDao.TaskAnomalyByLeader(leaderIds, 1) |
355 | if err != nil { | 355 | if err != nil { |
356 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error()) | 356 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error()) |
357 | } | 357 | } |
@@ -369,7 +369,7 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. | @@ -369,7 +369,7 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. | ||
369 | //我作为上级, 获取我的下一级的异常任务 | 369 | //我作为上级, 获取我的下一级的异常任务 |
370 | var taskStageList2 []dao.TaskData2 | 370 | var taskStageList2 []dao.TaskData2 |
371 | if len(childUserId) > 0 { | 371 | if len(childUserId) > 0 { |
372 | - taskStageList2, err = taskDao.TaskAnomalyByLeader(childUserId, 4) | 372 | + taskStageList2, err = taskDao.TaskAnomalyByLeader(childUserId, 3) |
373 | if err != nil { | 373 | if err != nil { |
374 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error()) | 374 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error()) |
375 | } | 375 | } |
1 | package command | 1 | package command |
2 | 2 | ||
3 | type UpdateTaskCommand struct { | 3 | type UpdateTaskCommand struct { |
4 | + CompanyId int `json:"-"` | ||
4 | Id int `json:"id,string"` | 5 | Id int `json:"id,string"` |
5 | Alias string `json:"alias"` //任务名称 | 6 | Alias string `json:"alias"` //任务名称 |
6 | LevelName string `json:"levelName"` //优先级 | 7 | LevelName string `json:"levelName"` //优先级 |
@@ -349,11 +349,61 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | @@ -349,11 +349,61 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] | ||
349 | if err := transactionContext.CommitTransaction(); err != nil { | 349 | if err := transactionContext.CommitTransaction(); err != nil { |
350 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 350 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
351 | } | 351 | } |
352 | + err = srv.SaveTaskLevel(param.LevelName, param.CompanyId) | ||
353 | + if err != nil { | ||
354 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务等级"+err.Error()) | ||
355 | + } | ||
352 | return map[string]interface{}{ | 356 | return map[string]interface{}{ |
353 | "id": param.Id, | 357 | "id": param.Id, |
354 | }, nil | 358 | }, nil |
355 | } | 359 | } |
356 | 360 | ||
361 | +func (srv TaskService) SaveTaskLevel(levelName string, companyId int) error { | ||
362 | + defalutLevel := domain.DefaultTaskLevel() | ||
363 | + for _, val := range defalutLevel { | ||
364 | + if val.LevelName == levelName { | ||
365 | + return nil | ||
366 | + } | ||
367 | + } | ||
368 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
369 | + if err != nil { | ||
370 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
371 | + } | ||
372 | + if err := transactionContext.StartTransaction(); err != nil { | ||
373 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
374 | + } | ||
375 | + defer func() { | ||
376 | + _ = transactionContext.RollbackTransaction() | ||
377 | + }() | ||
378 | + taskLevelRepo := factory.CreateTaskLevelRepository(map[string]interface{}{ | ||
379 | + "transactionContext": transactionContext, | ||
380 | + }) | ||
381 | + cnt, _, err := taskLevelRepo.Find(map[string]interface{}{ | ||
382 | + "companyId": companyId, | ||
383 | + "levelName": levelName, | ||
384 | + "limit": 1, | ||
385 | + }) | ||
386 | + if err != nil { | ||
387 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务优先级失败:"+err.Error()) | ||
388 | + } | ||
389 | + if cnt > 0 { | ||
390 | + return nil | ||
391 | + } | ||
392 | + newTaskLevel := domain.TaskLevel{ | ||
393 | + Id: 0, | ||
394 | + LevelName: levelName, | ||
395 | + CompanyId: companyId, | ||
396 | + } | ||
397 | + err = taskLevelRepo.Save(&newTaskLevel) | ||
398 | + if err != nil { | ||
399 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务优先级失败:"+err.Error()) | ||
400 | + } | ||
401 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
402 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
403 | + } | ||
404 | + return nil | ||
405 | +} | ||
406 | + | ||
357 | // 获取任务详情 | 407 | // 获取任务详情 |
358 | func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.TaskInfoAdapter, error) { | 408 | func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.TaskInfoAdapter, error) { |
359 | transactionContext, err := factory.CreateTransactionContext(nil) | 409 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -1471,3 +1521,37 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s | @@ -1471,3 +1521,37 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s | ||
1471 | } | 1521 | } |
1472 | return result, nil | 1522 | return result, nil |
1473 | } | 1523 | } |
1524 | + | ||
1525 | +func (srv TaskService) ListTaskLevel(companyId int) (map[string]interface{}, error) { | ||
1526 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
1527 | + if err != nil { | ||
1528 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
1529 | + } | ||
1530 | + if err := transactionContext.StartTransaction(); err != nil { | ||
1531 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
1532 | + } | ||
1533 | + defer func() { | ||
1534 | + _ = transactionContext.RollbackTransaction() | ||
1535 | + }() | ||
1536 | + taskLevelRepo := factory.CreateTaskLevelRepository(map[string]interface{}{ | ||
1537 | + "transactionContext": transactionContext, | ||
1538 | + }) | ||
1539 | + _, taskLevelList, err := taskLevelRepo.Find(map[string]interface{}{ | ||
1540 | + "companyId": companyId, | ||
1541 | + }) | ||
1542 | + if err != nil { | ||
1543 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务优先级失败:"+err.Error()) | ||
1544 | + } | ||
1545 | + | ||
1546 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
1547 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
1548 | + } | ||
1549 | + | ||
1550 | + taskLevelAll := []*domain.TaskLevel{} | ||
1551 | + taskLevelAll = append(taskLevelAll, domain.DefaultTaskLevel()...) | ||
1552 | + taskLevelAll = append(taskLevelAll, taskLevelList...) | ||
1553 | + result := map[string]interface{}{ | ||
1554 | + "list": taskLevelAll, | ||
1555 | + } | ||
1556 | + return result, nil | ||
1557 | +} |
pkg/domain/task_level.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// 任务有优先级 | ||
4 | +type TaskLevel struct { | ||
5 | + Id int `json:"id"` | ||
6 | + LevelName string `json:"levelName"` | ||
7 | + CompanyId int `json:"companyId"` | ||
8 | +} | ||
9 | + | ||
10 | +type TaskLevelRepository interface { | ||
11 | + Save(t *TaskLevel) error | ||
12 | + // Remove(t *TaskLevel) (*TaskLevel, error) | ||
13 | + // FindOne(queryOptions map[string]interface{}) (*TaskLevel, error) | ||
14 | + Find(queryOptions map[string]interface{}) (int, []*TaskLevel, error) | ||
15 | +} | ||
16 | + | ||
17 | +func DefaultTaskLevel() []*TaskLevel { | ||
18 | + return []*TaskLevel{ | ||
19 | + { | ||
20 | + Id: 0, | ||
21 | + LevelName: "战略任务", | ||
22 | + CompanyId: 0, | ||
23 | + }, | ||
24 | + { | ||
25 | + Id: 0, | ||
26 | + LevelName: "重点任务", | ||
27 | + CompanyId: 0, | ||
28 | + }, | ||
29 | + { | ||
30 | + Id: 0, | ||
31 | + LevelName: "常规任务", | ||
32 | + CompanyId: 0, | ||
33 | + }, | ||
34 | + } | ||
35 | +} |
@@ -595,7 +595,7 @@ type TaskData4 struct { | @@ -595,7 +595,7 @@ type TaskData4 struct { | ||
595 | LeaderId int `pg:"leader_id"` | 595 | LeaderId int `pg:"leader_id"` |
596 | } | 596 | } |
597 | 597 | ||
598 | -// TaskStageAnomalyAll 获取所有异常的里程碑任务 | 598 | +// TaskStageAnomalyAll 获取所有异常的里程碑任务, |
599 | func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) { | 599 | func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) { |
600 | sqlStr := `select distinct | 600 | sqlStr := `select distinct |
601 | task.id as task_id, | 601 | task.id as task_id, |
@@ -56,6 +56,7 @@ func init() { | @@ -56,6 +56,7 @@ func init() { | ||
56 | &models.TaskStage{}, | 56 | &models.TaskStage{}, |
57 | &models.TaskIgnore{}, | 57 | &models.TaskIgnore{}, |
58 | &models.TaskRecord{}, | 58 | &models.TaskRecord{}, |
59 | + &models.TaskLevel{}, | ||
59 | } | 60 | } |
60 | for _, model := range tables { | 61 | for _, model := range tables { |
61 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | 62 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ |
pkg/infrastructure/pg/models/task_level.go
0 → 100644
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
7 | +) | ||
8 | + | ||
9 | +//任务 | ||
10 | + | ||
11 | +type TaskLevelRepository struct { | ||
12 | + transactionContext *pgTransaction.TransactionContext | ||
13 | +} | ||
14 | + | ||
15 | +var _ domain.TaskLevelRepository = (*TaskLevelRepository)(nil) | ||
16 | + | ||
17 | +func NewTaskLevelRepository(transactionContext *pgTransaction.TransactionContext) *TaskLevelRepository { | ||
18 | + return &TaskLevelRepository{transactionContext: transactionContext} | ||
19 | +} | ||
20 | + | ||
21 | +func (repo *TaskLevelRepository) TransformToDomain(d *models.TaskLevel) *domain.TaskLevel { | ||
22 | + return &domain.TaskLevel{ | ||
23 | + Id: d.Id, | ||
24 | + LevelName: d.LevelName, | ||
25 | + CompanyId: d.CompanyId, | ||
26 | + } | ||
27 | +} | ||
28 | + | ||
29 | +func (repo *TaskLevelRepository) Save(param *domain.TaskLevel) error { | ||
30 | + | ||
31 | + m := models.TaskLevel{ | ||
32 | + Id: param.Id, | ||
33 | + LevelName: param.LevelName, | ||
34 | + CompanyId: param.CompanyId, | ||
35 | + } | ||
36 | + db := repo.transactionContext.PgTx | ||
37 | + if m.Id == 0 { | ||
38 | + _, err := db.Model(&m).Insert() | ||
39 | + if err != nil { | ||
40 | + return err | ||
41 | + } | ||
42 | + } else { | ||
43 | + _, err := db.Model(&m).WherePK().Update() | ||
44 | + if err != nil { | ||
45 | + return err | ||
46 | + } | ||
47 | + } | ||
48 | + param.Id = m.Id | ||
49 | + return nil | ||
50 | +} | ||
51 | + | ||
52 | +func (repo *TaskLevelRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskLevel, error) { | ||
53 | + tx := repo.transactionContext.PgTx | ||
54 | + var m []*models.TaskLevel | ||
55 | + query := tx.Model(&m) | ||
56 | + if v, ok := queryOptions["companyId"]; ok { | ||
57 | + query.Where("company_id=?", v) | ||
58 | + } | ||
59 | + if v, ok := queryOptions["levelName"]; ok { | ||
60 | + query.Where("level_name=?", v) | ||
61 | + } | ||
62 | + query.Order("id desc") | ||
63 | + count, err := query.SelectAndCount() | ||
64 | + if err != nil { | ||
65 | + return 0, nil, err | ||
66 | + } | ||
67 | + var datas []*domain.TaskLevel | ||
68 | + for _, v := range m { | ||
69 | + d := repo.TransformToDomain(v) | ||
70 | + datas = append(datas, d) | ||
71 | + } | ||
72 | + return count, datas, nil | ||
73 | +} |
@@ -39,7 +39,8 @@ func (c *TaskController) UpdateTask() { | @@ -39,7 +39,8 @@ func (c *TaskController) UpdateTask() { | ||
39 | c.Response(nil, e) | 39 | c.Response(nil, e) |
40 | return | 40 | return |
41 | } | 41 | } |
42 | - | 42 | + userReq := middlewares.GetUser(c.Ctx) |
43 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
43 | data, err := srv.UpdateTask(paramReq) | 44 | data, err := srv.UpdateTask(paramReq) |
44 | c.Response(data, err) | 45 | c.Response(data, err) |
45 | } | 46 | } |
@@ -189,3 +190,11 @@ func (c *TaskController) SelectCondition() { | @@ -189,3 +190,11 @@ func (c *TaskController) SelectCondition() { | ||
189 | data, err := srv.ConditionForListTask2(paramReq) | 190 | data, err := srv.ConditionForListTask2(paramReq) |
190 | c.Response(data, err) | 191 | c.Response(data, err) |
191 | } | 192 | } |
193 | + | ||
194 | +func (c *TaskController) LevelList() { | ||
195 | + srv := service.NewTaskService() | ||
196 | + userReq := middlewares.GetUser(c.Ctx) | ||
197 | + companyId := int(userReq.CompanyId) | ||
198 | + data, err := srv.ListTaskLevel(companyId) | ||
199 | + c.Response(data, err) | ||
200 | +} |
@@ -17,6 +17,7 @@ func init() { | @@ -17,6 +17,7 @@ func init() { | ||
17 | web.NSCtrlPost("/run", (*controllers.TaskController).RunTask), | 17 | web.NSCtrlPost("/run", (*controllers.TaskController).RunTask), |
18 | web.NSCtrlPost("/stop", (*controllers.TaskController).StopTask), | 18 | web.NSCtrlPost("/stop", (*controllers.TaskController).StopTask), |
19 | web.NSCtrlPost("/list", (*controllers.TaskController).ListTask), | 19 | web.NSCtrlPost("/list", (*controllers.TaskController).ListTask), |
20 | + web.NSCtrlGet("/level/list", (*controllers.TaskController).LevelList), | ||
20 | ) | 21 | ) |
21 | web.AddNamespace(taskAdminNS) | 22 | web.AddNamespace(taskAdminNS) |
22 | // 员工绩效模块 | 23 | // 员工绩效模块 |
-
请 注册 或 登录 后发表评论