sozsoft-platform/configs/seeds/postgres/object/Hr_S_PerformanceNotify.sql
2026-10-19 17:35:08 +03:00

42 lines
2.5 KiB
PL/PgSQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

CREATE OR REPLACE PROCEDURE public."Hr_S_PerformanceNotify"(
p_ReviewId uuid,
p_RecipientId uuid,
p_TypeName varchar(64),
p_SubjectKey varchar(128),
p_MessageKey varchar(128),
p_ActorId uuid DEFAULT NULL
)
LANGUAGE plpgsql
AS $$
BEGIN
-- Alıcı kayıttan gelir (çalışan, yönetici ya da 360 değerlendiricisi); tipin Custom kuralları
-- yalnızca kanalı belirler. Metin TR dil anahtarından okunur, yer tutucular kayıttan dolar.
IF p_ReviewId IS NULL OR p_RecipientId IS NULL THEN
RETURN;
END IF;
INSERT INTO "Adm_T_Notification" ("Id", "TenantId", "NotificationRuleId", "NotificationChannel", "NotificationTypeId", "Identifier", "UserId", "Message", "Subject", "IsSent", "IsRead", "CreationTime", "CreatorId", "IsDeleted")
SELECT gen_random_uuid(), rv."TenantId", r."Id", r."Channel", t."Id",
CASE WHEN r."Channel" = 'Mail' THEN u."Email" ELSE u."Id"::text END,
u."Id",
LEFT(REPLACE(REPLACE(REPLACE(COALESCE(msg."Value", p_MessageKey),
'[Employee]', COALESCE(e."Name" || ' ' || e."Surname", '')),
'[Period]', COALESCE(p."Name", '')),
'[Status]', COALESCE(st."Value", rv."Status")), 2048),
LEFT(COALESCE(sub."Value", p_SubjectKey), 256),
r."Channel" = 'UiActivity', FALSE, NOW() AT TIME ZONE 'UTC', p_ActorId, FALSE
FROM "Hr_T_PerformanceReview" rv
INNER JOIN "Hr_T_PerformancePeriod" p ON p."Id" = rv."PeriodId"
INNER JOIN "AbpUsers" e ON e."Id" = rv."EmployeeId"
INNER JOIN "AbpUsers" u ON u."Id" = p_RecipientId AND u."IsActive" = TRUE
INNER JOIN "Adm_T_NotificationType" t ON t."Name" = p_TypeName AND t."IsDeleted" = FALSE
AND (t."TenantId" = rv."TenantId" OR (t."TenantId" IS NULL AND rv."TenantId" IS NULL))
INNER JOIN "Adm_T_NotificationRule" r ON r."NotificationTypeId" = t."Id" AND r."IsActive" = TRUE AND r."IsCustomized" = FALSE
AND r."IsDeleted" = FALSE AND r."RecipientType" = 'Custom' AND r."RecipientId" IS NULL
LEFT JOIN "Sas_H_LanguageText" msg ON msg."ResourceName" = 'Platform' AND msg."Key" = p_MessageKey AND msg."CultureName" = 'tr'
LEFT JOIN "Sas_H_LanguageText" sub ON sub."ResourceName" = 'Platform' AND sub."Key" = p_SubjectKey AND sub."CultureName" = 'tr'
LEFT JOIN "Sas_H_LanguageText" st ON st."ResourceName" = 'Platform' AND st."Key" = 'Hr.PerformanceReview.Status.' || rv."Status" AND st."CultureName" = 'tr'
WHERE rv."Id" = p_ReviewId
AND (r."Channel" <> 'Mail' OR u."Email" IS NOT NULL);
END
$$;