107 lines
5.9 KiB
C#
107 lines
5.9 KiB
C#
using System;
|
|
using Kreta.Client.FileService;
|
|
using Kreta.Client.FileService.Request;
|
|
using Kreta.Core.Iktato.Poszeidon.Domain.Model;
|
|
using Kreta.Core.Iktato.Poszeidon.Factory.Interface;
|
|
using Kreta.Core.Iktato.Poszeidon.Infrastructure.Interface;
|
|
using Kreta.DataAccessManual;
|
|
using Kreta.Framework;
|
|
using Kreta.Job.Tasks.Core;
|
|
|
|
namespace Kreta.Job.Tasks
|
|
{
|
|
public class TavolletIktatasJob : IktatasJobBase, ITavolletIktatasJob
|
|
{
|
|
private readonly IFileServiceClientV3 fileServiceClientV3;
|
|
private readonly IFileServiceClient fileServiceClient;
|
|
|
|
public TavolletIktatasJob(IIktatoRepositoryFactory iktatoRepositoryFactory, IWcfServiceContext wcfServiceContext, Kreta.Core.IktatoServiceConfiguration iktatoServiceConfiguration, IFileServiceClientV3 fileServiceClientV3, IFileServiceClient fileServiceClient) : base(iktatoRepositoryFactory, wcfServiceContext, iktatoServiceConfiguration)
|
|
{
|
|
this.fileServiceClientV3 = fileServiceClientV3;
|
|
this.fileServiceClient = fileServiceClient;
|
|
}
|
|
|
|
[Hangfire.AutomaticRetry(Attempts = 1)]
|
|
[JobStateWatcher(typeof(TavolletIktatasJob), nameof(WriteFailedJobId))]
|
|
public void AddCsatolmanyokDokumentumhoz(int iktatottDokumentumId, int csatolmanyId, string intezmenyAzonosito, int tanevId, Hangfire.Server.PerformContext context)
|
|
{
|
|
Dal.OrganizationConnection.Run(intezmenyAzonosito, (h) =>
|
|
{
|
|
var intezmenyDal = h.IntezmenyDal();
|
|
var iktatottDokumentumCsatolmanyDal = h.IktatottDokumentumCsatolmanyDal();
|
|
int intezmenyId = intezmenyDal.GetIntezmenyId(intezmenyAzonosito);
|
|
var intezmeny = intezmenyDal.Get(intezmenyId);
|
|
UserContext.Instance.SetIntezmenyEsTanev(intezmenyId, tanevId, tanevId);
|
|
|
|
var iktatottDokumentum = h.IktatottDokumentumDal().Get(iktatottDokumentumId);
|
|
var csatolmany = iktatottDokumentumCsatolmanyDal.Get(csatolmanyId);
|
|
|
|
var privateToken = fileServiceClient.GetPrivateToken();
|
|
|
|
if (!csatolmany.IsAttached)
|
|
{
|
|
var fileDownloadRequest = new GetUrlRequest(csatolmany.File.Utvonal, csatolmany.File.FileGuid.Value, csatolmany.File.FileNev);
|
|
var response = fileServiceClientV3.GetFile(intezmenyAzonosito, privateToken.AccessToken, fileDownloadRequest);
|
|
if (response.TryAgain)
|
|
{
|
|
response = fileServiceClientV3.GetFile(intezmenyAzonosito, privateToken.AccessToken, fileDownloadRequest);
|
|
}
|
|
|
|
var tanev = h.TanevDal().Get(tanevId);
|
|
var kulcsszavak = GetDokumentumKulcsszavak(h, iktatottDokumentumId, intezmenyId, tanevId, tanev.Nev, iktatottDokumentum.IktatoSzemely.NyomtatasiNev);
|
|
|
|
var csatolmanyIktatasRequest = new CsatolmanyIktatasRequest
|
|
{
|
|
ElektronikusPeldanyRequest = new ElektronikusPeldanyRequest
|
|
{
|
|
BirtokloSzervezetKod = intezmeny.IktatoSzervezetAzonosito,
|
|
EredetiFajlnev = csatolmany.Fajlnev,
|
|
Tartalom = Convert.FromBase64String(response.Tartalom),
|
|
},
|
|
IktatoSzervezetKod = intezmeny.IktatoSzervezetAzonosito,
|
|
IratId = iktatottDokumentum.IratId.ToString(),
|
|
Kulcsszavak = kulcsszavak,
|
|
};
|
|
var iktatoRepositoryConfiguration = GetIktatoRepositoryConfiguration(intezmeny.IktatoSzervezetAzonosito, intezmeny.PoszeidonBejelentkezesiNev);
|
|
var csatolmanyElektronikusPeldanyId = IktatoRepositoryFactory.GetIktatoRepository(iktatoRepositoryConfiguration).CsatolmanyHozzarendeleseIktatottDokumentumhoz(csatolmanyIktatasRequest);
|
|
|
|
csatolmany.ElektronikusPeldanyId = int.Parse(csatolmanyElektronikusPeldanyId);
|
|
csatolmany.IsAttached = true;
|
|
iktatottDokumentumCsatolmanyDal.Update(csatolmany);
|
|
}
|
|
|
|
var deleteRequest = new FileDeleteRequest(csatolmany.File.Utvonal, csatolmany.File.FileGuid.Value);
|
|
var delResponse = fileServiceClientV3.Delete(intezmenyAzonosito, privateToken.AccessToken, deleteRequest);
|
|
if (delResponse.TryAgain)
|
|
{
|
|
delResponse = fileServiceClientV3.Delete(intezmenyAzonosito, privateToken.AccessToken, deleteRequest);
|
|
}
|
|
if (delResponse.IsSuccess)
|
|
{
|
|
h.FileDAL().Delete(csatolmany.File.ID, csatolmany.File.FelhasznaloId);
|
|
}
|
|
|
|
csatolmany.FailedJobId = null;
|
|
iktatottDokumentumCsatolmanyDal.Update(csatolmany);
|
|
});
|
|
}
|
|
|
|
public static void WriteFailedJobId(string jobId)
|
|
{
|
|
var jobDetails = Hangfire.JobStorage.Current.GetMonitoringApi().JobDetails(jobId);
|
|
var csatolmanyId = int.Parse((string)jobDetails.Job.Args[1]);
|
|
var intezmenyAzonosito = (string)jobDetails.Job.Args[2];
|
|
var tanevId = (int)jobDetails.Job.Args[3];
|
|
Dal.OrganizationConnection.Run(intezmenyAzonosito, (h) =>
|
|
{
|
|
var intezmenyDal = h.IntezmenyDal();
|
|
int intezmenyId = intezmenyDal.GetIntezmenyId(intezmenyAzonosito);
|
|
UserContext.Instance.SetIntezmenyEsTanev(intezmenyId, tanevId, tanevId);
|
|
var iktatottDokumentumCsatolmanyDal = h.IktatottDokumentumCsatolmanyDal();
|
|
var iktatottDokumentumCsatolmany = iktatottDokumentumCsatolmanyDal.Get(csatolmanyId);
|
|
iktatottDokumentumCsatolmany.FailedJobId = int.Parse(jobId);
|
|
iktatottDokumentumCsatolmanyDal.Update(iktatottDokumentumCsatolmany);
|
|
});
|
|
}
|
|
}
|
|
}
|