MS Common

This commit is contained in:
Developer01
2025-05-09 16:51:31 +02:00
parent 773b43b1ad
commit 686b1a3a59
15 changed files with 113 additions and 34 deletions

View File

@@ -13,7 +13,7 @@ Imports System.Data.SqlClient
Imports DevExpress.XtraRichEdit.Layout.Engine
Namespace Jobs
Public Class SendInvitationMailJob
Public Class APIEnvelopeJob
Implements IJob
@@ -44,30 +44,29 @@ Namespace Jobs
myTempFiles = New TempFiles(LogConfig)
myTempFiles.Create()
Dim JobId = pContext.JobDetail.Key
Logger.Debug("SendInvMail - Starting job {0}", JobId)
Logger.Debug("API Envelopes - Starting job {0}", JobId)
Try
Logger.Debug("SendInvMail - Loading Database..")
Logger.Debug("API Envelopes - Loading Database..")
Database = GetDatabase(pContext, LogConfig)
Logger.Debug("SendInvMail - Loading Models & Services")
Logger.Debug("API Envelopes - Loading Models & Services")
Dim oState = GetState()
InitializeModels(oState)
Logger.Debug("SendInvMail - Loading Configuration..")
Logger.Debug("API Envelopes - Loading Configuration..")
Config = ConfigModel.LoadConfiguration()
oState.DbConfig = Config
InitializeServices(oState)
Config.DocumentPath = Config.DocumentPath
Logger.Debug("SendInvMail - ExportPath: [{0}]", Config.ExportPath)
Logger.Debug("API Envelopes - ExportPath: [{0}]", Config.ExportPath)
Dim oCompleteStatus As Integer = Constants.EnvelopeStatus.EnvelopeCompletelySigned
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE where SOURCE = 'API' AND STATUS = 1003 order by guid"
Dim oTable = Database.GetDatatable(oSql)
Dim oDTEnv_invitations = Database.GetDatatable(oSql)
Dim oEnvelopeIds As List(Of Integer) = oTable.Rows.Cast(Of DataRow).
Dim oEnvelopeIds As List(Of Integer) = oDTEnv_invitations.Rows.Cast(Of DataRow).
Select(Function(r) r.Item("GUID")).
Cast(Of Integer).
ToList()
@@ -83,10 +82,12 @@ Namespace Jobs
Logger.Info("SendInvMail - Gathering Info for Envelope [{0}] ({1}/{2})", oId, oCurrent, oTotal)
Try
Dim oEnvelope = EnvelopeModel.GetById(oId)
If oEnvelope Is Nothing Then
Logger.Warn("SendInvMail - Envelope could not be loaded for Id [{0}]!", oId)
Throw New ArgumentNullException("EnvelopeData")
End If
oEnvelope.CURRENT_WORK_APP = "signFLOW_API_EnvJob_InvMail"
Logger.Debug("SendInvMail - Loading Envelope Data..")
Dim oEnvelopeData = GetEnvelopeData(oId)
oEnvelope.Receivers = ReceiverModel.ListEnvelopeReceivers(oEnvelope.Id).ToList()
@@ -108,13 +109,63 @@ Namespace Jobs
Logger.Info("SendInvMail - Envelope finalized!")
Next
'Hier nun der Teil um zurückgezogene Envelopes abzuarbeiten
oSql = $"SELECT ENV.GUID,REJ.COMMENT REJECTION_REASON FROM
(SELECT * FROM TBSIG_ENVELOPE where STATUS = 1009 AND SOURCE = 'API') ENV INNER JOIN
(SELECT MAX(GUID) GUID,ENVELOPE_ID,MAX(ADDED_WHEN) ADDED_WHEN,MAX(ACTION_DATE) ACTION_DATE, COMMENT FROM TBSIG_ENVELOPE_HISTORY where STATUS = 1009 GROUP BY ENVELOPE_ID,COMMENT ) REJ ON ENV.GUID = REJ.ENVELOPE_ID LEFT JOIN
(SELECT * FROM TBSIG_ENVELOPE_HISTORY where STATUS = 3004 ) M_Send ON ENV.GUID = M_Send.ENVELOPE_ID
where M_Send.GUID IS NULL"
Dim oDT_EnvWithdrawn = Database.GetDatatable(oSql)
Logger.Debug("SendInvMail - Completed job {0} successfully!", JobId)
oEnvelopeIds = oDTEnv_invitations.Rows.Cast(Of DataRow).
Select(Function(r) r.Item("GUID")).
Cast(Of Integer).
ToList()
If oEnvelopeIds.Count > 0 Then
Logger.Info("WithdrawnEnv - Found [{0}] envelopes.", oEnvelopeIds.Count)
End If
oTotal = oEnvelopeIds.Count
oCurrent = 1
Dim oEnvID As Integer
For Each oRow As DataRow In oDT_EnvWithdrawn.Rows
oEnvID = oRow.Item("GUID")
Dim oReason = oRow.Item("REJECTION_REASON")
Logger.Info("WithdrawnEnv - Gathering Info for Envelope [{0}] ({1}/{2})", oEnvID, oCurrent, oTotal)
Try
Dim oEnvelope = EnvelopeModel.GetById(oEnvID)
If oEnvelope Is Nothing Then
Logger.Warn("WithdrawnEnv - Envelope could not be loaded for Id [{0}]!", oEnvID)
Throw New ArgumentNullException("EnvelopeData")
End If
oEnvelope.CURRENT_WORK_APP = "signFLOW_API_EnvJob_Withdrawn"
oEnvelope.Receivers = ReceiverModel.ListEnvelopeReceivers(oEnvelope.Id).ToList()
Logger.Debug("WithdrawnEnv - Sending Withdrawn Mails..")
If ActionService.API_SendWithdrawn_Mails(oEnvelope, oReason) = False Then
Logger.Warn("Could not send the Mails for withdrawn Envelope")
Else
Dim oStatInsert = $"INSERT INTO TBSIG_ENVELOPE_HISTORY (ENVELOPE_ID,STATUS,USER_REFERENCE,ADDED_WHEN,ACTION_DATE) VALUES ('{oEnvelope.Id}',3004,'API',GETDATE(),GETDATE())"
Database.ExecuteNonQuery(oStatInsert)
End If
Catch ex As Exception
Logger.Warn(ex, $"WithdrawnEnv - Unhandled exception while working envelope [{oEnvID}]")
End Try
oCurrent += 1
Logger.Info("WithdrawnEnv - Envelope finalized!")
Next
Logger.Debug("API Envelopes - Completed job {0} successfully!", JobId)
Catch ex As Exception
Logger.Warn("SendInvMail job failed!")
Logger.Warn("API Envelopes job failed!")
Logger.Error(ex)
Finally
Logger.Debug("SendInvMail execution for [{0}] ended", JobId)
Logger.Debug("API Envelopes execution for [{0}] ended", JobId)
End Try
Return Task.FromResult(True)