ZUGFeRDService: Fix updating rejection status

This commit is contained in:
Jonathan Jenne 2022-07-07 13:53:09 +02:00
parent 3658326547
commit 55e484308c
2 changed files with 21 additions and 10 deletions

View File

@ -29,6 +29,10 @@
''' there's no size limit. ''' there's no size limit.
''' </summary> ''' </summary>
Public Property MaxAttachmentSizeInMegaBytes As Integer = -1 Public Property MaxAttachmentSizeInMegaBytes As Integer = -1
Public Property RejectionTransferTimeUnit As String = "HOUR"
Public Property RejectionTransferTimeValue As Integer = 12
End Class End Class
Public Class FirebirdConfig Public Class FirebirdConfig

View File

@ -142,12 +142,12 @@ Public Class ThreadRunner
Private Sub MaybeUpdateRejected() Private Sub MaybeUpdateRejected()
Try Try
Dim oTimeUnit = "HOUR" Dim oTimeUnit = _config.Config.Custom.RejectionTransferTimeUnit
Dim oTimeValue = 12 Dim oTimeValue = _config.Config.Custom.RejectionTransferTimeValue
Dim oDifference As TimeSpan = Now - RejectedLastRun Dim oDifference As TimeSpan = Now - RejectedLastRun
If oDifference.TotalMinutes < RejectedMaxDifferenceInMinutes Then If oDifference.TotalMinutes < RejectedMaxDifferenceInMinutes Then
_logger.Info("Updating rejected files: Waiting for next run.") _logger.Debug("Updating rejected files: Waiting for next run.")
Exit Sub Exit Sub
End If End If
@ -156,20 +156,27 @@ Public Class ThreadRunner
Dim oSQL = $" Dim oSQL = $"
SELECT [EMAIL_MSGID] SELECT [EMAIL_MSGID]
FROM TBEMLP_HISTORY FROM TBEMLP_HISTORY
WHERE (STATUS = 'REJECTED' OR CUST_REJECTED = 1) WHERE (STATUS = 'REJECTED' OR CUST_REJECTED = 1) AND FB_UPDATED = 0
AND DATEDIFF({oTimeUnit}, CHANGED_WHEN, GETDATE()) <= {oTimeValue} AND DATEDIFF({oTimeUnit}, CHANGED_WHEN, GETDATE()) <= {oTimeValue}
ORDER BY GUID DESC" ORDER BY GUID DESC"
Dim oDT As DataTable = _mssql.GetDatatable(oSQL) Dim oTable As DataTable = _mssql.GetDatatable(oSQL)
If Not IsNothing(oDT) Then If Not IsNothing(oTable) Then
For Each oROW As DataRow In oDT.Rows For Each oROW As DataRow In oTable.Rows
Dim oUpdate = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET REJECTED = True WHERE MESSAGE_ID = '{oROW.Item(0)}' and REJECTED = false" Dim oUpdate = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET REJECTED = True WHERE MESSAGE_ID = '{oROW.Item(0)}' and REJECTED = false"
_firebird.ExecuteNonQuery(oUpdate) If _firebird.ExecuteNonQuery(oUpdate) = True Then
Dim oUpdateSQL = $"
UPDATE TBEMLP_HISTORY
SET FB_UPDATED = 1
WHERE [EMAIL_MSGID] = '{oROW.Item(0)}' AND FB_UPDATED = 0"
_mssql.ExecuteNonQuery(oUpdateSQL)
End If
Next Next
RejectedLastRun = Now
End If End If
Catch ex As Exception Catch ex As Exception
_logger.Warn("Error while Updating REJECTED State: " & ex.Message) _logger.Warn("Error while Updating REJECTED State: " & ex.Message)
Finally
RejectedLastRun = Now
End Try End Try
End Sub End Sub