CBAM kafka, NCTS Fremd(Tobb), realyhub

This commit is contained in:
2025-10-23 11:33:14 +02:00
parent e0c06d3c2f
commit 6d1e68157d
22 changed files with 1973 additions and 23 deletions

View File

@@ -23,8 +23,8 @@ Public Class cATEZ_Greenpulse_KafkaDecs
'== Kafka: Konfiguration (Klassenebene)
'========================
Public Shared BootstrapServers As String = "192.168.85.250:9092" 'http://192.168.85.250:8888
Public Shared TopicName As String = "greenpulse.declarationdata.v1"
' Public Shared TopicName As String = "dev.greenpulse.declarationdata.v1"
' Public Shared TopicName As String = "greenpulse.declarationdata.v1"
Public Shared TopicName As String = "dev.greenpulse.declarationdata.v1"
' Falls SASL/TLS benötigt:
Public Shared UseSasl As Boolean = False
Public Shared SaslUsername As String = ""
@@ -66,6 +66,11 @@ Public Class cATEZ_Greenpulse_KafkaDecs
<JsonProperty("importerDetails")>
Public Property ImporterDetails As ImporterDetailsNode
'--- documents ---
<JsonProperty("documents")>
Public Property Documents As List(Of DocumentNode)
'--- declaration ---
Public Class DeclarationNode
<JsonProperty("declarationsourceId")>
@@ -201,6 +206,19 @@ Public Class cATEZ_Greenpulse_KafkaDecs
<JsonProperty("importerCoordinateLatitudeY")>
Public Property ImporterCoordinateLatitudeY As String
End Class
Public Class DocumentNode
<JsonProperty("reference")>
Public Property Reference As String
<JsonProperty("doc-type")>
Public Property DocType As String
<JsonProperty("mime-type")>
Public Property MimeType As String
<JsonProperty("blob")>
Public Property Blob As String
End Class
'========================
'== Serialisierung
@@ -267,7 +285,8 @@ Public Class cATEZ_Greenpulse_KafkaDecs
.ImporterPoBox = "PO DCL-123",
.ImporterCoordinateLongitudeX = "41.0091982",
.ImporterCoordinateLatitudeY = "28.9662187"
}
},
.Documents = New List(Of cATEZ_Greenpulse_KafkaDecs.DocumentNode)()
}
End Function
@@ -298,6 +317,8 @@ Public Class cATEZ_Greenpulse_KafkaDecs
.MaxInFlight = 5,
.MessageTimeoutMs = Math.Max(waitMs, 60000),
.RequestTimeoutMs = 30000,
.CompressionType = Confluent.Kafka.CompressionType.Zstd, ' gute Kompression
.MessageMaxBytes = 20971520, ' ≈ 20 MB darf Topic/Broker nicht übersteigen
.EnableDeliveryReports = True,
.AllowAutoCreateTopics = True
}
@@ -379,7 +400,7 @@ Public Class cATEZ_Greenpulse_KafkaDecsBuilder_DAKOSY
Dim obj As New cATEZ_Greenpulse_KafkaDecs() With {
.Declaration = New cATEZ_Greenpulse_KafkaDecs.DeclarationNode() With {
.DeclarationSourceId = SafeStr(head("Bezugsnummer_LRN")),
.DeclarationSourceId = SafeStr(head("Registriernummer_MRN")),
.DeclarationNo = SafeStr(head("Registriernummer_MRN")),
.DeclarationDate = FirstNonEmptyDateStr(head, {"Annahmedatum", "Überlassungsdatum"}),
.RequestedProcedure = SafeStr(head("Verfahren")),
@@ -412,7 +433,8 @@ Public Class cATEZ_Greenpulse_KafkaDecsBuilder_DAKOSY
.ImporterPoBox = "",
.ImporterCoordinateLongitudeX = "",
.ImporterCoordinateLatitudeY = ""
}
},
.Documents = New List(Of cATEZ_Greenpulse_KafkaDecs.DocumentNode)()
}
' 2) Commercial (Rechnung) aus Unterlagen N380, falls vorhanden
@@ -424,6 +446,38 @@ Public Class cATEZ_Greenpulse_KafkaDecsBuilder_DAKOSY
.DefaultIfEmpty(Nothing) _
.FirstOrDefault()
' --- Dokumente aus Unterlagen übernehmen ---
Dim SQLS As New VERAG_PROG_ALLGEMEIN.SQL
Dim SenungsId = SQLS.getValueTxtBySql("SELECT dy_SendungsId from [tblDakosy_Zollanmeldungen] where dy_BezugsNr=''", "FMZOLL",,, Nothing)
If SenungsId IsNot Nothing Then
If IsNumeric(SenungsId) AndAlso SenungsId > 0 Then
Dim ANH_LIST As New List(Of cAvisoAnhaenge)
cAvisoAnhaenge.LOAD_LIST_BySendung(ANH_LIST, SenungsId)
For Each doc In ANH_LIST
Select Case doc.anh_Art
Case "Rechnung", "eFatura"
Dim dateiBytes As Byte() = System.IO.File.ReadAllBytes(VERAG_PROG_ALLGEMEIN.cDATENSERVER.GET_PDFPath_BY_DocID(doc.anh_docId))
Dim d As New cATEZ_Greenpulse_KafkaDecs.DocumentNode With {
.Reference = doc.anh_Name,
.DocType = "invoice",
.MimeType = cATEZ_Greenpulse_KafkaDecsBuilder_DAKOSY.GuessMimeTypeFromNumber(doc.anh_Typ),
.Blob = Convert.ToBase64String(dateiBytes)
}
obj.Documents.Add(d)
End Select
Next
End If
End If
If invRow IsNot Nothing Then
obj.Commercial.InvoiceNumbers = SafeStr(invRow("Unterlagennummer"))
obj.Commercial.InvoiceDate = SafeDateStr(invRow("Unterlagendatum"))
@@ -519,4 +573,15 @@ Public Class cATEZ_Greenpulse_KafkaDecsBuilder_DAKOSY
Return String.IsNullOrWhiteSpace(Convert.ToString(value))
End Function
Public Shared Function GuessMimeTypeFromNumber(num As Object) As String
' Wenn du Dateiendungen erkennst (z. B. .pdf oder .jpg im Namen)
Dim s As String = SafeStr(num).ToLowerInvariant()
If s.EndsWith(".pdf") Or s.ToLower = "PDF" Then Return "application/pdf"
If s.EndsWith(".jpg") Or s.EndsWith(".jpeg") Or s.ToLower = "JPG" Or s.ToLower = "JPEG" Then Return "image/jpeg"
If s.EndsWith(".png") Or s.ToLower = "PNG" Then Return "image/png"
Return "application/octet-stream"
End Function
End Class

View File

@@ -62,7 +62,7 @@ Public Class cRelayHub
Public Class cRelayHubAddress
Public Property addressType As String
Public Property participantEORI As String
Public Property participantSubsidiaryNumber As String
Public Property participantSubsidiaryNumber As Integer
Public Property companyName As String
Public Property streetAndNumber As String
Public Property countryCode As String
@@ -131,7 +131,21 @@ Public Class cRelayHub
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim jsonPayload As String = JsonConvert.SerializeObject(request)
Dim sanitized = Sanitize(request)
Dim settings As New JsonSerializerSettings With {
.NullValueHandling = NullValueHandling.Ignore,
.ContractResolver = New Newtonsoft.Json.Serialization.DefaultContractResolver With {
.NamingStrategy = New Newtonsoft.Json.Serialization.CamelCaseNamingStrategy()
}
}
Dim jsonPayload As String = JsonConvert.SerializeObject(sanitized, settings)
Console.WriteLine("JSON → " & jsonPayload)
'Dim jsonPayload As String = JsonConvert.SerializeObject(request)
' 1. Versuch
Dim response As Chilkat.HttpResponse = SendJobOrder(jsonPayload)
@@ -208,6 +222,26 @@ Public Class cRelayHub
End Try
End Function
Private Shared Function Sanitize(req As cRelayHub.cRelayHubJobOrderRequest) As cRelayHub.cRelayHubJobOrderRequest
req.outputApplication = If(req.outputApplication, "").Trim()
req.dispatchCountry = If(req.dispatchCountry, "").Trim().ToUpperInvariant()
req.destinationCountry = If(req.destinationCountry, "").Trim().ToUpperInvariant()
' lokale Fail-fast Checks
If req.dispatchCountry.Length <> 2 Then Throw New ApplicationException("dispatchCountry ISO-2 erforderlich.")
If req.destinationCountry.Length <> 2 Then Throw New ApplicationException("destinationCountry ISO-2 erforderlich.")
Dim allowed = New HashSet(Of String)(StringComparer.Ordinal) From {
"test", "dakosy/sftp/vera", "evrim/excel", "sec/import/integration"
}
If Not allowed.Contains(req.outputApplication) Then
Throw New ApplicationException("outputApplication muss 'test' | 'dakosy/sftp/vera' | 'evrim/excel' | 'sec/import/integration' sein.")
End If
If req.regimeType <> "IMPORT" AndAlso req.regimeType <> "EXPORT" Then
Throw New ApplicationException("regimeType muss 'IMPORT' oder 'EXPORT' sein.")
End If
Return req
End Function
' Beispielfall
Function CreateSampleJobOrderRequest() As cRelayHubJobOrderRequest
Dim req As New cRelayHubJobOrderRequest With {