41 lines
No EOL
2.4 KiB
Transact-SQL
41 lines
No EOL
2.4 KiB
Transact-SQL
CREATE OR ALTER PROCEDURE [dbo].[Hr_S_PerformanceNotify]
|
||
@ReviewId uniqueidentifier,
|
||
@RecipientId uniqueidentifier,
|
||
@TypeName nvarchar(64),
|
||
@SubjectKey nvarchar(128),
|
||
@MessageKey nvarchar(128),
|
||
@ActorId uniqueidentifier = NULL
|
||
AS
|
||
BEGIN
|
||
SET NOCOUNT ON;
|
||
|
||
-- 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 @ReviewId 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(), rv.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(COALESCE(msg.Value, @MessageKey),
|
||
N'[Employee]', COALESCE(e.Name + N' ' + e.Surname, N'')),
|
||
N'[Period]', COALESCE(p.Name, N'')),
|
||
N'[Status]', COALESCE(st.Value, rv.Status)), 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_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 = @RecipientId AND u.IsActive = 1
|
||
INNER JOIN Adm_T_NotificationType t ON t.Name = @TypeName AND t.IsDeleted = 0
|
||
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 = 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'
|
||
LEFT JOIN Sas_H_LanguageText st ON st.ResourceName = N'Platform' AND st.[Key] = N'App.Hr.PerformanceReview.Status.' + rv.Status AND st.CultureName = N'tr'
|
||
WHERE rv.Id = @ReviewId
|
||
AND (r.Channel <> N'Mail' OR u.Email IS NOT NULL);
|
||
END
|
||
GO |