kreta/Kreta.Client/KozpontiKreta/KozpontiKretaClient.cs
2024-03-13 00:33:46 +01:00

237 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Kreta.Client.ClientBase;
using Kreta.Client.KozpontiKreta.Interface;
using Kreta.Client.KozpontiKreta.Model;
using Kreta.Core.Configuratiaton.Interface;
using Kreta.Core.Exceptions;
using Kreta.Core.KozpontiModels.MdszModels;
using Kreta.Core.KozpontiModels.TargyiEszkozModels;
using Kreta.Core.KozpontiModels.UzletiTervezesModels;
using Kreta.Enums.ManualEnums;
using Kreta.Framework;
using Kreta.Resources;
namespace Kreta.Client.KozpontiKreta
{
internal class KozpontiKretaClient : RestSharpClientBase, IKozpontiKretaClient
{
private readonly IKozpontiKretaConfiguration KozpontiKretaConfiguration;
private const string DiakOlimpiaRelativeUrl = "/api/Mdsz/external/get";
private const string NebuloJelenletRelativeUrl = "/api/nebulo/external/megjelent";
private const string ApiPath = "/api/";
private const string TtfPath = "Document/TTFExportExternal";
private const string RiportPath = "Report/ExportReportExternal";
private const string TtfKiegeszitettAdatokPath = "Document/OnlineReportsExportExternal";
private const string TTFEllenorzesPath = "ttfapproves/external";
private const string TtfElfogadottPath = "Document/ApprovedTTFExportExternal";
private const string TargyiEszkozAlkalmazottPath = "/api/saptool/riport/external/targyieszkozalkalmazott";
private const string SzemelyijuttatasIntezmenyPath = "/api/sapperspayments/riport/external/szemelyijuttatasintezmeny";
private const string SzemelyijuttatasAlkalmazottakPath = "/api/sapperspayments/riport/external/szemelyijuttatasalkalmazottak";
private const string TargyiEszkozokIntezmenyPath = "/api/saptool/riport/external/targyieszkozintezmeny";
private const string KotelezoOraszamPath = "/api/Employee/external/kotelezooraszam";
public KozpontiKretaClient(IKozpontiKretaConfiguration kozpontiKretaConfiguration)
{
KozpontiKretaConfiguration = kozpontiKretaConfiguration ?? throw new ArgumentNullException(nameof(kozpontiKretaConfiguration));
BaseUrl = kozpontiKretaConfiguration.KtrUrl;
}
public List<MdszResponseModel> GetDiakOlimpiaList(MdszRequestModel model)
{
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
var response = Post<List<MdszResponseModel>>(DiakOlimpiaRelativeUrl, header, body: model);
var result = response.Result;
return result;
}
public KozpontiNebuloResponseModel NebuloJelenlet(KozpontiNebuloRequestModel model)
{
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
var response = Post<KozpontiNebuloResponseModel>(NebuloJelenletRelativeUrl, header, body: model);
var result = response.Result;
return result;
}
private (string DokumentumKey, string DokumentumPath) GetDokumentumDetails(KozpontiKretaDokumentumTipusEnum tipus, SystemType systemType)
{
switch (tipus)
{
case KozpontiKretaDokumentumTipusEnum.OsztalyokSzamaRiport:
return (DokumentumKey: "/OSZTALYOK_CSOPORTOK-004-3", DokumentumPath: RiportPath);
case KozpontiKretaDokumentumTipusEnum.CsoportokSzamaRiport:
return (DokumentumKey: "/OSZTALYOK_CSOPORTOK-006-3", DokumentumPath: RiportPath);
case KozpontiKretaDokumentumTipusEnum.FeladatellatasiHelyekRiport:
return (DokumentumKey: "/INTEZMENY-001-3", DokumentumPath: RiportPath);
case KozpontiKretaDokumentumTipusEnum.ReszletesAlkalmazottRiport:
return (DokumentumKey: DokumentumKeyByKornyezet(tipus, systemType), DokumentumPath: RiportPath);
case KozpontiKretaDokumentumTipusEnum.ReszletesTanulokRiport:
return (DokumentumKey: "/SZAKKEPZES-001-3", DokumentumPath: RiportPath);
case KozpontiKretaDokumentumTipusEnum.AgazatiTanuloiLetszamEvfolyamonkentNemenkentRiport:
return (DokumentumKey: "/LETSZAMOK-010-3", DokumentumPath: RiportPath);
case KozpontiKretaDokumentumTipusEnum.TtfExcel:
case KozpontiKretaDokumentumTipusEnum.TtfPdf:
return (DokumentumKey: string.Empty, DokumentumPath: TtfPath);
case KozpontiKretaDokumentumTipusEnum.TtfKiegeszitettAdatok:
return (DokumentumKey: string.Empty, DokumentumPath: TtfKiegeszitettAdatokPath);
case KozpontiKretaDokumentumTipusEnum.TtfElfogadottExcel:
case KozpontiKretaDokumentumTipusEnum.TtfElfogadottPdf:
return (DokumentumKey: string.Empty, DokumentumPath: TtfElfogadottPath);
default:
return (DokumentumKey: string.Empty, DokumentumPath: string.Empty);
}
}
private string DokumentumKeyByKornyezet(KozpontiKretaDokumentumTipusEnum kozpontiKretaDokumentumTipus, SystemType systemType)
{
//systemType = SystemType.NemzetiSzakkepzesiEsFelnottkepzesiHivatal;
if (kozpontiKretaDokumentumTipus == KozpontiKretaDokumentumTipusEnum.ReszletesAlkalmazottRiport)
{
switch (systemType)
{
case SystemType.AZURE:
case SystemType.NSZFH_EMA:
case SystemType.KK:
return "/ALKALMAZOTTAK-018-3-A";
case SystemType.NSZFH:
return "/ALKALMAZOTTAK-018-3-B";
case SystemType.HOI:
return "/ALKALMAZOTTAK-019-3";
}
}
return string.Empty;
}
public byte[] GetRiportDokumentum(KozpontiKretaDokumentumTipusEnum tipus, SystemType systemType, string intezmenyAzonosito, string tanevId, string formatum = "")
{
var (DokumentumKey, DokumentumPath) = GetDokumentumDetails(tipus, systemType);
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
var response = Get<HttpResponseMessage>($"{ApiPath}{DokumentumPath}{DokumentumKey}/{intezmenyAzonosito}/{tanevId}/{formatum}", headers: header, requestTimeout: 600000);
if (response.StatusCode != HttpStatusCode.OK)
{
if (response.StatusCode == HttpStatusCode.NoContent)
{
response.StatusDescription = NyomtatvanyokResource.UresDokumentum;
}
throw new ClientException(response.StatusDescription, response.StatusCode);
}
return response.RawBytes;
}
public TantargyFelosztasResponse PostTTFEllenorzes(string intezmenyAzonosito, string tanevId)
{
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
return Post<TantargyFelosztasResponse>($"{ApiPath}{TTFEllenorzesPath}/{intezmenyAzonosito}/{tanevId}", headers: header).Result;
}
public TantargyFelosztasResponse GetTTFEllenorzes(string intezmenyAzonosito, string tanevId)
{
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
return Get<TantargyFelosztasResponse>($"{ApiPath}{TTFEllenorzesPath}/{intezmenyAzonosito}/{tanevId}", headers: header).Result;
}
public List<UzletiTervezesIntezmenyResponseModel> GetIntezmenyUzletiTerv(UzletiTervezesIntezmenyRequestModel model)
{
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
var response = Post<List<UzletiTervezesIntezmenyResponseModel>>(SzemelyijuttatasIntezmenyPath, header, body: model);
var result = response.Result;
return result;
}
public List<UzletiTervezesAlkalmazottResponseModel> GetIntezmenyUzletiTervAlkalmazottaknak(UzletiTervezesAlkalmazottRequestModel model)
{
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
var response = Post<List<UzletiTervezesAlkalmazottResponseModel>>(SzemelyijuttatasAlkalmazottakPath, header, body: model);
var result = response.Result;
return result;
}
public List<TargyiEszkozResponseModel> GetTargyiEszkozAlkalmazott(TargyiEszkozAlkalmazottRequestModel model)
{
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
var response = Post<List<TargyiEszkozResponseModel>>(TargyiEszkozAlkalmazottPath, header, body: model);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new BlException(Core.Enum.BlExceptionType.ElvartErtekNemTalalhato);
}
var result = response.Result;
return result;
}
public List<TargyiEszkozResponseModel> GetTargyiEszkozok(TargyiEszkozIntezmenyRequestModel model)
{
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
var response = Post<List<TargyiEszkozResponseModel>>(TargyiEszkozokIntezmenyPath, header, body: model);
return response.Result;
}
public KotelezoOraszamResponseModel GetKotelezoOraszamok(KotelezoOraszamRequestModel model)
{
var header = new Dictionary<string, string>
{
{ nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey }
};
var response = Post<KotelezoOraszamResponseModel>(KotelezoOraszamPath, header, body: model);
return response.Result;
}
}
}