This commit is contained in:
Andrey Cunha
2026-05-06 23:19:49 -03:00
parent 4b465e54fe
commit 2bbc71eee2
12 changed files with 5822 additions and 4717 deletions
+68 -2
View File
@@ -22,9 +22,62 @@ function createDataset(fields, constraints, sortFields) {
dataset.addColumn("data_consulta");
dataset.addColumn("hora_consulta");
dataset.addColumn("sucesso");
dataset.addColumn("COTACOES_JSON");
dataset.addColumn("COTACAO_ERRO");
function emptyRow() {
return ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "false"];
return ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "false", "", ""];
}
function consultarCotacao(clientService, cotacao) {
var endpoints = [
"/UF_MATA130/" + cotacao,
"/rest/UF_MATA130/" + cotacao,
"/rest/uf_mata130/" + cotacao
];
var ultimoErro = "";
for (var i = 0; i < endpoints.length; i++) {
try {
var dataCot = {
companyId: "1",
serviceCode: "Postprod",
endpoint: endpoints[i],
method: "get",
timeoutService: "60000",
headers: {
"Content-Type": "application/json"
}
};
var responseCot = clientService.invoke(JSON.stringify(dataCot));
if (!responseCot || !responseCot.getResult()) {
ultimoErro = "Sem resposta ao consultar cotacao";
continue;
}
var resultCot = JSON.parse(responseCot.getResult());
if (resultCot && resultCot.sucesso && resultCot.cotacoes && resultCot.cotacoes.length > 0) {
return {
sucesso: true,
cotacoes: resultCot.cotacoes
};
}
if (resultCot && resultCot.message) {
ultimoErro = String(resultCot.message);
} else {
ultimoErro = "Cotacao sem itens retornados";
}
} catch (eCot) {
ultimoErro = String(eCot);
}
}
return {
sucesso: false,
erro: ultimoErro || "Falha ao consultar cotacao"
};
}
try {
@@ -66,6 +119,17 @@ function createDataset(fields, constraints, sortFields) {
cotacao = "";
}
var cotacoesJson = "";
var cotacaoErro = "";
if (cotacao) {
var consultaCot = consultarCotacao(clientService, cotacao);
if (consultaCot.sucesso) {
cotacoesJson = JSON.stringify(consultaCot.cotacoes || []);
} else {
cotacaoErro = consultaCot.erro || "";
}
}
dataset.addRow([
sc.C1_FILIAL || "",
sc.C1_NUM || "",
@@ -87,7 +151,9 @@ function createDataset(fields, constraints, sortFields) {
sc.STATUS || "",
result.data_consulta || "",
result.hora_consulta || "",
"true"
"true",
cotacoesJson,
cotacaoErro
]);
} else {
dataset.addRow(emptyRow());