- Remoção de log para contas "saudáveis"

- Adição de contas não encontradas à tabela de erros "AgVirtual4DocsErros"
This commit is contained in:
Adriano Serighelli 2024-04-19 14:53:08 -03:00
parent 1867a3c50f
commit 82d6df6a35

View File

@ -181,7 +181,7 @@ namespace Webhook_4docs
{
double errorID = 0;
switch (JsonBody.GetProperty("healthy").GetBoolean(), JsonBody.GetProperty("blame").ToString())
switch (JsonBody.GetProperty("healthy").GetBoolean(), JsonBody.GetProperty("blame").ToString().ToLower())
{
case (false, "user"):
logger.LogError("Loc ID: " + JsonBody.GetProperty("locationID").ToString() + " Sem acesso");
@ -196,40 +196,66 @@ namespace Webhook_4docs
errorID = 3;
break;
case (true, _):
logger.LogInformation("Loc ID: " + JsonBody.GetProperty("locationID").ToString() + " está saudável");
//logger.LogInformation("Loc ID: " + JsonBody.GetProperty("locationID").ToString() + " está saudável");
break;
}
UpdateErrorIdStatus(CaminhoDB, JsonBody.GetProperty("locationID").GetInt64(), errorID);
int test = UpdateErrorIdStatus(CaminhoDB, JsonBody.GetProperty("locationID").GetInt64(), errorID);
if (test == 0)
{
InsertErrorIdStatus(CaminhoDB, errorID, requestBody);
}
}
});
});
app.Run();
}
public static void UpdateErrorIdStatus(string CaminhoDB, double location_id, double errorID)
public static void InsertErrorIdStatus(string CaminhoDB, double errorID, string requestBody)
{
var JsonBody = JsonDocument.Parse(requestBody).RootElement;
double locationID = JsonBody.GetProperty("locationID").GetInt64() ;
string accountID = JsonBody.GetProperty("accountID").ToString() ;
string deliveryTimeStamp = JsonBody.GetProperty("deliveryTimestamp").ToString() ;
string provider = JsonBody.GetProperty("provider").ToString() ;
string accessPoint = JsonBody.GetProperty("accessPoint").ToString() ;
string slaStatus = JsonBody.GetProperty("slaStatus").ToString() ;
string healthy = JsonBody.GetProperty("healthy").ToString() ;
string blame = JsonBody.GetProperty("blame").ToString() ;
string lastSuccess = JsonBody.GetProperty("lastSuccess").ToString() ;
string active = JsonBody.GetProperty("active").ToString() ;
string blacklistStatus = JsonBody.GetProperty("blacklistStatus").ToString() ;
string lastActivated = JsonBody.GetProperty("lastActivated").ToString() ;
string lastDeactivated = JsonBody.GetProperty("lastDeactivated").ToString() ;
string lastDeactivatedBy = JsonBody.GetProperty("lastDeactivatedBy").ToString() ;
using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + CaminhoDB + ";Jet OLEDB:Database Password=gds21"))
{
conn.Open();
int test = 0;
using (OleDbCommand cmd = new OleDbCommand($"INSERT INTO AgVirtual4DocsErros (locationID, accountID, errorID, deliveryTimeStamp, provider, accessPoint, slaStatus, healthy, blame, lastSuccess, active, blacklistStatus, lastActivated, lastDeactivated, lastDeactivatedBy) VALUES ({locationID}, {accountID}, {errorID}, \'{deliveryTimeStamp}\', \'{provider}\', \'{accessPoint}\', \'{slaStatus}\', \'{healthy}\', \'{blame}\', \'{lastSuccess}\', \'{active}\', \'{blacklistStatus}\', \'{lastActivated}\', \'{lastDeactivated}\', \'{lastDeactivatedBy}\')", conn))
{
//cmd.Parameters.AddWithValue("@location_id", location_id);
//cmd.Parameters.AddWithValue("@errorID", errorID);
test = cmd.ExecuteNonQuery();
}
}
}
public static int UpdateErrorIdStatus(string CaminhoDB, double location_id, double errorID)
{
using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + CaminhoDB + ";Jet OLEDB:Database Password=gds21"))
{
conn.Open();
int test = 0;
using (OleDbCommand cmd = new OleDbCommand($"UPDATE AgVirtual4Docs SET AgVirtual4Docs.errorID = {errorID}\r\nWHERE (((AgVirtual4Docs.location_id)={location_id}));\r\n", conn))
{
//cmd.Parameters.AddWithValue("@location_id", location_id);
//cmd.Parameters.AddWithValue("@errorID", errorID);
int test = cmd.ExecuteNonQuery();
}
using (OleDbCommand cmd = new OleDbCommand($"SELECT location_id, errorID FROM AgVirtual4Docs WHERE location_id = @location_id", conn))
{
cmd.Parameters.AddWithValue("@location_id", location_id);
using (OleDbDataReader reader = cmd.ExecuteReader())
{
while(reader.Read())
{
string? test = reader["errorID"].ToString();
}
}
test = cmd.ExecuteNonQuery();
}
return test;
}
}
public static bool CriarArquivo(string fatura_arquivo, string pdfFile64)