评查文件列表的查询查看、文档列表的查询查看修改删除都添加了user_id去限制用户操作。
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
CREATE OR REPLACE FUNCTION "public"."get_review_files_with_details"("p_keyword" text=NULL::text, "p_typeid" _int4=NULL::integer[], "p_evaluations_status" int4=NULL::integer, "p_date_from" date=NULL::date, "p_date_to" date=NULL::date, "p_sort_order" text='created_at_desc'::text, "p_page" int4=1, "p_page_size" int4=10)
|
||||
CREATE OR REPLACE FUNCTION "public"."get_review_files_with_details"("p_keyword" text=NULL::text, "p_typeid" _int4=NULL::integer[], "p_evaluations_status" int4=NULL::integer, "p_date_from" date=NULL::date, "p_date_to" date=NULL::date, "p_sort_order" text='created_at_desc'::text, "p_page" int4=1, "p_page_size" int4=10, "p_document_ids" _int4=NULL::integer[], "p_user_id" int4=NULL::integer)
|
||||
RETURNS TABLE("id" int4, "status" varchar, "path" varchar, "file_name" varchar, "file_code" varchar, "file_type_name" varchar, "file_type_id" int4, "file_size" int4, "upload_time" timestamptz, "created_at" timestamptz, "evaluations_status" int4, "audit_status" int4, "created_by_user_id" int4, "issue_count" int8, "total_score" numeric, "pass_count" int8, "warning_count" int8, "fail_count" int8, "manual_count" int8, "issues" jsonb) AS $BODY$
|
||||
DECLARE
|
||||
offset_val integer;
|
||||
@@ -6,6 +6,11 @@ DECLARE
|
||||
sort_direction text;
|
||||
BEGIN
|
||||
offset_val := (p_page - 1) * p_page_size;
|
||||
|
||||
-- 如果p_user_id为NULL,直接返回0
|
||||
IF p_user_id IS NULL THEN
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
SELECT
|
||||
CASE
|
||||
@@ -70,13 +75,44 @@ BEGIN
|
||||
($2 IS NULL OR d.type_id = ANY($2)) AND
|
||||
($3 IS NULL OR d.evaluations_status = $3) AND
|
||||
($4 IS NULL OR d.created_at >= $4) AND
|
||||
($5 IS NULL OR d.created_at < ($5 + INTERVAL ''1 day''))
|
||||
($5 IS NULL OR d.created_at < ($5 + INTERVAL ''1 day'')) AND
|
||||
($8 IS NULL OR d.id = ANY($8)) AND
|
||||
($9 d.user_id = $9)
|
||||
ORDER BY %I %s
|
||||
LIMIT $6 OFFSET $7
|
||||
', sort_column, sort_direction)
|
||||
USING p_keyword, p_typeid, p_evaluations_status, p_date_from, p_date_to, p_page_size, offset_val;
|
||||
USING p_keyword, p_typeid, p_evaluations_status, p_date_from, p_date_to, p_page_size, offset_val, p_document_ids, p_user_id;
|
||||
END;
|
||||
$BODY$
|
||||
LANGUAGE plpgsql VOLATILE
|
||||
COST 100
|
||||
ROWS 1000;
|
||||
ROWS 1000;
|
||||
|
||||
-- 同时创建或更新 count_review_files 函数
|
||||
CREATE OR REPLACE FUNCTION "public"."count_review_files"("p_keyword" text=NULL::text, "p_typeid" _int4=NULL::integer[], "p_evaluations_status" int4=NULL::integer, "p_date_from" date=NULL::date, "p_date_to" date=NULL::date, "p_document_ids" _int4=NULL::integer[], "p_user_id" int4=NULL::integer)
|
||||
RETURNS int4 AS $BODY$
|
||||
DECLARE
|
||||
total_count integer;
|
||||
BEGIN
|
||||
-- 如果p_user_id为NULL,直接返回0
|
||||
IF p_user_id IS NULL THEN
|
||||
RETURN 0;
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO total_count
|
||||
FROM documents d
|
||||
WHERE
|
||||
(p_keyword IS NULL OR (d.name ILIKE '%' || p_keyword || '%' OR d.document_number ILIKE '%' || p_keyword || '%')) AND
|
||||
(p_typeid IS NULL OR d.type_id = ANY(p_typeid)) AND
|
||||
(p_evaluations_status IS NULL OR d.evaluations_status = p_evaluations_status) AND
|
||||
(p_date_from IS NULL OR d.created_at >= p_date_from) AND
|
||||
(p_date_to IS NULL OR d.created_at < (p_date_to + INTERVAL '1 day')) AND
|
||||
(p_document_ids IS NULL OR d.id = ANY(p_document_ids)) AND
|
||||
d.user_id = p_user_id;
|
||||
|
||||
RETURN total_count;
|
||||
END;
|
||||
$BODY$
|
||||
LANGUAGE plpgsql STABLE
|
||||
COST 100;
|
||||
Reference in New Issue
Block a user