init
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Hangfire.Server;
|
||||
using Kreta.BusinessLogic.Helpers.Models;
|
||||
using Kreta.Core.MessageBroker.Contract.MobileNotification;
|
||||
using Kreta.Core.MessageBroker.Contract.MobileNotification.Enum;
|
||||
using Kreta.Job.Tasks.Cache;
|
||||
using Kreta.Job.Tasks.Helpers.Utility;
|
||||
using Kreta.MessageBroker.Client.MobileNotification;
|
||||
using Kreta.Resources;
|
||||
using Serilog;
|
||||
using Serilog.Core.Enrichers;
|
||||
|
||||
namespace Kreta.Job.Tasks.Helpers.Notification
|
||||
{
|
||||
internal static class OrarendValtozasNotificationHelper
|
||||
{
|
||||
internal static void SendOrarendValtozasNotification(PerformContext context)
|
||||
{
|
||||
var logger = Log.ForContext(new PropertyEnricher[] { new PropertyEnricher("LoggerId", Guid.NewGuid()) });
|
||||
try
|
||||
{
|
||||
var userIds = new List<int>();
|
||||
foreach (var intezmenyAzonosito in KretaServer.KretaServer.Instance.GetOsszesIntezmeny())
|
||||
{
|
||||
OrarendValtozasCache orarendValtozasCache = KretaServer.KretaServer.Instance.CacheManager.AquireCacheMobile<OrarendValtozasCache>();
|
||||
if (orarendValtozasCache != null)
|
||||
{
|
||||
var orarendValtozasok = orarendValtozasCache.GetOrarendValtozasok(intezmenyAzonosito);
|
||||
var kikuldendoOrarendValtozasok = GetKikuldendoOrarendValtozasok(orarendValtozasok);
|
||||
var mobileNotificationMessages = new List<MobileNotificationMessage>();
|
||||
foreach (var orarendValtozas in kikuldendoOrarendValtozasok)
|
||||
{
|
||||
mobileNotificationMessages.Add(MobileNotificationMessageHelper.CreateMessage(
|
||||
orarendValtozas.IntezmenyAzonosito,
|
||||
orarendValtozas.UserId,
|
||||
MobileNotificationMessageType.OrarendValtozas,
|
||||
orarendValtozas.OrarendiOraId,
|
||||
orarendValtozas.Uzenet,
|
||||
NotificationResource.OrarendValtozasTitle,
|
||||
orarendValtozas.Datum.ToIso8601UtcString()));
|
||||
userIds.Add(orarendValtozas.UserId);
|
||||
}
|
||||
if (mobileNotificationMessages.Any())
|
||||
{
|
||||
orarendValtozasCache.RemoveOrarendValtozasok(intezmenyAzonosito);
|
||||
MobileNotificationMessageHelper.PostStudentNotification(mobileNotificationMessages.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
context.SetJobParameter("UserIds", userIds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Fatal(ex, ex.GetType().FullName);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<OrarendValtozasModel> GetKikuldendoOrarendValtozasok(List<OrarendValtozasModel> orarendValtozasok)
|
||||
{
|
||||
var kikuldendoOrarendValtozasok = new List<OrarendValtozasModel>();
|
||||
var userIdGroupedOrarendValtozasok = orarendValtozasok.GroupBy(x => x.UserId).Select(x => new
|
||||
{
|
||||
Key = x.Key,
|
||||
OrarendValtozasok = x.OrderBy(c => c.Datum)
|
||||
});
|
||||
|
||||
foreach (var orarendValtozas in userIdGroupedOrarendValtozasok)
|
||||
{
|
||||
var legkorabbi = orarendValtozas.OrarendValtozasok.First();
|
||||
var napok = string.Concat(string.Join("i, ", orarendValtozas.OrarendValtozasok.Select(n => n.Nap).Distinct()), "i ");
|
||||
|
||||
kikuldendoOrarendValtozasok.Add(new OrarendValtozasModel
|
||||
{
|
||||
IntezmenyAzonosito = legkorabbi.IntezmenyAzonosito,
|
||||
UserId = legkorabbi.UserId,
|
||||
IdpUniqueId = legkorabbi.IdpUniqueId,
|
||||
UserNev = legkorabbi.UserNev,
|
||||
OrarendiOraId = legkorabbi.OrarendiOraId,
|
||||
Uzenet = string.Format(NotificationResource.OrarendValtozasNotificationMessage, legkorabbi.UserNev, napok),
|
||||
Datum = legkorabbi.Datum
|
||||
});
|
||||
}
|
||||
|
||||
return kikuldendoOrarendValtozasok;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user