20231120 - conclusão iminente

This commit is contained in:
giuliano 2023-11-20 17:23:05 -03:00
parent 9f6a277f31
commit 589b09279d
2 changed files with 59 additions and 10 deletions

View File

@ -9,6 +9,9 @@ using Newtonsoft.Json.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using Pipefy; using Pipefy;
using Microsoft.VisualBasic;
using System.Net.Quic;
class Program class Program
{ {
static async Task Main(string[] args) static async Task Main(string[] args)
@ -29,7 +32,7 @@ class Program
{ {
string strGestores = JsonConvert.SerializeObject(allGestores); string strGestores = JsonConvert.SerializeObject(allGestores);
// Desserialize o JSON em objetos C# // Desserialize o JSON em objetos C#
var jsonGestores = JsonConvert.DeserializeObject<List<Pipefy.RootObject>>(strGestores); var jsonGestores = JsonConvert.DeserializeObject<List<Pipefy.RootGestor>>(strGestores);
List<Pipefy.ClasseGestores> jsonListGestores = convertGestoresJson(jsonGestores); List<Pipefy.ClasseGestores> jsonListGestores = convertGestoresJson(jsonGestores);
@ -47,6 +50,30 @@ class Program
if (recordsMissingInJson.Count != 0) if (recordsMissingInJson.Count != 0)
{ {
string strQuery = "{\"query\":\"mutation {\\r\\n ";
for (int i = 0; i < recordsMissingInJson.Count; i++)
{
if (i % 49 == 0) { strQuery = "{\"query\":\"mutation {\\r\\n "; }
strQuery = strQuery + $"N{i}: createTableRecord(input: {{ table_id: \\\"{PipefyTokenTableID}\\\", fields_attributes: [ {{ field_id: \\\"nome_da_empresa\\\", field_value: \\\"{recordsMissingInJson[i].nome_da_empresa.ToString()}\\\" }} {{ field_id: \\\"c_digo_smart\\\", field_value: \\\"{recordsMissingInJson[i].c_digo_smart.ToString()}\\\" }} {{ field_id: \\\"modalidade\\\", field_value: \\\"{recordsMissingInJson[i].modalidade.ToString()}\\\" }} {{ field_id: \\\"gestores\\\", field_value: \\\"{recordsMissingInJson[i].gestores.ToString()}\\\" }}]}}) {{ table_record {{ id }}}}\\r\\n ";
if (i % 48 == 0 && i != 0) {
strQuery = strQuery + "}\",\"variables\":{}}";
bool success = await CreatePipefyDataAsync(apiUrl, PipefyToken, PipefyTokenTableID, strQuery);
if (!success) {
int test2 = 10;
}
}
}
strQuery = strQuery + "}\",\"variables\":{}}";
bool success1 = await CreatePipefyDataAsync(apiUrl, PipefyToken, PipefyTokenTableID, strQuery);
// Faça algo com os registros ausentes // Faça algo com os registros ausentes
int maxCId = recordsMissingInJson.OrderByDescending(s => s.c_digo_smart.Length).First().c_digo_smart.Length; int maxCId = recordsMissingInJson.OrderByDescending(s => s.c_digo_smart.Length).First().c_digo_smart.Length;
int maxCNome = recordsMissingInJson.OrderByDescending(s => s.nome_da_empresa.Length).First().nome_da_empresa.Length; int maxCNome = recordsMissingInJson.OrderByDescending(s => s.nome_da_empresa.Length).First().nome_da_empresa.Length;
@ -66,6 +93,22 @@ class Program
} }
} }
private static async Task<bool> CreatePipefyDataAsync(string apiUrl, string PipefyToken, string PipefyTokenTableID, string query)
{
var httpClient = new HttpClient();
// Defina os headers da requisição (opcional)
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + PipefyToken);
var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
request.Headers.Add("Accept", "application/json");
var content = new StringContent(query, null, "application/json");
request.Content = content;
var response = await httpClient.SendAsync(request);
return response.IsSuccessStatusCode;
}
private static async Task<JArray> GetPipefyDataAsync(string apiUrl, string PipefyToken, string PipefyTokenTableID) private static async Task<JArray> GetPipefyDataAsync(string apiUrl, string PipefyToken, string PipefyTokenTableID)
{ {
JArray allRecords = new JArray(); JArray allRecords = new JArray();
@ -188,23 +231,21 @@ class Program
return data; return data;
} }
static List<Pipefy.ClasseGestores> convertGestoresJson(List<Pipefy.RootObject> jsonData) static List<Pipefy.ClasseGestores> convertGestoresJson(List<Pipefy.RootGestor> jsonData)
{ {
List<Pipefy.ClasseGestores> data = new List<Pipefy.ClasseGestores>(); List<Pipefy.ClasseGestores> data = new List<Pipefy.ClasseGestores>();
for (int i = 0; i < jsonData.Count; i++) for (int i = 0; i < jsonData.Count; i++)
{ {
Pipefy.ClasseGestores record = new Pipefy.ClasseGestores(); Pipefy.ClasseGestores record = new Pipefy.ClasseGestores();
record.id = jsonData[i].node.id.ToString();
for (int j = 0; j < jsonData[i].node.record_fields.Length; j++) for (int j = 0; j < jsonData[i].node.record_fields.Length; j++)
{ {
switch (jsonData[i].node.record_fields[j].field.id) if (jsonData[i].node.record_fields[j].field.id == "gest_o")
{ {
case "gestor":
record.id = jsonData[i].node.record_fields.ToString();
break;
case "gest_o":
record.gestores = jsonData[i].node.record_fields[j].value; record.gestores = jsonData[i].node.record_fields[j].value;
break;
} }
} }
@ -218,7 +259,7 @@ class Program
static List<Pipefy.ClasseEmpresas> CompareData(List<Pipefy.ClasseEmpresas> databaseData, List<Pipefy.ClasseEmpresas> jsonList, List<Pipefy.ClasseGestores> jsonListGestores) static List<Pipefy.ClasseEmpresas> CompareData(List<Pipefy.ClasseEmpresas> databaseData, List<Pipefy.ClasseEmpresas> jsonList, List<Pipefy.ClasseGestores> jsonListGestores)
{ {
if (jsonList == null) if (jsonList == null | jsonListGestores == null)
{ {
return databaseData; return databaseData;
} }

10
data.cs
View File

@ -10,6 +10,10 @@ namespace Pipefy
{ {
public Node node { get; set; } public Node node { get; set; }
} }
public class RootGestor
{
public NodeGestor node { get; set; }
}
public class Data public class Data
{ {
@ -20,7 +24,11 @@ namespace Pipefy
{ {
public Record_Fields[] record_fields { get; set; } public Record_Fields[] record_fields { get; set; }
} }
public class NodeGestor
{
public string id { get; set; }
public Record_Fields[] record_fields { get; set; }
}
public class Record_Fields public class Record_Fields
{ {
public Field field { get; set; } public Field field { get; set; }