Adicionada a função GetErrorText para validar os textos de erro e escolhe o mais adequado para inserir no BD.
This commit is contained in:
parent
a870debbc3
commit
496ed11510
@ -169,7 +169,7 @@ namespace Webhook_4docs
|
|||||||
case ("FATURA DUPLICADA NO BD"):
|
case ("FATURA DUPLICADA NO BD"):
|
||||||
status_id = 4;
|
status_id = 4;
|
||||||
break;
|
break;
|
||||||
case ("UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD"):
|
case ("UNIDADE CONSUMIDORA N<EFBFBD>O LOCALIZADA NO BD"):
|
||||||
status_id = 5;
|
status_id = 5;
|
||||||
break;
|
break;
|
||||||
case ("FATURA INCLUIDA NO BD"):
|
case ("FATURA INCLUIDA NO BD"):
|
||||||
@ -191,7 +191,7 @@ namespace Webhook_4docs
|
|||||||
|
|
||||||
if (status_id != 4)
|
if (status_id != 4)
|
||||||
{
|
{
|
||||||
fatura_arquivo = IndexedFilename($@"{path}\ID {fatura_ID!} - Mês {fatura.Mes} - Empresa {fatura.Empresa} - Unidade {fatura.Unidade}", "pdf");
|
fatura_arquivo = IndexedFilename($@"{path}\ID {fatura_ID!} - M<EFBFBD>s {fatura.Mes} - Empresa {fatura.Empresa} - Unidade {fatura.Unidade}", "pdf");
|
||||||
CriarArquivo(fatura_arquivo, JsonBody.GetProperty("pdfFile").ToString());
|
CriarArquivo(fatura_arquivo, JsonBody.GetProperty("pdfFile").ToString());
|
||||||
|
|
||||||
var DatabaseModel = new ProcessedInvoices
|
var DatabaseModel = new ProcessedInvoices
|
||||||
@ -202,7 +202,7 @@ namespace Webhook_4docs
|
|||||||
InvoicePath = fatura_arquivo
|
InvoicePath = fatura_arquivo
|
||||||
};
|
};
|
||||||
|
|
||||||
logger.LogInformation("Fatura incluída no BD");
|
logger.LogInformation("Fatura inclu<EFBFBD>da no BD");
|
||||||
|
|
||||||
logger.LogInformation("Fatura salva na pasta " + fatura_arquivo);
|
logger.LogInformation("Fatura salva na pasta " + fatura_arquivo);
|
||||||
|
|
||||||
@ -244,15 +244,16 @@ namespace Webhook_4docs
|
|||||||
errorID = 3;
|
errorID = 3;
|
||||||
break;
|
break;
|
||||||
case (true, _):
|
case (true, _):
|
||||||
//logger.LogInformation("Loc ID: " + JsonBody.GetProperty("locationID").ToString() + " está saudável");
|
//logger.LogInformation("Loc ID: " + JsonBody.GetProperty("locationID").ToString() + " est<EFBFBD> saud<75>vel");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await UpdateErrorIdStatusAsync(CaminhoDB, JsonBody.GetProperty("locationID").GetInt64(), errorID, (JsonBody.GetProperty("systemText").ToString() == "" ? JsonBody.GetProperty("websiteText").ToString() : JsonBody.GetProperty("systemText").ToString()), logger);
|
var errorText = GetErrorText(JsonBody);
|
||||||
|
await UpdateErrorIdStatusAsync(CaminhoDB, JsonBody.GetProperty("locationID").GetInt64(), errorID, errorText, logger);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//implementação futura para receber as faturas enviadas via api de forma assíncrona - Upload4Docs (substituir parte do agendador de tarefas)
|
//implementa<EFBFBD><EFBFBD>o futura para receber as faturas enviadas via api de forma ass<73>ncrona - Upload4Docs (substituir parte do agendador de tarefas)
|
||||||
endpoints.MapPut("/api", async context =>
|
endpoints.MapPut("/api", async context =>
|
||||||
{
|
{
|
||||||
var a = 10;
|
var a = 10;
|
||||||
@ -260,6 +261,30 @@ namespace Webhook_4docs
|
|||||||
});
|
});
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
//tenta pegar o deactivationReport, se não conseguir ou for null, tenta pegar o websiteText, se não conseguir ou for null, tenta pegar o systemText. As propriedades podem não exisir
|
||||||
|
public static string GetErrorText(JsonElement root)
|
||||||
|
{
|
||||||
|
string errorText = string.Empty;
|
||||||
|
|
||||||
|
if (root.TryGetProperty("deactivationReport", out JsonElement deactivationReportElement) && deactivationReportElement.ValueKind != JsonValueKind.Null)
|
||||||
|
{
|
||||||
|
errorText = deactivationReportElement.ToString();
|
||||||
|
}
|
||||||
|
else if (root.TryGetProperty("websiteText", out JsonElement websiteTextElement) && websiteTextElement.ValueKind != JsonValueKind.Null)
|
||||||
|
{
|
||||||
|
errorText = websiteTextElement.ToString();
|
||||||
|
}
|
||||||
|
else if (root.TryGetProperty("systemText", out JsonElement systemTextElement) && systemTextElement.ValueKind != JsonValueKind.Null)
|
||||||
|
{
|
||||||
|
errorText = systemTextElement.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errorText = "Erro desconhecido";
|
||||||
|
}
|
||||||
|
|
||||||
|
return errorText;
|
||||||
|
}
|
||||||
public static async Task<int> UpdateErrorIdStatusAsync(string CaminhoDB, double location_id, double errorID, string systemText, ILogger logger)
|
public static async Task<int> UpdateErrorIdStatusAsync(string CaminhoDB, double location_id, double errorID, string systemText, ILogger logger)
|
||||||
{
|
{
|
||||||
int test = 0;
|
int test = 0;
|
||||||
@ -283,7 +308,7 @@ namespace Webhook_4docs
|
|||||||
SET errorID = @errorID, status = @status
|
SET errorID = @errorID, status = @status
|
||||||
WHERE location_id = @location_id", conn))
|
WHERE location_id = @location_id", conn))
|
||||||
{
|
{
|
||||||
// Adiciona parâmetros de forma segura
|
// Adiciona par<EFBFBD>metros de forma segura
|
||||||
cmd.Parameters.AddWithValue("@errorID", errorID);
|
cmd.Parameters.AddWithValue("@errorID", errorID);
|
||||||
cmd.Parameters.AddWithValue("@status", systemText);
|
cmd.Parameters.AddWithValue("@status", systemText);
|
||||||
cmd.Parameters.AddWithValue("@location_id", location_id);
|
cmd.Parameters.AddWithValue("@location_id", location_id);
|
||||||
@ -307,7 +332,7 @@ namespace Webhook_4docs
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Propaga a exceção na última tentativa
|
// Propaga a exce<EFBFBD><EFBFBD>o na <20>ltima tentativa
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -316,11 +341,11 @@ namespace Webhook_4docs
|
|||||||
connLease.Dispose();
|
connLease.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
attempt++; // Incrementa a tentativa após adquirir o lease, mesmo que falhe
|
attempt++; // Incrementa a tentativa ap<EFBFBD>s adquirir o lease, mesmo que falhe
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Aguarda um curto período antes de tentar novamente se não conseguiu adquirir o lease
|
// Aguarda um curto per<EFBFBD>odo antes de tentar novamente se n<>o conseguiu adquirir o lease
|
||||||
await Task.Delay(200);
|
await Task.Delay(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user