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 GetDiakOlimpiaList(MdszRequestModel model) { var header = new Dictionary { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; var response = Post>(DiakOlimpiaRelativeUrl, header, body: model); var result = response.Result; return result; } public KozpontiNebuloResponseModel NebuloJelenlet(KozpontiNebuloRequestModel model) { var header = new Dictionary { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; var response = Post(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 { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; var response = Get($"{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 { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; return Post($"{ApiPath}{TTFEllenorzesPath}/{intezmenyAzonosito}/{tanevId}", headers: header).Result; } public TantargyFelosztasResponse GetTTFEllenorzes(string intezmenyAzonosito, string tanevId) { var header = new Dictionary { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; return Get($"{ApiPath}{TTFEllenorzesPath}/{intezmenyAzonosito}/{tanevId}", headers: header).Result; } public List GetIntezmenyUzletiTerv(UzletiTervezesIntezmenyRequestModel model) { var header = new Dictionary { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; var response = Post>(SzemelyijuttatasIntezmenyPath, header, body: model); var result = response.Result; return result; } public List GetIntezmenyUzletiTervAlkalmazottaknak(UzletiTervezesAlkalmazottRequestModel model) { var header = new Dictionary { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; var response = Post>(SzemelyijuttatasAlkalmazottakPath, header, body: model); var result = response.Result; return result; } public List GetTargyiEszkozAlkalmazott(TargyiEszkozAlkalmazottRequestModel model) { var header = new Dictionary { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; var response = Post>(TargyiEszkozAlkalmazottPath, header, body: model); if (response.StatusCode != HttpStatusCode.OK) { throw new BlException(Core.Enum.BlExceptionType.ElvartErtekNemTalalhato); } var result = response.Result; return result; } public List GetTargyiEszkozok(TargyiEszkozIntezmenyRequestModel model) { var header = new Dictionary { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; var response = Post>(TargyiEszkozokIntezmenyPath, header, body: model); return response.Result; } public KotelezoOraszamResponseModel GetKotelezoOraszamok(KotelezoOraszamRequestModel model) { var header = new Dictionary { { nameof(KozpontiKretaConfiguration.ApiKey), KozpontiKretaConfiguration.ApiKey } }; var response = Post(KotelezoOraszamPath, header, body: model); return response.Result; } } }