切换导航条
此项目
正在载入...
登录
allied-creation
/
performance
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
tangxvhui
2 years ago
提交
07389a1f87887ae77c68e81e1c35355c77ac4ce5
1 个父辈
3b41c2d2
调整sql
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
175 行增加
和
0 行删除
pkg/infrastructure/dao/task.go
pkg/infrastructure/dao/task.go
0 → 100644
查看文件 @
07389a1
package
dao
import
(
"fmt"
pgTransaction
"github.com/linmadan/egglib-go/transaction/pg"
)
type
TaskDao
struct
{
transactionContext
*
pgTransaction
.
TransactionContext
}
func
NewTaskDao
(
options
map
[
string
]
interface
{})
*
TaskDao
{
var
transactionContext
*
pgTransaction
.
TransactionContext
if
value
,
ok
:=
options
[
"transactionContext"
];
ok
{
transactionContext
=
value
.
(
*
pgTransaction
.
TransactionContext
)
}
return
&
TaskDao
{
transactionContext
:
transactionContext
,
}
}
func
(
d
*
TaskDao
)
catchTaskIdByPermission
(
userId
int
)
string
{
sqlStr
:=
`with
-- 人员自身以及全下级
recursive t_user as (
(
select "user".id,"user".parent_id
from "user"
where company_id =233 and "user".id=%d
)
union
(
select "child_user".id,"child_user".parent_id
from "user" as "child_user"
join t_user as "parent_user" on "parent_user".id="child_user".parent_id
)
),
-- 根据任务负责人和相关人员查询
t_task_0 as (
(select task.id from task
join t_user on task.leader ->>'id'=t_user.id::text
)
union
(select task.id from task where task.related_user@>'[%d]')
),
t_task_ignore as (
select * from task_ignore where task_ignore.user_id =%d
),
-- 过滤取消关注的
t_task_1 as (
select t_task_0.id
from t_task_0
left join t_task_ignore on t_task_0.id=t_task_ignore.task_id
where t_task_ignore.id isnull
)`
return
fmt
.
Sprintf
(
sqlStr
,
userId
,
userId
,
userId
)
}
type
ListTaskCondition
struct
{
Limit
int
//分页
Offset
int
//分页
UserId
int
//谁要查看任务数据
TaskName
string
//任务名称
LevelName
string
//优先级
OnlyMy
bool
//只查看我负责的任务
LeaderId
string
//任务负责人id
}
// 获取任务以及里程碑列表,用于页面展示; 有过滤查看权限
// userid 谁要查看任务数据
// limit 分页
// offset 分页
func
(
d
*
TaskDao
)
ListTaskStageNotHrbp
(
param
ListTaskCondition
)
{
task1
:=
d
.
catchTaskIdByPermission
(
param
.
UserId
)
withSql
:=
task1
+
`,
-- 获取的里程碑数据,以及排序
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 t_task_1 on task.id=t_task_1.id
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
where 1=1
%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 t_task_tage_1.leader_id = '?' `
}
else
if
param
.
LeaderId
!=
""
{
condition
=
append
(
condition
,
param
.
LeaderId
)
whereSql
+=
` and t_task_tage_1.leader_id = ? `
}
if
len
(
param
.
TaskName
)
>
0
{
condition
=
append
(
condition
,
param
.
TaskName
)
whereSql
+=
` and t_task_tage_1.task_name like ? `
}
if
len
(
param
.
LevelName
)
>
0
{
condition
=
append
(
condition
,
param
.
LevelName
)
whereSql
+=
` and t_task_tage_1.level_name like ? `
}
=
withSql
}
// 获取任务总数,用于页面展示; 有过滤查看权限
func
(
d
*
TaskDao
)
CountTaskStageNotHrbp
(
param
ListTaskCondition
)
{
task1
:=
d
.
catchTaskIdByPermission
(
param
.
UserId
)
withSql
:=
task1
+
`select count(*) from task
join t_task_1 on task.id =t_task_1.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
_
=
sqlStr
}
、、'
\ No newline at end of file
...
...
请
注册
或
登录
后发表评论