refactor: improve SQL queries to include user nicknames and enhance readability

This commit is contained in:
CaptainB 2025-06-18 18:14:02 +08:00
parent 13c5833d42
commit b9304f0fda
4 changed files with 71 additions and 65 deletions

View File

@ -1,28 +1,30 @@
select * select *
from (select "id"::text, from (select application."id"::text,
"name", application."name",
"desc", application. "desc",
"is_publish", application. "is_publish",
"type", application."type",
'application' as "resource_type", 'application' as "resource_type",
"workspace_id", application."workspace_id",
"folder_id", application. "folder_id",
"user_id", application."user_id",
"create_time", "user"."nick_name" as "nick_name",
"update_time" application."create_time",
from application application."update_time"
from application left join "user" on user_id = "user".id
${application_custom_sql} ${application_custom_sql}
UNION UNION
select "id", select application_folder."id",
"name", application_folder."name",
"desc", application_folder."desc",
true as "is_publish", true as "is_publish",
'folder' as "type", 'folder' as "type",
'folder' as "resource_type", 'folder' as "resource_type",
"workspace_id", application_folder."workspace_id",
"parent_id" as "folder_id", application_folder."parent_id" as "folder_id",
"user_id", application_folder."user_id",
"create_time", "user"."nick_name" as "nick_name",
"update_time" application_folder."create_time",
from application_folder ${folder_query_set}) temp application_folder."update_time"
from application_folder left join "user" on user_id = "user".id ${folder_query_set}) temp
${application_query_set} ${application_query_set}

View File

@ -1,31 +1,33 @@
select * select *
from (select "id"::text, from (select application."id"::text,
"name", application."name",
"desc", application. "desc",
"is_publish", application. "is_publish",
"type", application."type",
'application' as "resource_type", 'application' as "resource_type",
"workspace_id", application."workspace_id",
"folder_id", application. "folder_id",
"user_id", application."user_id",
"create_time", "user"."nick_name" as "nick_name",
"update_time" application."create_time",
from application application."update_time"
from application left join "user" on user_id = "user".id
where id in (select target where id in (select target
from workspace_user_resource_permission from workspace_user_resource_permission
where auth_target_type = 'APPLICATION' where auth_target_type = 'APPLICATION'
and 'VIEW' = any (permission_list)) and 'VIEW' = any (permission_list))
UNION UNION
select "id", select application_folder."id",
"name", application_folder."name",
"desc", application_folder."desc",
true as "is_publish", true as "is_publish",
'folder' as "type", 'folder' as "type",
'folder' as "resource_type", 'folder' as "resource_type",
"workspace_id", application_folder."workspace_id",
"parent_id" as "folder_id", application_folder."parent_id" as "folder_id",
"user_id", application_folder."user_id",
"create_time", "user"."nick_name" as "nick_name",
"update_time" application_folder."create_time",
from application_folder ${folder_query_set}) temp application_folder."update_time"
from application_folder left join "user" on user_id = "user".id ${folder_query_set}) temp
${application_query_set} ${application_query_set}

View File

@ -1,16 +1,17 @@
select * select *
from (select "id"::text, from (select application."id"::text,
"name", application."name",
"desc", application. "desc",
"is_publish", application. "is_publish",
"type", application."type",
'application' as "resource_type", 'application' as "resource_type",
"workspace_id", application."workspace_id",
"folder_id", application. "folder_id",
"user_id", application."user_id",
"create_time", "user"."nick_name" as "nick_name",
"update_time" application."create_time",
from application application."update_time"
from application left join "user" on user_id = "user".id
where id in (select target where id in (select target
from workspace_user_resource_permission from workspace_user_resource_permission
where auth_target_type = 'APPLICATION' where auth_target_type = 'APPLICATION'
@ -24,16 +25,17 @@ from (select "id"::text,
'VIEW' = any (permission_list) 'VIEW' = any (permission_list)
end) end)
UNION UNION
select "id", select application_folder."id",
"name", application_folder."name",
"desc", application_folder."desc",
true as "is_publish", true as "is_publish",
'folder' as "type", 'folder' as "type",
'folder' as "resource_type", 'folder' as "resource_type",
"workspace_id", application_folder."workspace_id",
"parent_id" as "folder_id", application_folder."parent_id" as "folder_id",
"user_id", application_folder."user_id",
"create_time", "user"."nick_name" as "nick_name",
"update_time" application_folder."create_time",
from application_folder ${folder_query_set}) temp application_folder."update_time"
from application_folder left join "user" on user_id = "user".id ${folder_query_set}) temp
${application_query_set} ${application_query_set}

View File

@ -153,7 +153,7 @@
</template> </template>
<template #subTitle> <template #subTitle>
<el-text class="color-secondary lighter" size="small"> <el-text class="color-secondary lighter" size="small">
{{ $t('common.creator') }}: {{ item.username }} {{ $t('common.creator') }}: {{ item.nick_name }}
</el-text> </el-text>
</template> </template>
</CardBox> </CardBox>
@ -171,7 +171,7 @@
<template #subTitle> <template #subTitle>
<el-text class="color-secondary" size="small"> <el-text class="color-secondary" size="small">
<auto-tooltip :content="item.username"> <auto-tooltip :content="item.username">
{{ $t('common.creator') }}: {{ item.username }} {{ $t('common.creator') }}: {{ item.nick_name }}
</auto-tooltip> </auto-tooltip>
</el-text> </el-text>
</template> </template>