作者 tangxvhui

日常保存

@@ -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{}
@@ -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,51 @@ func (t TaskService) CancelAttention(param *command.CancelAttentionCommand) erro @@ -590,3 +588,51 @@ 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 + if hrbpFlag == domain.RoleTypeSystem {
  626 + //已hrbp权限获取
  627 + // info.IsHrbp = true
  628 + return nil, nil
  629 + }
  630 + taskDato := dao.NewTaskDao(map[string]interface{}{
  631 + "transactionContext": transactionContext,
  632 + })
  633 + taskDato.ListTaskStageNotHrbp(condition)
  634 + if err := transactionContext.CommitTransaction(); err != nil {
  635 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  636 + }
  637 + return nil, nil
  638 +}
@@ -2,7 +2,9 @@ package dao @@ -2,7 +2,9 @@ package dao
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
5 6
  7 + "github.com/go-pg/pg/v10"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 ) 9 )
8 10
@@ -27,7 +29,7 @@ func (d *TaskDao) catchTaskIdByPermission(userId int) string { @@ -27,7 +29,7 @@ func (d *TaskDao) catchTaskIdByPermission(userId int) string {
27 ( 29 (
28 select "user".id,"user".parent_id 30 select "user".id,"user".parent_id
29 from "user" 31 from "user"
30 - where company_id =233 and "user".id=%d 32 + where "user".id=%d
31 ) 33 )
32 union 34 union
33 ( 35 (
@@ -67,11 +69,28 @@ type ListTaskCondition struct { @@ -67,11 +69,28 @@ type ListTaskCondition struct {
67 LeaderId string //任务负责人id 69 LeaderId string //任务负责人id
68 } 70 }
69 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 +
70 // 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限 89 // 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限
71 // userid 谁要查看任务数据 90 // userid 谁要查看任务数据
72 // limit 分页 91 // limit 分页
73 // offset 分页 92 // offset 分页
74 -func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) { 93 +func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
75 task1 := d.catchTaskIdByPermission(param.UserId) 94 task1 := d.catchTaskIdByPermission(param.UserId)
76 withSql := task1 + `, 95 withSql := task1 + `,
77 -- 获取的里程碑数据,以及排序 96 -- 获取的里程碑数据,以及排序
@@ -143,11 +162,16 @@ func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) { @@ -143,11 +162,16 @@ func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) {
143 condition = append(condition, param.LevelName) 162 condition = append(condition, param.LevelName)
144 whereSql += ` and t_task_tage_1.level_name like ? ` 163 whereSql += ` and t_task_tage_1.level_name like ? `
145 } 164 }
146 - = withSql 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
147 } 171 }
148 172
149 // 获取任务总数,用于页面展示; 有过滤查看权限 173 // 获取任务总数,用于页面展示; 有过滤查看权限
150 -func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) { 174 +func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) (int, error) {
151 task1 := d.catchTaskIdByPermission(param.UserId) 175 task1 := d.catchTaskIdByPermission(param.UserId)
152 withSql := task1 + `select count(*) from task 176 withSql := task1 + `select count(*) from task
153 join t_task_1 on task.id =t_task_1.id 177 join t_task_1 on task.id =t_task_1.id
@@ -170,6 +194,127 @@ func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) { @@ -170,6 +194,127 @@ func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) {
170 whereSql += ` and task.level_name like ? ` 194 whereSql += ` and task.level_name like ? `
171 } 195 }
172 sqlStr := withSql + whereSql 196 sqlStr := withSql + whereSql
173 - _ = sqlStr 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
174 } 320 }
175 -、、'