From a2a61407851c961f86b4cc4a5c7cd1a588ebe5bb Mon Sep 17 00:00:00 2001 From: Andreas Luxbauer Date: Thu, 24 Apr 2025 17:01:07 +0200 Subject: [PATCH 1/2] vers --- SDL/My Project/AssemblyInfo.vb | 4 +- .../Schnittstellen/TELOTEC/cTelotecAPI.vb | 271 +++++++----------- 2 files changed, 110 insertions(+), 165 deletions(-) diff --git a/SDL/My Project/AssemblyInfo.vb b/SDL/My Project/AssemblyInfo.vb index 5a5e0c26..77446643 100644 --- a/SDL/My Project/AssemblyInfo.vb +++ b/SDL/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - - + + diff --git a/VERAG_PROG_ALLGEMEIN/Schnittstellen/TELOTEC/cTelotecAPI.vb b/VERAG_PROG_ALLGEMEIN/Schnittstellen/TELOTEC/cTelotecAPI.vb index b79cb469..900f0541 100644 --- a/VERAG_PROG_ALLGEMEIN/Schnittstellen/TELOTEC/cTelotecAPI.vb +++ b/VERAG_PROG_ALLGEMEIN/Schnittstellen/TELOTEC/cTelotecAPI.vb @@ -6,9 +6,16 @@ Imports System.IO Imports System.Text Public Class cTelotecAPI + + 'SPI SWAGGER:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + 'https://accscustomsapi.teloweb.at/accscustomsapi120/swagger/index.html + + Public API_KEY = "YlcbZryXuKPSzQTzkGIJK9UdScGuSnhBBji94Z7A8UMoWPR0qDvVOvmlWNuUCMrQ" 'VERAG Public BASE_URL = "https://accscustomsapi.teloweb.at/accscustomsapi120" Dim TELOTEC_JSON As String = "\\datenarchiv\Datenarchiv\TELOTEC\ECHTSYSTEM\Nachrichtendaten_Ablage_JSON" ' <-- Deinen Pfad hier setzen + Dim TELOTEC_ATTACHMENT_PATH As String = "\\datenarchiv\Datenarchiv\TELOTEC\ECHTSYSTEM\Nachrichtendaten_Ablage_PDF" ' + Sub Main() Console.WriteLine("ACCS Customs API Demo") @@ -16,6 +23,9 @@ Public Class cTelotecAPI PostStoreTADeclarations(taRequest) Dim messages As List(Of TAMessage) = GetTAMessages() Console.WriteLine("Nachrichten: " & messages.Count) + + + End Sub Function getAPIKEY(Firma) As String @@ -147,34 +157,63 @@ Public Class cTelotecAPI End If Console.WriteLine("📡 HTTP-Statuscode: " & resp.StatusCode) + 'If resp.StatusCode <> 200 Then + ' Console.WriteLine("❌ Fehler: Erwartet wurde Statuscode 200, erhalten: " & resp.StatusCode) + ' Console.WriteLine("Antworttext:") + ' Console.WriteLine(resp.BodyStr) + ' Return messages + 'End If + + + If resp.StatusCode <> 200 Then - Console.WriteLine("❌ Fehler: Erwartet wurde Statuscode 200, erhalten: " & resp.StatusCode) - Console.WriteLine("Antworttext:") + Console.WriteLine("❌ Fehler: HTTP-Statuscode " & resp.StatusCode) Console.WriteLine(resp.BodyStr) - Return messages - End If - - Dim json As New JsonObject() - Dim success As Boolean = json.Load(resp.BodyStr) - - If Not success Then - Console.WriteLine("❌ Fehler beim Parsen der JSON-Antwort:") - Console.WriteLine(json.LastErrorText) - Return messages - End If - - Dim msgArray As JsonArray = json.ArrayOf("messages") - If msgArray Is Nothing Then - Console.WriteLine("⚠️ 'messages' war null oder nicht vorhanden.") - Return messages + Return New List(Of TAMessage)() End If Dim jsonText As String = resp.BodyStr SaveJsonResponseToFile(jsonText, TELOTEC_JSON) + ' Übergabe an Parserfunktion + Return ParseTAMessagesJson(jsonText) + + + + End Function + + + Public Function ParseTAMessagesFromFile(filePath As String) As List(Of TAMessage) + Dim messages As New List(Of TAMessage)() + + If Not File.Exists(filePath) Then + Console.WriteLine("❌ Datei nicht gefunden: " & filePath) + Return messages + End If + + Try + Dim jsonText As String = File.ReadAllText(filePath, Encoding.UTF8) + Return ParseTAMessagesJson(jsonText) + Catch ex As Exception + Console.WriteLine("❌ Fehler beim Lesen/Verarbeiten der Datei: " & ex.Message) + End Try + + Return messages + End Function + + + Public Function ParseTAMessagesJson(jsonText As String) As List(Of TAMessage) + Dim messages As New List(Of TAMessage)() + + Dim json As New Chilkat.JsonObject() + If Not json.Load(jsonText) Then + Console.WriteLine("❌ Fehler beim Parsen des JSON.") + Return messages + End If + + Dim msgArray As Chilkat.JsonArray = json.ArrayOf("messages") + If msgArray Is Nothing Then Return messages - Dim serializer As New JavaScriptSerializer() - Console.WriteLine("✅ Empfangene Nachrichten: " & msgArray.Size) For i As Integer = 0 To msgArray.Size - 1 Dim jmsg As Chilkat.JsonObject = msgArray.ObjectAt(i) Dim msg As New TAMessage() @@ -183,6 +222,15 @@ Public Class cTelotecAPI msg.externalReference = jmsg.StringOf("externalReference") msg.msgType = jmsg.StringOf("msgType") + + ' 💾 Attachment speichern + + Dim attachmentB64 As String = jmsg.StringOf("attachment") + If Not String.IsNullOrWhiteSpace(attachmentB64) AndAlso attachmentB64.ToString <> "null" Then + SaveAttachmentBase64(attachmentB64, TELOTEC_ATTACHMENT_PATH, msg.lrn) + End If + + Dim contentObj As Chilkat.JsonObject = jmsg.ObjectOf("declarationContent") If Not contentObj Is Nothing Then Dim decl As New TADeclaration() @@ -252,6 +300,13 @@ Public Class cTelotecAPI If arr2 IsNot Nothing Then decl.guarantee = ParseGuarantee(arr2) msg.declarationContent = decl + + + + 'PARSE TO cTELANMEUNG + + + '------------------------------- Else Console.WriteLine("⚠️ Keine declarationContent für Nachricht: " & msg.lrn) End If @@ -262,8 +317,31 @@ Public Class cTelotecAPI Return messages End Function + Public Sub SaveAttachmentBase64(base64String As String, ByVal TELOTEC_ATTACHMENT_PATH As String, filePrefix As String) + Try + If String.IsNullOrWhiteSpace(base64String) Then Exit Sub + Dim yearDir As String = Path.Combine(TELOTEC_ATTACHMENT_PATH, Date.Now.Year.ToString()) + Dim dayDir As String = Path.Combine(yearDir, Date.Now.ToString("yyyy-MM-dd")) + Directory.CreateDirectory(dayDir) + ' ❗️Unerlaubte Zeichen im Dateinamen ersetzen + Dim invalidChars() As Char = Path.GetInvalidFileNameChars() + For Each ch In invalidChars + filePrefix = filePrefix.Replace(ch, "_"c) + Next + + Dim fileName As String = filePrefix & "_" & Date.Now.ToString("HHmmss") & ".pdf" + Dim filePath As String = Path.Combine(dayDir, fileName) + + Dim fileBytes() As Byte = Convert.FromBase64String(base64String) + File.WriteAllBytes(filePath, fileBytes) + + Console.WriteLine("📄 PDF gespeichert unter: " & filePath) + Catch ex As Exception + Console.WriteLine("❌ Fehler beim Speichern des Attachments: " & ex.Message) + End Try + End Sub Public Sub SaveJsonResponseToFile(jsonText As String, ByVal TELOTEC_JSON As String) Try @@ -283,7 +361,7 @@ Public Class cTelotecAPI End Sub Function SafeParseDate(value As String) As Date? - If String.IsNullOrWhiteSpace(value) Then + If String.IsNullOrWhiteSpace(value) OrElse value = "null" Then Return Nothing End If Return Date.Parse(value) @@ -382,7 +460,7 @@ Public Class cTelotecAPI Public Property interfaceReferenceId As String Public Property ifcCustomerId As String Public Property dec2_ID As Integer - Public Property anmeldedatum As Date + Public Property anmeldedatum As Object Public Property lrn As String Public Property mrn As String Public Property totNet As Decimal @@ -391,21 +469,21 @@ Public Class cTelotecAPI Public Property flugInfo As String Public Property fillPackList_IND As Boolean Public Property memo As String - Public Property erstellDatum As Date + Public Property erstellDatum As Object Public Property erstellPersonalID As String Public Property declarationType As String Public Property additionalDeclarationType As String Public Property tirCarnetNumber As String - Public Property presentationOfTheGoodsDateAndTime As Date + Public Property presentationOfTheGoodsDateAndTime As Object Public Property security As Integer Public Property reducedDatasetIndicator As Boolean Public Property specificCircumstanceIndicator As String Public Property communicationLanguageAtDeparture As String Public Property bindingItinerary As Boolean - Public Property limitDate As Date - Public Property declarationAcceptanceDate As Date - Public Property releaseDate As Date - Public Property writeOffDate As Date + Public Property limitDate As Object + Public Property declarationAcceptanceDate As Object + Public Property releaseDate As Object + Public Property writeOffDate As Object Public Property countryOfDispatch As String Public Property countryOfDestination As String Public Property containerIndicator As Boolean @@ -425,7 +503,7 @@ Public Class cTelotecAPI Public Property customsOfficeOfDeparture As String Public Property customsOfficeOfDestinationDeclared As String Public Property customsOfficeOfPresentation As String - Public Property controlResult_Date As Date + Public Property controlResult_Date As Object Public Property controlResult_ControlledBy As String Public Property controlResult_Text As String Public Property controlResult_Code As String @@ -524,7 +602,7 @@ Public Class cTelotecAPI Public Class TransitOffice Public Property sequenceNumber As Integer Public Property referenceNumber As String - Public Property arrivalDateAndTimeEstimated As Date + Public Property arrivalDateAndTimeEstimated As Object End Class Public Class DepartureTransportMeans @@ -603,139 +681,6 @@ Public Class cTelotecAPI - 'Public Function ConvertTAMessageToTelotec(msg As TAMessage) As cTelotec_Anmeldung - ' Dim telotec As New cTelotec_Anmeldung() - - ' With msg - ' If .declarationContent IsNot Nothing Then - ' Dim decl = .declarationContent - - ' telotec.telanm_ART = "TA" - ' telotec.telanm_BezugsNr = .lrn - ' telotec.telanm_CRN = .mrn - ' telotec.MsgType = .msgType - ' telotec.Refs_LRN = .lrn - ' telotec.Refs_CRN = .mrn - - ' telotec.Mandant_ID = decl.mandant_ID - ' telotec.Referenz_ID = decl.interfaceReferenceId - ' telotec.dec_CreatePersonalID = decl.erstellPersonalID - ' telotec.dec_CreateDate = decl.erstellDatum - ' telotec.dec_Template_ID = decl.template_ID - ' telotec.dec_TotNet = decl.totNet - ' telotec.dec_TotNetSplit_IND = decl.totNetSplit_IND - ' telotec.dec_FillPackList_IND = decl.fillPackList_IND - ' telotec.dec_Memo = decl.memo - - ' telotec.Hea_DecTy = decl.declarationType - ' telotec.Hea_Simp = decl.reducedDatasetIndicator - ' telotec.Hea_DecDT = decl.declarationAcceptanceDate - ' telotec.Hea_WoffD = decl.writeOffDate - ' telotec.Hea_AccDT = decl.declarationAcceptanceDate - ' telotec.Hea_ProArrDT = decl.presentationOfTheGoodsDateAndTime - ' telotec.Hea_PlaDepDT = decl.presentationOfTheGoodsDateAndTime - ' telotec.Hea_TotGross = decl.grossMass - ' telotec.Hea_PayMet = decl.methodOfPayment - ' telotec.Hea_SecInd = decl.security - ' telotec.Hea_DestLNG = decl.countryOfDestination - ' telotec.Hea_DepLNG = decl.countryOfDispatch - ' telotec.Transp_InMo = decl.inlandModeOfTransport - ' telotec.Transp_BordMo = decl.modeOfTransportAtTheBorder - ' telotec.Transp_ContInd = decl.containerIndicator - ' telotec.Transp_DepIdnt = SafeFirst(decl.departureTransportMeans, Function(dt) dt.identificationNumber) - ' telotec.Transp_DepNat = SafeFirst(decl.departureTransportMeans, Function(dt) dt.nationality) - - ' ' Consignor/Consignee - ' telotec.ConorTra_Na = SafeGetName(decl.consignor) - ' telotec.ConorTra_Strt = decl.consignor?.streetAndNumber - ' telotec.ConorTra_Pst = decl.consignor?.postcode - ' telotec.ConorTra_Cty = decl.consignor?.city - ' telotec.ConorTra_Ctry = decl.consignor?.country - ' telotec.ConorTra_TIN = decl.consignor?.identificationNumber - - ' telotec.ConeeTra_Na = SafeGetName(decl.consignee) - ' telotec.ConeeTra_Strt = decl.consignee?.streetAndNumber - ' telotec.ConeeTra_Pst = decl.consignee?.postcode - ' telotec.ConeeTra_Cty = decl.consignee?.city - ' telotec.ConeeTra_Ctry = decl.consignee?.country - ' telotec.ConeeTra_TIN = decl.consignee?.identificationNumber - - ' telotec.Represent_Na = decl.representative?.contactPersonName - ' telotec.Represent_RIN = decl.representative?.identificationNumber - - ' telotec.Locs_Disp = decl.countryOfDispatch - ' telotec.Locs_Dest = decl.countryOfDestination - ' telotec.Locs_GdsLoc = decl.locationOfGoods_PlaceOfGoods - ' telotec.Locs_GdsLocCd = decl.locationOfGoods_CustomsOffice - - ' ' HouseConsignments inkl. ConsignmentItems und Packaging - ' If decl.houseConsignment IsNot Nothing Then - ' telotec.HouseConsignments = New List(Of cTelotec_HouseConsignment)() - ' For Each hc In decl.houseConsignment - ' Dim newHc As New cTelotec_HouseConsignment() - ' newHc.CountryOfDispatch = hc.countryOfDispatch - ' newHc.CountryOfDestination = hc.countryOfDestination - ' newHc.GrossMass = hc.grossMass - ' newHc.ReferenceNumberUCR = hc.referenceNumberUCR - ' newHc.MethodOfPayment = hc.methodOfPayment - - ' If hc.consignmentItem IsNot Nothing Then - ' newHc.ConsignmentItems = New List(Of cTelotec_ConsignmentItem)() - ' For Each item In hc.consignmentItem - ' Dim newItem As New cTelotec_ConsignmentItem() - ' newItem.GoodsItemNumber = item.goodsItemNumber - ' newItem.DeclarationGoodsItemNumber = item.declarationGoodsItemNumber - ' newItem.DeclarationType = item.declarationType - ' newItem.CountryOfDispatch = item.countryOfDispatch - ' newItem.CountryOfDestination = item.countryOfDestination - ' newItem.DescriptionOfGoods = item.descriptionOfGoods - ' newItem.GrossMass = item.grossMass - ' newItem.NetMass = item.netMass - ' newItem.MethodOfPayment = item.methodOfPayment - ' newItem.ReferenceNumberUCR = item.referenceNumberUCR - - ' If item.packaging IsNot Nothing Then - ' newItem.Packaging = New List(Of cTelotec_Packaging)() - ' For Each pack In item.packaging - ' Dim newPack As New cTelotec_Packaging() - ' newPack.TypeOfPackages = pack.typeOfPackages - ' newPack.NumberOfPackages = pack.numberOfPackages - ' newPack.ShippingMarks = pack.shippingMarks - ' newItem.Packaging.Add(newPack) - ' Next - ' End If - - ' newHc.ConsignmentItems.Add(newItem) - ' Next - ' End If - - ' telotec.HouseConsignments.Add(newHc) - ' Next - ' End If - ' End If - ' End With - - ' telotec.telanm_LetzteBearbeitung = Now - ' telotec.telanm_Erstellung = Now - ' telotec.telanm_Erstellung_SB = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID - ' telotec.telanm_LetzteBearbeitung_SB = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID - ' telotec.ComIndicator = True - ' telotec.initData() - - ' Return telotec - 'End Function - - 'Private Function SafeFirst(Of T, R)(list As List(Of T), selector As Func(Of T, R)) As R - ' If list Is Nothing OrElse list.Count = 0 Then Return Nothing - ' Return selector(list(0)) - 'End Function - - 'Private Function SafeGetName(party As Object) As String - ' If party Is Nothing Then Return Nothing - ' Return If(party?.consignorName, party?.consigneeName, "") - 'End Function - - End Class From 52ffb6feb43360de0b709fcf983ff15df6cfcf13 Mon Sep 17 00:00:00 2001 From: Andreas Luxbauer Date: Thu, 24 Apr 2025 17:07:14 +0200 Subject: [PATCH 2/2] vers --- SDL/My Project/AssemblyInfo.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SDL/My Project/AssemblyInfo.vb b/SDL/My Project/AssemblyInfo.vb index 77446643..210c6039 100644 --- a/SDL/My Project/AssemblyInfo.vb +++ b/SDL/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - - + +