sozsoft-platform/configs/seeds/host/sql/object/Hr_S_LeaveNotify.sql

43 lines
2.3 KiB
MySQL
Raw Normal View History

2026-10-04 19:17:16 +00:00
CREATE OR ALTER PROCEDURE [dbo].[Hr_S_LeaveNotify]
@RequestId uniqueidentifier,
@RecipientId uniqueidentifier,
@TypeName nvarchar(64),
@SubjectKey nvarchar(128),
@MessageKey nvarchar(128),
@ActorId uniqueidentifier = NULL
AS
BEGIN
SET NOCOUNT ON;
-- Alıcı talepten gelir (müdür, İK onaycısı ya da çalışan); tipin Custom kuralları yalnızca
-- kanalı belirler. Metin TR dil anahtarından okunur, yer tutucular talepten dolar.
IF @RequestId IS NULL OR @RecipientId IS NULL
RETURN;
INSERT INTO Adm_T_Notification (Id, TenantId, NotificationRuleId, NotificationChannel, NotificationTypeId, Identifier, UserId, Message, Subject, IsSent, IsRead, CreationTime, CreatorId, IsDeleted)
SELECT NEWID(), lr.TenantId, r.Id, r.Channel, t.Id,
CASE WHEN r.Channel = N'Mail' THEN u.Email ELSE CONVERT(nvarchar(64), u.Id) END,
u.Id,
LEFT(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(COALESCE(msg.Value, @MessageKey),
N'[Employee]', COALESCE(lr.EmployeeName, N'')),
N'[LeaveType]', COALESCE(lt.Name, N'')),
N'[StartDate]', FORMAT(lr.StartDate, 'dd.MM.yyyy')),
N'[EndDate]', FORMAT(lr.EndDate, 'dd.MM.yyyy')),
N'[Days]', FORMAT(lr.Days, '0.#')),
N'[Status]', COALESCE(lr.ApprovalStatus, N'')), 2048),
LEFT(COALESCE(sub.Value, @SubjectKey), 256),
CASE WHEN r.Channel = N'UiActivity' THEN 1 ELSE 0 END, 0, GETUTCDATE(), @ActorId, 0
FROM Hr_T_LeaveRequest lr
INNER JOIN Hr_T_LeaveType lt ON lt.Id = lr.LeaveTypeId
INNER JOIN AbpUsers u ON u.Id = @RecipientId AND u.IsActive = 1
INNER JOIN Adm_T_NotificationType t ON t.Name = @TypeName AND t.IsDeleted = 0
AND (t.TenantId = lr.TenantId OR (t.TenantId IS NULL AND lr.TenantId IS NULL))
INNER JOIN Adm_T_NotificationRule r ON r.NotificationTypeId = t.Id AND r.IsActive = 1 AND r.IsCustomized = 0
AND r.IsDeleted = 0 AND r.RecipientType = N'Custom' AND r.RecipientId IS NULL
LEFT JOIN Sas_H_LanguageText msg ON msg.ResourceName = N'Platform' AND msg.[Key] = @MessageKey AND msg.CultureName = N'tr'
LEFT JOIN Sas_H_LanguageText sub ON sub.ResourceName = N'Platform' AND sub.[Key] = @SubjectKey AND sub.CultureName = N'tr'
WHERE lr.Id = @RequestId
AND (r.Channel <> N'Mail' OR u.Email IS NOT NULL);
END
GO