-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathget_trigger_page_list.sql
More file actions
34 lines (33 loc) · 1.43 KB
/
get_trigger_page_list.sql
File metadata and controls
34 lines (33 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
SELECT *
FROM (SELECT t.id,
t.workspace_id,
t.name,
t."desc",
t.trigger_type,
t.trigger_setting,
t.meta::JSON,
t.is_active,
t.create_time,
t.update_time,
t.user_id,
(SELECT nick_name FROM "user" WHERE id = t.user_id) AS create_user,
COALESCE(
JSON_AGG(
JSON_BUILD_OBJECT(
'type', tt.source_type,
'name', COALESCE(app.name, tool.name),
'icon', COALESCE(app.icon, tool.icon)
)
), '[]'::JSON
) AS trigger_task,
STRING_AGG(COALESCE(app.name, tool.name), ' ') AS trigger_task_str
FROM event_trigger t
LEFT JOIN event_trigger_task tt ON t.id = tt.trigger_id
LEFT JOIN application app ON tt.source_type = 'APPLICATION' AND tt.source_id = app.id
LEFT JOIN tool ON tt.source_type = 'TOOL' AND tt.source_id = tool.id
${trigger_query_set}
GROUP BY t.id, t.workspace_id, t.name, t.desc, t.trigger_type, t.trigger_setting, t.meta, t.is_active,
t.create_time,
t.update_time, t.user_id) AS sub
${task_query_set}
ORDER BY sub.create_time DESC