...
|
...
|
@@ -2,7 +2,9 @@ package dao |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -27,7 +29,7 @@ func (d *TaskDao) catchTaskIdByPermission(userId int) string { |
|
|
(
|
|
|
select "user".id,"user".parent_id
|
|
|
from "user"
|
|
|
where company_id =233 and "user".id=%d
|
|
|
where "user".id=%d
|
|
|
)
|
|
|
union
|
|
|
(
|
...
|
...
|
@@ -67,11 +69,28 @@ type ListTaskCondition struct { |
|
|
LeaderId string //任务负责人id
|
|
|
}
|
|
|
|
|
|
// 任务和里程碑列表
|
|
|
type ListTaskStage struct {
|
|
|
TaskId string `pg:"task_id"`
|
|
|
TaskName string `pg:"task_name"`
|
|
|
LeaderName string `pg:"leader_name"`
|
|
|
LeaderId string `pg:"leader_id"`
|
|
|
LevelName string `pg:"level_name"`
|
|
|
Level int `pg:"level"`
|
|
|
Anomaly int `pg:"anomaly"`
|
|
|
UpdatedAt time.Time `pg:"updated_at"`
|
|
|
CreatedAt time.Time `pg:"created_at"`
|
|
|
StageName string `pg:"stage_name"`
|
|
|
StageSortBy int `pg:"stage_sort_by"`
|
|
|
StageStatus int `pg:"stage_status"`
|
|
|
PlanCompletedAt int `pg:"plan_completed_at"`
|
|
|
}
|
|
|
|
|
|
// 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限
|
|
|
// userid 谁要查看任务数据
|
|
|
// limit 分页
|
|
|
// offset 分页
|
|
|
func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) {
|
|
|
func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
|
|
|
task1 := d.catchTaskIdByPermission(param.UserId)
|
|
|
withSql := task1 + `,
|
|
|
-- 获取的里程碑数据,以及排序
|
...
|
...
|
@@ -143,11 +162,16 @@ func (d *TaskDao) ListTaskStageNotHrbp(param ListTaskCondition) { |
|
|
condition = append(condition, param.LevelName)
|
|
|
whereSql += ` and t_task_tage_1.level_name like ? `
|
|
|
}
|
|
|
= withSql
|
|
|
condition = append(condition, param.Limit, param.Offset)
|
|
|
sqlStr := fmt.Sprintf(withSql, whereSql)
|
|
|
result := []ListTaskStage{}
|
|
|
tx := d.transactionContext.PgTx
|
|
|
_, err := tx.Query(&result, sqlStr, condition...)
|
|
|
return result, err
|
|
|
}
|
|
|
|
|
|
// 获取任务总数,用于页面展示; 有过滤查看权限
|
|
|
func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) {
|
|
|
func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) (int, error) {
|
|
|
task1 := d.catchTaskIdByPermission(param.UserId)
|
|
|
withSql := task1 + `select count(*) from task
|
|
|
join t_task_1 on task.id =t_task_1.id
|
...
|
...
|
@@ -170,6 +194,127 @@ func (d *TaskDao) CountTaskStageNotHrbp(param ListTaskCondition) { |
|
|
whereSql += ` and task.level_name like ? `
|
|
|
}
|
|
|
sqlStr := withSql + whereSql
|
|
|
_ = sqlStr
|
|
|
tx := d.transactionContext.PgTx
|
|
|
var cnt int
|
|
|
_, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
|
|
|
return cnt, err
|
|
|
}
|
|
|
|
|
|
// 获取任务以及里程碑列表,用于页面展示; 无过滤查看权限
|
|
|
// userid 谁要查看任务数据
|
|
|
// limit 分页
|
|
|
// offset 分页
|
|
|
func (d *TaskDao) ListTaskStageByHrbp(param ListTaskCondition) ([]ListTaskStage, error) {
|
|
|
withSql := `with
|
|
|
t_task_ignore as (
|
|
|
select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
|
|
|
),
|
|
|
-- 获取的里程碑数据,以及排序
|
|
|
t_task_tage_1 as(
|
|
|
select
|
|
|
task.id as task_id,
|
|
|
task."name" as task_name,
|
|
|
task.leader ->>'name' as leader_name,
|
|
|
task.leader ->>'id' as leader_id,
|
|
|
task.level_name ,
|
|
|
task.anomaly ,
|
|
|
task.updated_at ,
|
|
|
task.created_at ,
|
|
|
task."level" ,
|
|
|
task_stage."name" as stage_name,
|
|
|
task_stage.sort_by as stage_sort_by,
|
|
|
task_stage.status as stage_status,
|
|
|
task_stage.plan_completed_at,
|
|
|
(case
|
|
|
when task_stage.real_completed_at =0
|
|
|
then task_stage.plan_completed_at - floor( extract(epoch from now()))
|
|
|
else task_stage.plan_completed_at - task_stage.real_completed_at
|
|
|
end) as diff_time
|
|
|
from task
|
|
|
join task_stage on task.id =task_stage.task_id
|
|
|
where 1=1
|
|
|
order by diff_time,task."level",task.created_at
|
|
|
),
|
|
|
-- 按任务数据分页获取
|
|
|
t_task_page as (
|
|
|
select distinct t_task_tage_1.task_id
|
|
|
from t_task_tage_1
|
|
|
left join t_task_ignore on t_task_ignore.task_id=t_task_tage_1.task_id
|
|
|
where t_task_ignore.id isnull
|
|
|
%s
|
|
|
limit ? offset ?
|
|
|
)
|
|
|
select
|
|
|
t_task_tage_1.task_id,
|
|
|
t_task_tage_1.task_name,
|
|
|
t_task_tage_1.leader_name,
|
|
|
t_task_tage_1.level_name ,
|
|
|
t_task_tage_1.anomaly ,
|
|
|
t_task_tage_1.updated_at ,
|
|
|
t_task_tage_1.created_at ,
|
|
|
t_task_tage_1."level" ,
|
|
|
t_task_tage_1.plan_completed_at,
|
|
|
t_task_tage_1.stage_name,
|
|
|
t_task_tage_1.stage_sort_by,
|
|
|
t_task_tage_1.stage_status,
|
|
|
from t_task_tage_1
|
|
|
where t_task_tage_1.task_id in(
|
|
|
select t_task_page.task_id from t_task_page
|
|
|
)`
|
|
|
condition := []interface{}{}
|
|
|
whereSql := ``
|
|
|
if param.OnlyMy {
|
|
|
condition = append(condition, param.UserId)
|
|
|
whereSql += ` and task.leader ->>'id' = '?' `
|
|
|
} else if param.LeaderId != "" {
|
|
|
condition = append(condition, param.LeaderId)
|
|
|
whereSql += ` and task.leader ->>'id' = ? `
|
|
|
}
|
|
|
if len(param.TaskName) > 0 {
|
|
|
condition = append(condition, param.TaskName)
|
|
|
whereSql += ` and task.name like ? `
|
|
|
}
|
|
|
if len(param.LevelName) > 0 {
|
|
|
condition = append(condition, param.LevelName)
|
|
|
whereSql += ` and task.level_name like ? `
|
|
|
}
|
|
|
condition = append(condition, param.Limit, param.Offset)
|
|
|
sqlStr := fmt.Sprintf(withSql, whereSql)
|
|
|
result := []ListTaskStage{}
|
|
|
tx := d.transactionContext.PgTx
|
|
|
_, err := tx.Query(&result, sqlStr, condition...)
|
|
|
return result, err
|
|
|
}
|
|
|
|
|
|
// 获取任务总数,用于页面展示; 无过滤查看权限
|
|
|
func (d *TaskDao) CountTaskStageByHrbp(param ListTaskCondition) (int, error) {
|
|
|
|
|
|
withSql := `with
|
|
|
t_task_ignore as (
|
|
|
select task_ignore.task_id,task_ignore.id from task_ignore where task_ignore.user_id =?
|
|
|
)select count(*) from task
|
|
|
left join t_task_ignore on t_task_ignore.task_id=task.id
|
|
|
where 1=1 `
|
|
|
condition := []interface{}{}
|
|
|
whereSql := ``
|
|
|
if param.OnlyMy {
|
|
|
condition = append(condition, param.UserId)
|
|
|
whereSql += ` and task.leader ->>'id' = '?' `
|
|
|
} else if param.LeaderId != "" {
|
|
|
condition = append(condition, param.LeaderId)
|
|
|
whereSql += ` and task.leader ->>'id' = ? `
|
|
|
}
|
|
|
if len(param.TaskName) > 0 {
|
|
|
condition = append(condition, param.TaskName)
|
|
|
whereSql += ` and task.name like ? `
|
|
|
}
|
|
|
if len(param.LevelName) > 0 {
|
|
|
condition = append(condition, param.LevelName)
|
|
|
whereSql += ` and task.level_name like ? `
|
|
|
}
|
|
|
sqlStr := withSql + whereSql
|
|
|
tx := d.transactionContext.PgTx
|
|
|
var cnt int
|
|
|
_, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
|
|
|
return cnt, err
|
|
|
} |
|
|
、、' |
|
|
\ No newline at end of file |
...
|
...
|
|