作者 郑周

Merge branch 'dev-tangxvhui' into dev-zhengzhou

@@ -7,7 +7,7 @@ type TaskInfoAdapter struct { @@ -7,7 +7,7 @@ type TaskInfoAdapter struct {
7 LeaderId int64 `json:"leaderId,string"` // 7 LeaderId int64 `json:"leaderId,string"` //
8 Leader UserData `json:"leader"` // 任务负责人 8 Leader UserData `json:"leader"` // 任务负责人
9 Status int `json:"status"` // 任务的状态 9 Status int `json:"status"` // 任务的状态
10 - StatusDescript string `json:"statusDescript"` // 10 + StatusDescription string `json:"statusDescription"` //
11 Level int `json:"level"` // 优先级,值越小优先级越高 11 Level int `json:"level"` // 优先级,值越小优先级越高
12 LevalName string `json:"levalName"` // 优先级名称 12 LevalName string `json:"levalName"` // 优先级名称
13 RelatedUserId []string `json:"relatedUserId"` // 相关的员工id 13 RelatedUserId []string `json:"relatedUserId"` // 相关的员工id
@@ -24,7 +24,7 @@ type UserData struct { @@ -24,7 +24,7 @@ type UserData struct {
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"` //里程碑名称 26 Name string `json:"name"` //里程碑名称
27 - StatusDescript string `json:"statusDescript"` //里程碑的完成情况 27 + StatusDescription string `json:"statusDescription"` //里程碑的完成情况
28 Status int `json:"status"` //里程碑状态 28 Status int `json:"status"` //里程碑状态
29 SortBy int `json:"sortBy"` 29 SortBy int `json:"sortBy"`
30 PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02 30 PlanCompletedAt string `json:"planCompletedAt"` //计划完成时间, 例:2006-01-02
@@ -13,4 +13,5 @@ type TaskItem struct { @@ -13,4 +13,5 @@ type TaskItem struct {
13 StageC TaskStage `json:"stageC"` // 里程碑3 13 StageC TaskStage `json:"stageC"` // 里程碑3
14 StageD TaskStage `json:"stageD"` // 里程碑4 14 StageD TaskStage `json:"stageD"` // 里程碑4
15 StageE TaskStage `json:"stageE"` // 里程碑5 15 StageE TaskStage `json:"stageE"` // 里程碑5
  16 + UpdatedAt string `json:"updatedAt"` //
16 } 17 }
  1 +package command
  2 +
  3 +type SearchTaskCommand struct {
  4 + UserId int `json:"-"` //谁要查看任务数据
  5 + CompanyId int `json:"-"`
  6 + PageNumber int `json:"pageNumber"` //分页
  7 + PageSize int `json:"pageSize"` //分页
  8 + TaskName string `json:"taskName"` //任务名称
  9 + LevelName string `json:"levelName"` //优先级
  10 + OnlyMy bool `json:"onlyMy"` //只查看我负责的任务
  11 + LeaderId string `json:"leaderId"` //任务负责人id
  12 +}
@@ -7,9 +7,11 @@ import ( @@ -7,9 +7,11 @@ import (
7 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
8 "github.com/linmadan/egglib-go/utils/tool_funs" 8 "github.com/linmadan/egglib-go/utils/tool_funs"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  10 + roleService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/adapter" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/adapter"
11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/command" 12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/command"
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  14 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
13 ) 15 )
14 16
15 type TaskService struct{} 17 type TaskService struct{}
@@ -337,7 +339,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task @@ -337,7 +339,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
337 Name: taskData.Leader.Name, 339 Name: taskData.Leader.Name,
338 }, 340 },
339 Status: int(taskData.Status), 341 Status: int(taskData.Status),
340 - StatusDescript: taskData.StatusDescript(), 342 + StatusDescription: taskData.StatusDescription(),
341 Level: taskData.Level, 343 Level: taskData.Level,
342 LevalName: taskData.LevelName, 344 LevalName: taskData.LevelName,
343 RelatedUserId: []string{}, 345 RelatedUserId: []string{},
@@ -369,7 +371,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task @@ -369,7 +371,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
369 PlanCompletedAt: t1, 371 PlanCompletedAt: t1,
370 RealCompletedAt: t2, 372 RealCompletedAt: t2,
371 SortBy: val.SortBy, 373 SortBy: val.SortBy,
372 - StatusDescript: val.StatusDescript(), 374 + StatusDescription: val.StatusDescription(),
373 Status: int(val.Status), 375 Status: int(val.Status),
374 }) 376 })
375 } 377 }
@@ -531,7 +533,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte @@ -531,7 +533,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte
531 stage := adapter.TaskStage{ 533 stage := adapter.TaskStage{
532 Id: val.Id, 534 Id: val.Id,
533 Name: val.Name, 535 Name: val.Name,
534 - StatusDescript: val.StatusDescript(), 536 + StatusDescription: val.StatusDescription(),
535 Status: int(val.Status), 537 Status: int(val.Status),
536 SortBy: val.SortBy, 538 SortBy: val.SortBy,
537 } 539 }
@@ -556,10 +558,6 @@ func (t TaskService) canUpdateTask(taskData *domain.Task, stageList []*domain.Ta @@ -556,10 +558,6 @@ func (t TaskService) canUpdateTask(taskData *domain.Task, stageList []*domain.Ta
556 return true, nil 558 return true, nil
557 } 559 }
558 560
559 -func (t TaskService) ListTask2() error {  
560 - return nil  
561 -}  
562 -  
563 // CancelAttention 用户取消关注某个任务 561 // CancelAttention 用户取消关注某个任务
564 func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) error { 562 func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) error {
565 transactionContext, err := factory.CreateTransactionContext(nil) 563 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -590,3 +588,57 @@ func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) erro @@ -590,3 +588,57 @@ func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) erro
590 } 588 }
591 return nil 589 return nil
592 } 590 }
  591 +
  592 +// 员工绩效-任务管理-列表
  593 +func (t TaskService) ListTask2(param command.SearchTaskCommand) (map[string]interface{}, error) {
  594 + transactionContext, err := factory.CreateTransactionContext(nil)
  595 + if err != nil {
  596 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  597 + }
  598 + if err := transactionContext.StartTransaction(); err != nil {
  599 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  600 + }
  601 + defer func() {
  602 + _ = transactionContext.RollbackTransaction()
  603 + }()
  604 + hrbpFlag, err := roleService.GetHrBp(transactionContext, int(param.CompanyId), int(param.UserId))
  605 + if err != nil {
  606 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息"+err.Error())
  607 + }
  608 + var limit = 20
  609 + var offset = 0
  610 + if param.PageSize > 0 {
  611 + limit = param.PageSize
  612 + if param.PageNumber > 0 {
  613 + offset = (param.PageNumber - 1) * param.PageSize
  614 + }
  615 + }
  616 + condition := dao.ListTaskCondition{
  617 + Limit: limit,
  618 + Offset: offset,
  619 + UserId: param.UserId,
  620 + TaskName: param.TaskName,
  621 + LevelName: param.LevelName,
  622 + OnlyMy: param.OnlyMy,
  623 + LeaderId: param.LeaderId,
  624 + }
  625 +
  626 + if hrbpFlag == domain.RoleTypeSystem {
  627 + //已hrbp权限获取
  628 + // info.IsHrbp = true
  629 + return nil, nil
  630 + }
  631 + taskDato := dao.NewTaskDao(map[string]interface{}{
  632 + "transactionContext": transactionContext,
  633 + })
  634 + taskDato.ListTaskStageNotHrbp(condition)
  635 + if err := transactionContext.CommitTransaction(); err != nil {
  636 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  637 + }
  638 + return nil, nil
  639 +}
  640 +
  641 +// 以hrbp角色权限获取任务列表
  642 +func (t TaskService) ListTask2ForHrbp(param command.SearchTaskCommand) (map[string]interface{}, error) {
  643 + return nil, nil
  644 +}
@@ -36,6 +36,7 @@ type TaskLeader struct { @@ -36,6 +36,7 @@ type TaskLeader struct {
36 } 36 }
37 37
38 // 设置任务的优先级 38 // 设置任务的优先级
  39 +// 值越小优先级越高,不是预定义的任务优先级,排在最后
39 func (t *Task) ApplyLevelName(name string) { 40 func (t *Task) ApplyLevelName(name string) {
40 t.LevelName = name 41 t.LevelName = name
41 switch name { 42 switch name {
@@ -51,7 +52,7 @@ func (t *Task) ApplyLevelName(name string) { @@ -51,7 +52,7 @@ func (t *Task) ApplyLevelName(name string) {
51 } 52 }
52 53
53 // StatusDescript 54 // StatusDescript
54 -func (t *Task) StatusDescript() string { 55 +func (t *Task) StatusDescription() string {
55 switch t.Status { 56 switch t.Status {
56 case TaskWait: 57 case TaskWait:
57 return "待启动" 58 return "待启动"
@@ -6,8 +6,8 @@ type TaskStageState int @@ -6,8 +6,8 @@ type TaskStageState int
6 6
7 const ( 7 const (
8 TaskStageUncompleted TaskStageState = 1 //里程碑未完成 8 TaskStageUncompleted TaskStageState = 1 //里程碑未完成
9 - TaskStageCompletedOverdue TaskStageState = 2 //里程碑逾期完成  
10 - TaskStageCompleted TaskStageState = 3 //里程碑完成 9 + // TaskStageCompletedOverdue TaskStageState = 2 //里程碑逾期完成
  10 + TaskStageCompleted TaskStageState = 2 //里程碑完成
11 11
12 ) 12 )
13 13
@@ -32,7 +32,7 @@ type TaskStageRepository interface { @@ -32,7 +32,7 @@ type TaskStageRepository interface {
32 } 32 }
33 33
34 // 描述里程碑完成情况 34 // 描述里程碑完成情况
35 -func (t TaskStage) StatusDescript() string { 35 +func (t TaskStage) StatusDescription() 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
@@ -45,10 +45,11 @@ func (t TaskStage) StatusDescript() string { @@ -45,10 +45,11 @@ func (t TaskStage) StatusDescript() string {
45 str = "未完成" 45 str = "未完成"
46 } 46 }
47 case TaskStageCompleted: 47 case TaskStageCompleted:
  48 + if t.PlanCompletedAt >= t.RealCompletedAt {
48 str = "已完成" 49 str = "已完成"
49 - case TaskStageCompletedOverdue: 50 + } else {
50 str = "逾期完成" 51 str = "逾期完成"
51 } 52 }
52 - 53 + }
53 return str 54 return str
54 } 55 }
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/go-pg/pg/v10"
  8 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  9 +)
  10 +
  11 +type TaskDao struct {
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +func NewTaskDao(options map[string]interface{}) *TaskDao {
  16 + var transactionContext *pgTransaction.TransactionContext
  17 + if value, ok := options["transactionContext"]; ok {
  18 + transactionContext = value.(*pgTransaction.TransactionContext)
  19 + }
  20 + return &TaskDao{
  21 + transactionContext: transactionContext,
  22 + }
  23 +}
  24 +
  25 +func (d *TaskDao) catchTaskIdByPermission(userId int) string {
  26 + sqlStr := `with
  27 + -- 人员自身以及全下级
  28 + recursive t_user as (
  29 + (
  30 + select "user".id,"user".parent_id
  31 + from "user"
  32 + where "user".id=%d
  33 + )
  34 + union
  35 + (
  36 + select "child_user".id,"child_user".parent_id
  37 + from "user" as "child_user"
  38 + join t_user as "parent_user" on "parent_user".id="child_user".parent_id
  39 + )
  40 + ),
  41 + -- 根据任务负责人和相关人员查询
  42 + t_task_0 as (
  43 + (select task.id from task
  44 + join t_user on task.leader ->>'id'=t_user.id::text
  45 + )
  46 + union
  47 + (select task.id from task where task.related_user@>'[%d]')
  48 + ),
  49 + t_task_ignore as (
  50 + select * from task_ignore where task_ignore.user_id =%d
  51 + ),
  52 + -- 过滤取消关注的
  53 + t_task_1 as (
  54 + select t_task_0.id
  55 + from t_task_0
  56 + left join t_task_ignore on t_task_0.id=t_task_ignore.task_id
  57 + where t_task_ignore.id isnull
  58 + )`
  59 + return fmt.Sprintf(sqlStr, userId, userId, userId)
  60 +}
  61 +
  62 +type ListTaskCondition struct {
  63 + Limit int //分页
  64 + Offset int //分页
  65 + UserId int //谁要查看任务数据
  66 + TaskName string //任务名称
  67 + LevelName string //优先级
  68 + OnlyMy bool //只查看我负责的任务
  69 + LeaderId string //任务负责人id
  70 +}
  71 +
  72 +// 任务和里程碑列表
  73 +type ListTaskStage struct {
  74 + TaskId string `pg:"task_id"`
  75 + TaskName string `pg:"task_name"`
  76 + LeaderName string `pg:"leader_name"`
  77 + LeaderId string `pg:"leader_id"`
  78 + LevelName string `pg:"level_name"`
  79 + Level int `pg:"level"`
  80 + Anomaly int `pg:"anomaly"`
  81 + UpdatedAt time.Time `pg:"updated_at"`
  82 + CreatedAt time.Time `pg:"created_at"`
  83 + StageName string `pg:"stage_name"`
  84 + StageSortBy int `pg:"stage_sort_by"`
  85 + StageStatus int `pg:"stage_status"`
  86 + PlanCompletedAt int `pg:"plan_completed_at"`
  87 +}
  88 +
  89 +// 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限
  90 +// userid 谁要查看任务数据
  91 +// limit 分页
  92 +// offset 分页
  93 +func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
  94 + task1 := d.catchTaskIdByPermission(param.UserId)
  95 + withSql := task1 + `,
  96 + -- 获取的里程碑数据,以及排序
  97 + t_task_tage_1 as(
  98 + select
  99 + task.id as task_id,
  100 + task."name" as task_name,
  101 + task.leader ->>'name' as leader_name,
  102 + task.leader ->>'id' as leader_id,
  103 + task.level_name ,
  104 + task.anomaly ,
  105 + task.updated_at ,
  106 + task.created_at ,
  107 + task."level" ,
  108 + task_stage."name" as stage_name,
  109 + task_stage.sort_by as stage_sort_by,
  110 + task_stage.status as stage_status,
  111 + task_stage.plan_completed_at,
  112 + (case
  113 + when task_stage.real_completed_at =0
  114 + then task_stage.plan_completed_at - floor( extract(epoch from now()))
  115 + else task_stage.plan_completed_at - task_stage.real_completed_at
  116 + end) as diff_time
  117 + from task
  118 + join t_task_1 on task.id=t_task_1.id
  119 + join task_stage on task.id =task_stage.task_id
  120 + where 1=1
  121 + order by diff_time,task."level",task.created_at
  122 + ),
  123 + -- 按任务数据分页获取
  124 + t_task_page as (
  125 + select distinct t_task_tage_1.task_id
  126 + from t_task_tage_1
  127 + where 1=1
  128 + %s
  129 + limit ? offset ?
  130 + )
  131 + select
  132 + t_task_tage_1.task_id,
  133 + t_task_tage_1.task_name,
  134 + t_task_tage_1.leader_name,
  135 + t_task_tage_1.level_name ,
  136 + t_task_tage_1.anomaly ,
  137 + t_task_tage_1.updated_at ,
  138 + t_task_tage_1.created_at ,
  139 + t_task_tage_1."level" ,
  140 + t_task_tage_1.plan_completed_at,
  141 + t_task_tage_1.stage_name,
  142 + t_task_tage_1.stage_sort_by,
  143 + t_task_tage_1.stage_status,
  144 + from t_task_tage_1
  145 + where t_task_tage_1.task_id in(
  146 + select t_task_page.task_id from t_task_page
  147 + )`
  148 + condition := []interface{}{}
  149 + whereSql := ``
  150 + if param.OnlyMy {
  151 + condition = append(condition, param.UserId)
  152 + whereSql += ` and t_task_tage_1.leader_id = '?' `
  153 + } else if param.LeaderId != "" {
  154 + condition = append(condition, param.LeaderId)
  155 + whereSql += ` and t_task_tage_1.leader_id = ? `
  156 + }
  157 + if len(param.TaskName) > 0 {
  158 + condition = append(condition, param.TaskName)
  159 + whereSql += ` and t_task_tage_1.task_name like ? `
  160 + }
  161 + if len(param.LevelName) > 0 {
  162 + condition = append(condition, param.LevelName)
  163 + whereSql += ` and t_task_tage_1.level_name like ? `
  164 + }
  165 + condition = append(condition, param.Limit, param.Offset)
  166 + sqlStr := fmt.Sprintf(withSql, whereSql)
  167 + result := []ListTaskStage{}
  168 + tx := d.transactionContext.PgTx
  169 + _, err := tx.Query(&result, sqlStr, condition...)
  170 + return result, err
  171 +}
  172 +
  173 +// 获取任务总数,用于页面展示; 有过滤查看权限
  174 +func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) (int, error) {
  175 + task1 := d.catchTaskIdByPermission(param.UserId)
  176 + withSql := task1 + `select count(*) from task
  177 + join t_task_1 on task.id =t_task_1.id
  178 + where 1=1 `
  179 + condition := []interface{}{}
  180 + whereSql := ``
  181 + if param.OnlyMy {
  182 + condition = append(condition, param.UserId)
  183 + whereSql += ` and task.leader ->>'id' = '?' `
  184 + } else if param.LeaderId != "" {
  185 + condition = append(condition, param.LeaderId)
  186 + whereSql += ` and task.leader ->>'id' = ? `
  187 + }
  188 + if len(param.TaskName) > 0 {
  189 + condition = append(condition, param.TaskName)
  190 + whereSql += ` and task.name like ? `
  191 + }
  192 + if len(param.LevelName) > 0 {
  193 + condition = append(condition, param.LevelName)
  194 + whereSql += ` and task.level_name like ? `
  195 + }
  196 + sqlStr := withSql + whereSql
  197 + tx := d.transactionContext.PgTx
  198 + var cnt int
  199 + _, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
  200 + return cnt, err
  201 +}
  202 +
  203 +// 获取任务以及里程碑列表,用于页面展示; 无过滤查看权限
  204 +// userid 谁要查看任务数据
  205 +// limit 分页
  206 +// offset 分页
  207 +func (d *TaskDao) ListTaskStageByHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
  208 + withSql := `with
  209 + t_task_ignore as (
  210 + select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
  211 + ),
  212 + -- 获取的里程碑数据,以及排序
  213 + t_task_tage_1 as(
  214 + select
  215 + task.id as task_id,
  216 + task."name" as task_name,
  217 + task.leader ->>'name' as leader_name,
  218 + task.leader ->>'id' as leader_id,
  219 + task.level_name ,
  220 + task.anomaly ,
  221 + task.updated_at ,
  222 + task.created_at ,
  223 + task."level" ,
  224 + task_stage."name" as stage_name,
  225 + task_stage.sort_by as stage_sort_by,
  226 + task_stage.status as stage_status,
  227 + task_stage.plan_completed_at,
  228 + (case
  229 + when task_stage.real_completed_at =0
  230 + then task_stage.plan_completed_at - floor( extract(epoch from now()))
  231 + else task_stage.plan_completed_at - task_stage.real_completed_at
  232 + end) as diff_time
  233 + from task
  234 + join task_stage on task.id =task_stage.task_id
  235 + where 1=1
  236 + order by diff_time,task."level",task.created_at
  237 + ),
  238 + -- 按任务数据分页获取
  239 + t_task_page as (
  240 + select distinct t_task_tage_1.task_id
  241 + from t_task_tage_1
  242 + left join t_task_ignore on t_task_ignore.task_id=t_task_tage_1.task_id
  243 + where t_task_ignore.id isnull
  244 + %s
  245 + limit ? offset ?
  246 + )
  247 + select
  248 + t_task_tage_1.task_id,
  249 + t_task_tage_1.task_name,
  250 + t_task_tage_1.leader_name,
  251 + t_task_tage_1.level_name ,
  252 + t_task_tage_1.anomaly ,
  253 + t_task_tage_1.updated_at ,
  254 + t_task_tage_1.created_at ,
  255 + t_task_tage_1."level" ,
  256 + t_task_tage_1.plan_completed_at,
  257 + t_task_tage_1.stage_name,
  258 + t_task_tage_1.stage_sort_by,
  259 + t_task_tage_1.stage_status,
  260 + from t_task_tage_1
  261 + where t_task_tage_1.task_id in(
  262 + select t_task_page.task_id from t_task_page
  263 + )`
  264 + condition := []interface{}{}
  265 + whereSql := ``
  266 + if param.OnlyMy {
  267 + condition = append(condition, param.UserId)
  268 + whereSql += ` and task.leader ->>'id' = '?' `
  269 + } else if param.LeaderId != "" {
  270 + condition = append(condition, param.LeaderId)
  271 + whereSql += ` and task.leader ->>'id' = ? `
  272 + }
  273 + if len(param.TaskName) > 0 {
  274 + condition = append(condition, param.TaskName)
  275 + whereSql += ` and task.name like ? `
  276 + }
  277 + if len(param.LevelName) > 0 {
  278 + condition = append(condition, param.LevelName)
  279 + whereSql += ` and task.level_name like ? `
  280 + }
  281 + condition = append(condition, param.Limit, param.Offset)
  282 + sqlStr := fmt.Sprintf(withSql, whereSql)
  283 + result := []ListTaskStage{}
  284 + tx := d.transactionContext.PgTx
  285 + _, err := tx.Query(&result, sqlStr, condition...)
  286 + return result, err
  287 +}
  288 +
  289 +// 获取任务总数,用于页面展示; 无过滤查看权限
  290 +func (d *TaskDao) CountTaskStageByHrbp(param ListTaskCondition) (int, error) {
  291 +
  292 + withSql := `with
  293 + t_task_ignore as (
  294 + select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
  295 + )select count(*) from task
  296 + left join t_task_ignore on t_task_ignore.task_id=task.id
  297 + where 1=1 `
  298 + condition := []interface{}{}
  299 + whereSql := ``
  300 + if param.OnlyMy {
  301 + condition = append(condition, param.UserId)
  302 + whereSql += ` and task.leader ->>'id' = '?' `
  303 + } else if param.LeaderId != "" {
  304 + condition = append(condition, param.LeaderId)
  305 + whereSql += ` and task.leader ->>'id' = ? `
  306 + }
  307 + if len(param.TaskName) > 0 {
  308 + condition = append(condition, param.TaskName)
  309 + whereSql += ` and task.name like ? `
  310 + }
  311 + if len(param.LevelName) > 0 {
  312 + condition = append(condition, param.LevelName)
  313 + whereSql += ` and task.level_name like ? `
  314 + }
  315 + sqlStr := withSql + whereSql
  316 + tx := d.transactionContext.PgTx
  317 + var cnt int
  318 + _, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
  319 + return cnt, err
  320 +}