作者 tangxvhui

更新

@@ -628,20 +628,29 @@ func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]i @@ -628,20 +628,29 @@ func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]i
628 LeaderId: param.LeaderId, 628 LeaderId: param.LeaderId,
629 } 629 }
630 630
631 - taskDato := dao.NewTaskDao(map[string]interface{}{ 631 + taskDao := dao.NewTaskDao(map[string]interface{}{
632 "transactionContext": transactionContext, 632 "transactionContext": transactionContext,
633 }) 633 })
634 - tasklistData, err := taskDato.ListTaskStageNotHrbp(condition) 634 + tasklistData, err := taskDao.ListTaskStageNotHrbp(condition)
635 if err != nil { 635 if err != nil {
636 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error()) 636 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
637 } 637 }
638 - taskCount, err := taskDato.CountTaskStageNotHrbp(condition) 638 + taskCount, err := taskDao.CountTaskStageNotHrbp(condition)
639 if err != nil { 639 if err != nil {
640 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error()) 640 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
641 } 641 }
  642 + taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyNotHrbp(condition)
  643 + if err != nil {
  644 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
  645 + }
  646 + taskAnomalyCnt, err := taskDao.CountTaskAnomalyNotHrbp(condition)
  647 + if err != nil {
  648 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
  649 + }
642 if err := transactionContext.CommitTransaction(); err != nil { 650 if err := transactionContext.CommitTransaction(); err != nil {
643 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 651 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
644 } 652 }
  653 +
645 taskResult := []*adapter.TaskItem{} 654 taskResult := []*adapter.TaskItem{}
646 taskMapResult := map[int]*adapter.TaskItem{} 655 taskMapResult := map[int]*adapter.TaskItem{}
647 for _, val := range tasklistData { 656 for _, val := range tasklistData {
@@ -690,6 +699,8 @@ func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]i @@ -690,6 +699,8 @@ func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]i
690 } 699 }
691 } 700 }
692 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult) 701 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
  702 + result["taskStageAnomaly"] = taskStageAnomalyCnt
  703 + result["taskAnomalyCnt"] = taskAnomalyCnt
693 return result, nil 704 return result, nil
694 } 705 }
695 706
@@ -723,17 +734,25 @@ func (srv TaskService) listTask2ForHrbp(param *command.SearchTaskCommand) (map[s @@ -723,17 +734,25 @@ func (srv TaskService) listTask2ForHrbp(param *command.SearchTaskCommand) (map[s
723 defer func() { 734 defer func() {
724 _ = transactionContext.RollbackTransaction() 735 _ = transactionContext.RollbackTransaction()
725 }() 736 }()
726 - taskDato := dao.NewTaskDao(map[string]interface{}{ 737 + taskDao := dao.NewTaskDao(map[string]interface{}{
727 "transactionContext": transactionContext, 738 "transactionContext": transactionContext,
728 }) 739 })
729 - tasklistData, err := taskDato.ListTaskStageByHrbp(condition) 740 + tasklistData, err := taskDao.ListTaskStageByHrbp(condition)
730 if err != nil { 741 if err != nil {
731 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error()) 742 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取任务列表"+err.Error())
732 } 743 }
733 - taskCount, err := taskDato.CountTaskStageByHrbp(condition) 744 + taskCount, err := taskDao.CountTaskStageByHrbp(condition)
734 if err != nil { 745 if err != nil {
735 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error()) 746 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务总数"+err.Error())
736 } 747 }
  748 + taskStageAnomalyCnt, err := taskDao.CountTaskStageAnomalyByHrbp(condition)
  749 + if err != nil {
  750 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
  751 + }
  752 + taskAnomalyCnt, err := taskDao.CountTaskAnomalyByHrbp(condition)
  753 + if err != nil {
  754 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务里程碑总数"+err.Error())
  755 + }
737 if err := transactionContext.CommitTransaction(); err != nil { 756 if err := transactionContext.CommitTransaction(); err != nil {
738 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 757 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
739 } 758 }
@@ -785,6 +804,8 @@ func (srv TaskService) listTask2ForHrbp(param *command.SearchTaskCommand) (map[s @@ -785,6 +804,8 @@ func (srv TaskService) listTask2ForHrbp(param *command.SearchTaskCommand) (map[s
785 } 804 }
786 } 805 }
787 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult) 806 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
  807 + result["taskStageAnomaly"] = taskStageAnomalyCnt
  808 + result["taskAnomalyCnt"] = taskAnomalyCnt
788 return result, nil 809 return result, nil
789 } 810 }
790 811
@@ -276,7 +276,7 @@ func (d *TaskDao) ListTaskStageByHrbp(param ListTaskCondition) ([]ListTaskStage, @@ -276,7 +276,7 @@ func (d *TaskDao) ListTaskStageByHrbp(param ListTaskCondition) ([]ListTaskStage,
276 where t_task_tage_1.task_id in( 276 where t_task_tage_1.task_id in(
277 select t_task_page.task_id from t_task_page 277 select t_task_page.task_id from t_task_page
278 )` 278 )`
279 - condition := []interface{}{} 279 + condition := []interface{}{param.UserId}
280 whereSql := `` 280 whereSql := ``
281 if param.OnlyMy { 281 if param.OnlyMy {
282 condition = append(condition, param.UserId) 282 condition = append(condition, param.UserId)
@@ -310,7 +310,7 @@ func (d *TaskDao) CountTaskStageByHrbp(param ListTaskCondition) (int, error) { @@ -310,7 +310,7 @@ func (d *TaskDao) CountTaskStageByHrbp(param ListTaskCondition) (int, error) {
310 )select count(*) from task 310 )select count(*) from task
311 left join t_task_ignore on t_task_ignore.task_id=task.id 311 left join t_task_ignore on t_task_ignore.task_id=task.id
312 where 1=1 ` 312 where 1=1 `
313 - condition := []interface{}{} 313 + condition := []interface{}{param.UserId}
314 whereSql := `` 314 whereSql := ``
315 if param.OnlyMy { 315 if param.OnlyMy {
316 condition = append(condition, param.UserId) 316 condition = append(condition, param.UserId)
@@ -386,7 +386,7 @@ func (d *TaskDao) CountTaskStageAnomalyByHrbp(param ListTaskCondition) (int, err @@ -386,7 +386,7 @@ func (d *TaskDao) CountTaskStageAnomalyByHrbp(param ListTaskCondition) (int, err
386 or 386 or
387 (task_stage.real_completed_at=0 and task_stage.plan_completed_at<extract(epoch from now())) 387 (task_stage.real_completed_at=0 and task_stage.plan_completed_at<extract(epoch from now()))
388 ) ` 388 ) `
389 - condition := []interface{}{} 389 + condition := []interface{}{param.UserId}
390 whereSql := `` 390 whereSql := ``
391 if param.OnlyMy { 391 if param.OnlyMy {
392 condition = append(condition, param.UserId) 392 condition = append(condition, param.UserId)
@@ -456,3 +456,68 @@ func (d *TaskDao) TaskAnomaly(leaderId []string, anomaly int) ([]TaskStageData, @@ -456,3 +456,68 @@ func (d *TaskDao) TaskAnomaly(leaderId []string, anomaly int) ([]TaskStageData,
456 _, err := tx.Query(&result, sqlStr, anomaly, pg.In(leaderId)) 456 _, err := tx.Query(&result, sqlStr, anomaly, pg.In(leaderId))
457 return result, err 457 return result, err
458 } 458 }
  459 +
  460 +// 统计任务异常的数量,以非hrbp角色统计
  461 +func (d *TaskDao) CountTaskAnomalyNotHrbp(param ListTaskCondition) (int, error) {
  462 + task1 := d.catchTaskIdByPermission(param.UserId)
  463 + withSql := task1 + ` select count(*)
  464 + from task
  465 + join t_task_1 on task.id =t_task_1.id
  466 + where 1=1
  467 + and task.anomaly>1 `
  468 + condition := []interface{}{}
  469 + whereSql := ``
  470 + if param.OnlyMy {
  471 + condition = append(condition, param.UserId)
  472 + whereSql += ` and task.leader ->>'id' = '?' `
  473 + } else if param.LeaderId != "" {
  474 + condition = append(condition, param.LeaderId)
  475 + whereSql += ` and task.leader ->>'id' = ? `
  476 + }
  477 + if len(param.TaskName) > 0 {
  478 + condition = append(condition, param.TaskName)
  479 + whereSql += ` and task.name like ? `
  480 + }
  481 + if len(param.LevelName) > 0 {
  482 + condition = append(condition, param.LevelName)
  483 + whereSql += ` and task.level_name like ? `
  484 + }
  485 + sqlStr := withSql + whereSql
  486 + tx := d.transactionContext.PgTx
  487 + var cnt int
  488 + _, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
  489 + return cnt, err
  490 +}
  491 +
  492 +// 统计任务异常的数量,以hrbp角色统计
  493 +func (d *TaskDao) CountTaskAnomalyByHrbp(param ListTaskCondition) (int, error) {
  494 + withSql := `with
  495 + t_task_ignore as (
  496 + select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
  497 + )select count(*)
  498 + from task
  499 + left join t_task_ignore on t_task_ignore.task_id=task.id
  500 + where 1=1 and task.anomaly>1 `
  501 + condition := []interface{}{param.UserId}
  502 + whereSql := ``
  503 + if param.OnlyMy {
  504 + condition = append(condition, param.UserId)
  505 + whereSql += ` and task.leader ->>'id' = '?' `
  506 + } else if param.LeaderId != "" {
  507 + condition = append(condition, param.LeaderId)
  508 + whereSql += ` and task.leader ->>'id' = ? `
  509 + }
  510 + if len(param.TaskName) > 0 {
  511 + condition = append(condition, param.TaskName)
  512 + whereSql += ` and task.name like ? `
  513 + }
  514 + if len(param.LevelName) > 0 {
  515 + condition = append(condition, param.LevelName)
  516 + whereSql += ` and task.level_name like ? `
  517 + }
  518 + sqlStr := withSql + whereSql
  519 + tx := d.transactionContext.PgTx
  520 + var cnt int
  521 + _, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
  522 + return cnt, err
  523 +}