20231114 - Perto da conclusão
This commit is contained in:
parent
97b8b1c3a6
commit
f8963096ef
86
Program.cs
86
Program.cs
@ -13,6 +13,7 @@ class Program
|
|||||||
{
|
{
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Console.Clear();
|
||||||
// URL da API que você deseja chamar
|
// URL da API que você deseja chamar
|
||||||
string apiUrl = "https://api.pipefy.com/graphql";
|
string apiUrl = "https://api.pipefy.com/graphql";
|
||||||
string PipefyToken = "eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJQaXBlZnkiLCJpYXQiOjE2OTg4NTYyMjcsImp0aSI6IjM2N2Y4M2NhLWZjODYtNGRhOC04ODEyLTkzODRkZGZkODc0MiIsInN1YiI6MzAyNTM0MzY2LCJ1c2VyIjp7ImlkIjozMDI1MzQzNjYsImVtYWlsIjoiYmFjazVAZW5lcmdpYXNtYXJ0LmNvbS5iciIsImFwcGxpY2F0aW9uIjozMDAyODkyNDgsInNjb3BlcyI6W119LCJpbnRlcmZhY2VfdXVpZCI6bnVsbH0.o13j9c_y3G3HX35qhX4PmkkibGsmlHsk5dL_Bxsr1CKV5Jlgj218kJdEmriS7aHiw0-P7sfs-bu4YcElfuyiqg";
|
string PipefyToken = "eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJQaXBlZnkiLCJpYXQiOjE2OTg4NTYyMjcsImp0aSI6IjM2N2Y4M2NhLWZjODYtNGRhOC04ODEyLTkzODRkZGZkODc0MiIsInN1YiI6MzAyNTM0MzY2LCJ1c2VyIjp7ImlkIjozMDI1MzQzNjYsImVtYWlsIjoiYmFjazVAZW5lcmdpYXNtYXJ0LmNvbS5iciIsImFwcGxpY2F0aW9uIjozMDAyODkyNDgsInNjb3BlcyI6W119LCJpbnRlcmZhY2VfdXVpZCI6bnVsbH0.o13j9c_y3G3HX35qhX4PmkkibGsmlHsk5dL_Bxsr1CKV5Jlgj218kJdEmriS7aHiw0-P7sfs-bu4YcElfuyiqg";
|
||||||
@ -22,7 +23,7 @@ class Program
|
|||||||
string? cursor = "null";
|
string? cursor = "null";
|
||||||
|
|
||||||
string query = $"{{\"query\":\"query GetRecords($cursor: String){{ table_records(table_id: \\\"{PipefyTokenTableID}\\\",first:50,after:$cursor){{ pageInfo{{ hasNextPage endCursor }} edges{{ node{{ record_fields{{ field {{ id }} value array_value }} }} }} }}}}\",\"variables\":{{\"cursor\":{cursor}}}}}";
|
string query = $"{{\"query\":\"query GetRecords($cursor: String){{ table_records(table_id: \\\"{PipefyTokenTableID}\\\",first:50,after:$cursor){{ pageInfo{{ hasNextPage endCursor }} edges{{ node{{ record_fields{{ field {{ id }} value array_value }} }} }} }}}}\",\"variables\":{{\"cursor\":{cursor}}}}}";
|
||||||
Console.WriteLine(query);
|
//Console.WriteLine(query);
|
||||||
bool hasNextPage = true;
|
bool hasNextPage = true;
|
||||||
bool hasSucceeded = true;
|
bool hasSucceeded = true;
|
||||||
JArray allRecords = new JArray();
|
JArray allRecords = new JArray();
|
||||||
@ -45,9 +46,12 @@ class Program
|
|||||||
var responseContent = await response.Content.ReadAsStringAsync();
|
var responseContent = await response.Content.ReadAsStringAsync();
|
||||||
var responseData = JObject.Parse(responseContent);
|
var responseData = JObject.Parse(responseContent);
|
||||||
|
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
var records = responseData["data"]["table_records"]["edges"];
|
var records = responseData["data"]["table_records"]["edges"];
|
||||||
foreach (var record in records)
|
foreach (var record in records)
|
||||||
{
|
{
|
||||||
|
//Console.WriteLine(record);
|
||||||
allRecords.Add(record);
|
allRecords.Add(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,26 +67,32 @@ class Program
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
if (hasSucceeded)
|
if (hasSucceeded)
|
||||||
{
|
{
|
||||||
string strJson = JsonConvert.SerializeObject(allRecords);
|
string strJson = JsonConvert.SerializeObject(allRecords);
|
||||||
// Desserialize o JSON em objetos C#
|
// Desserialize o JSON em objetos C#
|
||||||
var jsonData = JsonConvert.DeserializeObject<Pipefy.RootObject>(strJson);
|
var jsonData = JsonConvert.DeserializeObject<List<Pipefy.RootObject>>(strJson);
|
||||||
|
|
||||||
|
List<ClasseEmpresas> jsonList = convertJson(jsonData);
|
||||||
|
|
||||||
// Consulte os dados da tabela no banco de dados Access
|
// Consulte os dados da tabela no banco de dados Access
|
||||||
List<ClasseEmpresas> databaseData = GetDataFromDatabase(ConnSourcePath);
|
List<ClasseEmpresas> databaseData = GetDataFromDatabase(ConnSourcePath);
|
||||||
|
|
||||||
// Compare os dados e encontre os registros ausentes no JSON
|
// Compare os dados e encontre os registros ausentes no JSON
|
||||||
List<ClasseEmpresas> recordsMissingInJson = CompareData(databaseData, jsonData);
|
List<ClasseEmpresas> recordsMissingInJson = CompareData(databaseData, jsonList);
|
||||||
|
|
||||||
|
if (recordsMissingInJson.Count == 0) { Console.WriteLine("Sem registros");}
|
||||||
|
|
||||||
// Faça algo com os registros ausentes
|
// Faça algo com os registros ausentes
|
||||||
foreach (var record in recordsMissingInJson)
|
foreach (var record in recordsMissingInJson)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Registro ausente no JSON - ID: {record.c_odigo_smart}, Nome: {record.nome_da_empresa}");
|
Console.WriteLine($"Registro ausente no JSON - ID: {record.c_digo_smart}, Nome: {record.nome_da_empresa}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<ClasseEmpresas> GetDataFromDatabase(string ConnSourcePath)
|
static List<ClasseEmpresas> GetDataFromDatabase(string ConnSourcePath)
|
||||||
{
|
{
|
||||||
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ConnSourcePath;
|
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ConnSourcePath;
|
||||||
@ -102,7 +112,7 @@ class Program
|
|||||||
{
|
{
|
||||||
ClasseEmpresas record = new ClasseEmpresas
|
ClasseEmpresas record = new ClasseEmpresas
|
||||||
{
|
{
|
||||||
c_odigo_smart = (int)reader["Código Smart"],
|
c_digo_smart = (string)reader["Código Smart"].ToString(),
|
||||||
nome_da_empresa = (string)reader["Nome da empresa"],
|
nome_da_empresa = (string)reader["Nome da empresa"],
|
||||||
modalidade = (string)reader["modalidade"],
|
modalidade = (string)reader["modalidade"],
|
||||||
gestores = (string)reader["gestores"],
|
gestores = (string)reader["gestores"],
|
||||||
@ -117,23 +127,69 @@ class Program
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
static List<ClasseEmpresas> convertJson(List<Pipefy.RootObject> jsonData)
|
||||||
static List<ClasseEmpresas> CompareData(List<ClasseEmpresas> databaseData, Pipefy.RootObject jsonData)
|
|
||||||
{
|
{
|
||||||
if (jsonData == null)
|
List<ClasseEmpresas> data = new List<ClasseEmpresas>();
|
||||||
|
|
||||||
|
for (int i = 0;i<jsonData.Count;i++)
|
||||||
|
{
|
||||||
|
ClasseEmpresas record = new ClasseEmpresas();
|
||||||
|
for (int j = 0;j < jsonData[i].node.record_fields.Length;j++)
|
||||||
|
{
|
||||||
|
switch (jsonData[i].node.record_fields[j].field.id)
|
||||||
|
{
|
||||||
|
case "nome_da_empresa":
|
||||||
|
record.nome_da_empresa = jsonData[i].node.record_fields[j].value;
|
||||||
|
break;
|
||||||
|
case "c_digo_smart":
|
||||||
|
record.c_digo_smart = jsonData[i].node.record_fields[j].value.Replace(".0","");
|
||||||
|
break;
|
||||||
|
case "modalidade":
|
||||||
|
record.modalidade = jsonData[i].node.record_fields[j].value;
|
||||||
|
break;
|
||||||
|
case "gestores":
|
||||||
|
record.gestores = jsonData[i].node.record_fields[j].value;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adicione outras propriedades conforme necessário
|
||||||
|
data.Add(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<ClasseEmpresas> CompareData(List<ClasseEmpresas> databaseData, List<ClasseEmpresas> jsonList)
|
||||||
|
{
|
||||||
|
if (jsonList == null)
|
||||||
{
|
{
|
||||||
return databaseData;
|
return databaseData;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ClasseEmpresas> recordsMissingInJson = new List<ClasseEmpresas>();
|
List<ClasseEmpresas> recordsMissingInJson = new List<ClasseEmpresas>();
|
||||||
|
var exists = false;
|
||||||
|
|
||||||
foreach (var record in databaseData)
|
foreach (var record in databaseData)
|
||||||
{
|
{
|
||||||
//if (jsonData.node.Any(item => item.recordFields[0].value.ToString() == record.c_odigo_smart.ToString()))
|
exists = false;
|
||||||
//{
|
|
||||||
// continue;
|
for (var j = 0; j < jsonList.Count; j++) {
|
||||||
//}
|
|
||||||
recordsMissingInJson.Add(record);
|
//Console.WriteLine(jsonList[j].c_digo_smart.ToString().Replace(".0", "") + " - " + record.c_digo_smart.ToString() + " - " + (jsonList[j].c_digo_smart.ToString().Replace(".0", "") == record.c_digo_smart.ToString()));
|
||||||
|
|
||||||
|
if (jsonList[j].c_digo_smart.ToString().Replace(".0", "") == record.c_digo_smart.ToString())
|
||||||
|
{
|
||||||
|
exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
if (exists == false) { recordsMissingInJson.Add(record); }
|
||||||
}
|
}
|
||||||
|
|
||||||
return recordsMissingInJson;
|
return recordsMissingInJson;
|
||||||
@ -144,7 +200,7 @@ class Program
|
|||||||
|
|
||||||
class ClasseEmpresas
|
class ClasseEmpresas
|
||||||
{
|
{
|
||||||
public int c_odigo_smart { get; set; }
|
public string c_digo_smart { get; set; }
|
||||||
public string nome_da_empresa { get; set; }
|
public string nome_da_empresa { get; set; }
|
||||||
public string modalidade { get; set; }
|
public string modalidade { get; set; }
|
||||||
public string gestores { get; set; }
|
public string gestores { get; set; }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user