201 lines
8.6 KiB
C#
201 lines
8.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Hangfire;
|
|
using Kreta.Client.Tavollet;
|
|
using Kreta.Core.Configuratiaton;
|
|
using Kreta.Core.SAP.CommunicationModels;
|
|
using Kreta.DataAccessManual;
|
|
using Kreta.DataAccessManual.ParameterClasses;
|
|
using Kreta.Enums;
|
|
using Kreta.Enums.ManualEnums;
|
|
using Kreta.Job.Tasks.Core;
|
|
using Kreta.Job.Tasks.Core.Models;
|
|
using Kreta.Resources;
|
|
|
|
namespace Kreta.Job.Tasks
|
|
{
|
|
public class TavolletJob : ITavolletJob
|
|
{
|
|
private readonly string KozpontiKretaConfig = "KozpontiKretaConfig";
|
|
|
|
public void SyncTavolletIktatott()
|
|
{
|
|
var kozpontiKreta = (KozpontiKretaConfiguration)ConfigurationManager.GetSection(KozpontiKretaConfig);
|
|
|
|
var tavolletClient = new TavolletClient(kozpontiKreta.KgrUrl, kozpontiKreta.ApiKey);
|
|
|
|
var exceptions = new List<Exception>();
|
|
|
|
foreach (var azonosito in KretaServer.KretaServer.Instance.GetOsszesIntezmeny())
|
|
{
|
|
var connectionString = KretaServer.KretaServer.Instance.GetIntezmenyConnectionString(azonosito);
|
|
|
|
Dal.ServiceSystemConnection.Run(connectionString, h =>
|
|
{
|
|
try
|
|
{
|
|
var icDal = h.IntezmenyConfigDAL();
|
|
var dal = h.IntezmenyDal();
|
|
var intezmenyId = dal.GetIntezmenyIdByAzonosito(azonosito);
|
|
|
|
if (!bool.Parse(icDal.GetIntezmenyConfig(intezmenyId.Value, IntezmenyConfigModulEnum.HRModul.ToString(), IntezmenyConfigTipusEnum.IsEnabled.ToString())))
|
|
return;
|
|
|
|
var ds = dal.GetIntezmenyIdAktivTanevIdByAzonosito(azonosito);
|
|
|
|
if (ds.Tables[0].Rows.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var pco = new TavolletIktatottPCO()
|
|
{
|
|
TanevId = ds.Tables[0].Rows[0].Field<int>("AktivTanevId"),
|
|
IntezmenyId = ds.Tables[0].Rows[0].Field<int>("IntezmenyId")
|
|
};
|
|
|
|
var iDal = h.HRModulDAL();
|
|
|
|
var queryResult = iDal.GetTavolletSzinkronizalatlanDok(pco);
|
|
|
|
if (queryResult.Tables[0].Rows.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
TavolletDokumentumSyncRequestModel request = MapDatasetToRequestModel(queryResult);
|
|
|
|
if (tavolletClient.SyncTavolletIktatott(request).IsSuccess)
|
|
{
|
|
iDal.UpdateSzinkronizalatlan(pco.IntezmenyId, pco.TanevId, request.DokumentumokList.Select(x => x.TavolletJelentoId).Distinct().ToList());
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
exceptions.Add(ex);
|
|
}
|
|
|
|
if (exceptions.Any())
|
|
{
|
|
var aggregateException = new AggregateException(exceptions);
|
|
throw aggregateException.Flatten();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public void SendOutTavolletReminderEmails()
|
|
{
|
|
var kozpontiKreta = (KozpontiKretaConfiguration)ConfigurationManager.GetSection(KozpontiKretaConfig);
|
|
var tavolletClient = new TavolletClient(kozpontiKreta.KgrUrl, kozpontiKreta.ApiKey);
|
|
var exceptions = new List<Exception>();
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
foreach (var azonosito in KretaServer.KretaServer.Instance.GetOsszesIntezmeny())
|
|
{
|
|
var connectionString = KretaServer.KretaServer.Instance.GetIntezmenyConnectionString(azonosito);
|
|
TavolletjelentoListaResponseModel fuggoTavolletek = tavolletClient.GetTavolletek(
|
|
new TavolletjelentoListaRequestModel
|
|
{
|
|
IdoszakKezdet = new DateTime(dateTime.Year, dateTime.Month, 1),
|
|
TavolletStatuszId = (int)Kreta.Core.SAP.Enums.TavolletStatuszok.Fuggo,
|
|
KretaIntezmenyAzonosito = azonosito,
|
|
NaptariEv = new int[] { DateTime.Now.Year }
|
|
});
|
|
|
|
if (fuggoTavolletek?.TavolletjelentoResultList != null && fuggoTavolletek.TavolletjelentoResultList.Any())
|
|
{
|
|
Dal.ServiceSystemConnection.Run(connectionString, h =>
|
|
{
|
|
try
|
|
{
|
|
var icDal = h.IntezmenyConfigDAL();
|
|
var dal = h.IntezmenyDal();
|
|
var intezmenyId = dal.GetIntezmenyIdByAzonosito(azonosito);
|
|
|
|
if (!bool.Parse(icDal.GetIntezmenyConfig(intezmenyId.Value, IntezmenyConfigModulEnum.HRModul.ToString(), IntezmenyConfigTipusEnum.IsEnabled.ToString())))
|
|
return;
|
|
|
|
var ds = dal.GetIntezmenyIdAktivTanevIdByAzonosito(azonosito);
|
|
|
|
if (ds.Tables[0].Rows.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var tanevId = ds.Tables[0].Rows[0].Field<int>("AktivTanevId");
|
|
|
|
var alkalmazottDal = h.Alkalmazott();
|
|
DataSet tavolletJovahagyok = alkalmazottDal.GetAlkalmazottakNeveEsEmailCimeVzetoOraszamOkAlapjan(tanevId,
|
|
(int)EmailTipusEnum.Hivatalos, intezmenyId.Value,
|
|
new List<int>
|
|
{
|
|
(int) VezetoiOraszamokTipusEnum.Intezmenyvezeto,
|
|
(int) VezetoiOraszamokTipusEnum.TagintezmenyVezeto,
|
|
(int) VezetoiOraszamokTipusEnum.IntezmenyegysegVezeto
|
|
});
|
|
|
|
if (tavolletJovahagyok.Tables[0]?.Rows.Count > 0)
|
|
{
|
|
var emailsToBeSend = new List<EmailModel>();
|
|
|
|
// Iterate through users
|
|
foreach (DataRow dataRow in tavolletJovahagyok.Tables[0].Rows)
|
|
{
|
|
var emailCim = dataRow.Field<string>("EmailCim");
|
|
var emailModel = new EmailModel();
|
|
emailModel.TargetEmail = emailCim;
|
|
emailModel.Subject = EmailResource.TavolletJovahagyasEmlekeztetoTargy;
|
|
emailModel.Message = EmailResource.TavolletJovahagyasEmlekezteto;
|
|
|
|
emailsToBeSend.Add(emailModel);
|
|
}
|
|
|
|
if (emailsToBeSend.Any())
|
|
{
|
|
BackgroundJob.Enqueue<IEmailJob>(email => email.SendMailMessages(emailsToBeSend));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
exceptions.Add(ex);
|
|
}
|
|
|
|
if (exceptions.Any())
|
|
{
|
|
var aggregateException = new AggregateException(exceptions);
|
|
throw aggregateException.Flatten();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
private TavolletDokumentumSyncRequestModel MapDatasetToRequestModel(DataSet result)
|
|
{
|
|
var tavolletJelento = new List<TavolletDokumentumData>();
|
|
|
|
foreach (DataRow row in result.Tables[0].Rows)
|
|
{
|
|
var temp = new TavolletDokumentumData
|
|
{
|
|
TavolletJelentoId = row.Field<int>("C_KOZPONTITAVOLLETID"),
|
|
ElektronikusPeldanyId = row.Field<int>("C_ELEKTRONIKUSPELDANYID"),
|
|
FajlNev = row.Field<string>("C_FAJLNEV"),
|
|
RogzitoNev = row.Field<string>("C_NYOMTATASINEV"),
|
|
RogzitoGuid = Guid.Parse(row.Field<string>("C_EGYEDIAZONOSITO")),
|
|
RogzitesIdopontja = row.Field<DateTime>("C_IKTATASDATUMA"),
|
|
};
|
|
|
|
tavolletJelento.Add(temp);
|
|
}
|
|
|
|
return new TavolletDokumentumSyncRequestModel { DokumentumokList = tavolletJelento };
|
|
}
|
|
}
|
|
}
|