sozsoft-platform/configs/seeds/postgres/object/Hr_S_PerformanceNotify.sql

43 lines
2.5 KiB
MySQL
Raw Permalink Normal View History

2026-10-06 11:24:30 +00:00
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'
2026-10-19 14:35:08 +00:00
LEFT JOIN "Sas_H_LanguageText" st ON st."ResourceName" = 'Platform' AND st."Key" = 'Hr.PerformanceReview.Status.' || rv."Status" AND st."CultureName" = 'tr'
2026-10-06 11:24:30 +00:00
WHERE rv."Id" = p_ReviewId
AND (r."Channel" <> 'Mail' OR u."Email" IS NOT NULL);
END
$$;