GraphQL: exportSchemas, dataTask; scenarijuje — getDataExportSchemas, fetchExportData.
const schemas = await getDataExportSchemas();
await log.info("Galimi tipai: " + schemas.map(function (s) { return s.code; }).join(","));
const reportTypeId = initial?.reportTypeId ?? "SALES_YEAR_SUMMARY";
const res = await fetchExportData(reportTypeId, {
filters: { year: initial.year, companyId: companyId },
dataSelection: ["documentNo", "date", "amount", "client.name"]
});
if (res.status !== "SUCCESS") {
await log.error("Export data: " + JSON.stringify(res));
throw new UserError("Nepavyko paruošti duomenų");
}
output = { message: "Duomenys paruošti tolesniam foniniam eksportui / užduočiai", exportStatus: res.status };
Pilnas failas į diską dažnai eina per užduotį (žr. asinchroninio eksporto temą), ne per vieną output.
const size = initial?.maxRows ?? 5000;
const data = await rql(`
SELECT id, amount FROM saleInvoices
WITH companyId = ${companyId} size = ${size}
WHERE opDate >= ${toString(initial.dateFrom)}
`);
if ((data?.content?.length ?? 0) >= size) {
await log.warn("Pasiekta max eilučių riba — siūlykite Data Export");
output = { message: "Per didelis kiekis ekranui", executionStatus: "WARNING", documentsCount: data.content.length };
} else {
output = { message: "OK", documentsCount: data.content.length, rows: data.content };
}
// Nenaudoti vienam output visų eilučių — tik job / schema ID
await log.info("Paleidžiamas masinis eksportas: " + initial.reportTypeId);
output = {
message: "Užduotis sukurta (900k eilučių) — sekite vartotojo užduotyse",
executionStatus: "SUCCESS",
documentsCount: 0
};
// Blogai: const copy = [...bigArray, ...bigArray];
// Geriau: sąrašą imti vieną kartą (ribotu size) ir apdoroti partijomis JS cikle — kaip eilutes skaitote iš Excel
const BATCH = 500;
const all = (await rql(`
SELECT id FROM products
WITH companyId = ${companyId} size = 5000
`))?.content ?? [];
for (let i = 0; i < all.length; i += BATCH) {
const slice = all.slice(i, i + BATCH);
for (const row of slice) {
await mutate("touchProductExt", { productId: row.id }); // pavadinimas iliustratyvus — tikrinkite pagal SDL
}
await log.info("Apdorota " + Math.min(i + BATCH, all.length) + " / " + all.length);
}
output = { message: "Partijos baigtos" };
// Venkite A→B→A; jei reikia — vienas bendras helperis be callErpAutomation ciklo
async function processNode(nodeId, depth) {
if (depth > 5) throw new UserError("Per gilus kvietimų medis");
await log.info("node " + nodeId + " depth " + depth);
// await callErpAutomation("child", { nodeId, depth: depth + 1 });
}
await processNode(initial.rootId, 0);
output = { message: "Baigta" };