20231120 - conclusão iminente
This commit is contained in:
parent
9f6a277f31
commit
589b09279d
59
Program.cs
59
Program.cs
@ -9,6 +9,9 @@ using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Metadata;
|
||||
using Pipefy;
|
||||
using Microsoft.VisualBasic;
|
||||
using System.Net.Quic;
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
@ -29,7 +32,7 @@ class Program
|
||||
{
|
||||
string strGestores = JsonConvert.SerializeObject(allGestores);
|
||||
// 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);
|
||||
|
||||
@ -47,6 +50,30 @@ class Program
|
||||
|
||||
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
|
||||
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;
|
||||
@ -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)
|
||||
{
|
||||
JArray allRecords = new JArray();
|
||||
@ -188,23 +231,21 @@ class Program
|
||||
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>();
|
||||
|
||||
for (int i = 0; i < jsonData.Count; i++)
|
||||
{
|
||||
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
@ -218,7 +259,7 @@ class Program
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
10
data.cs
10
data.cs
@ -10,6 +10,10 @@ namespace Pipefy
|
||||
{
|
||||
public Node node { get; set; }
|
||||
}
|
||||
public class RootGestor
|
||||
{
|
||||
public NodeGestor node { get; set; }
|
||||
}
|
||||
|
||||
public class Data
|
||||
{
|
||||
@ -20,7 +24,11 @@ namespace Pipefy
|
||||
{
|
||||
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 Field field { get; set; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user