ЦИТК-917 - Публикация аналитических данных - поддержка PG

This commit is contained in:
Mikhail Chechnev 2025-04-05 13:58:42 +03:00
parent 0807b99b42
commit ca64cbd6b4

View File

@ -9,7 +9,6 @@
const { ServerError } = require("./../core/server_errors"); //Типовая ошибка
const { SERR_APP_SERVER_BEFORE, SERR_DB_SERVER } = require("./../core/constants"); //Общесистемные константы
const oracledb = require("oracledb"); //Работа с СУБД Oracle
//------------
// Тело модуля
@ -21,52 +20,37 @@ const before = async prms => {
if (prms.options.qs && prms.options.qs.STOKEN && prms.options.qs.NPREVIEW && prms.options.qs.NACTUAL_CHECK) {
//И есть подключение к БД
if (prms.dbConn.bConnected) {
let pooledConnection;
try {
//Считаем курсор с данными публикации
pooledConnection = await prms.dbConn.connection.getConnection();
let res = await pooledConnection.execute(
"BEGIN PKG_EXS_EXT_OLAPP_RUN.EXTRACT(STOKEN => :STOKEN, NPREVIEW => :NPREVIEW, NACTUAL_CHECK => :NACTUAL_CHECK, RCDATA => :RCDATA); END;",
{
STOKEN: prms.options.qs.STOKEN,
NPREVIEW: prms.options.qs.NPREVIEW,
NACTUAL_CHECK: prms.options.qs.NACTUAL_CHECK,
RCDATA: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{ outFormat: oracledb.OBJECT }
);
//Установим заголовок ответа и начнём выдачу данных
prms.res.set({
"content-type": "application/json;charset=utf-8"
});
prms.res.write("[");
//Обходим курсор и выдаём порционно ответ
const rs = res.outBinds.RCDATA;
let cnt = 1;
let row;
while ((row = await rs.getRow())) {
prms.res.write(Buffer.from(`${cnt > 1 ? "," : ""}${JSON.stringify(row)}`));
cnt++;
let olappExtractData = await prms.dbConn.executeStored({
sName: "PKG_EXS_EXT_OLAPP_RUN.EXTRACT",
inPrms: {
STOKEN: prms.options.qs.STOKEN,
NPREVIEW: prms.options.qs.NPREVIEW,
NACTUAL_CHECK: prms.options.qs.NACTUAL_CHECK
},
outPrms: {
RCDATA: prms.dbConn.connector.DT_CURSOR
}
//Завершаем передачу
prms.res.write("]");
prms.res.end();
await rs.close();
//Дальше обрабатывать не надо
return {
bStopPropagation: true
};
} catch (e) {
throw new ServerError(SERR_DB_SERVER, e.message);
} finally {
if (pooledConnection) {
try {
await pooledConnection.close();
} catch (e) {
throw new ServerError(SERR_DB_SERVER, e.message);
}
});
//Установим заголовок ответа и начнём выдачу данных
prms.res.set({
"content-type": "application/json;charset=utf-8"
});
prms.res.write("[");
if (olappExtractData)
if (olappExtractData.RCDATA) {
let cnt = 1;
olappExtractData.RCDATA.map(row => {
prms.res.write(Buffer.from(`${cnt > 1 ? "," : ""}${JSON.stringify(row)}`));
cnt++;
});
}
}
//Завершаем передачу
prms.res.write("]");
prms.res.end();
//Дальше обрабатывать не надо
return {
bStopPropagation: true
};
} else {
throw new ServerError(SERR_DB_SERVER, "Нет подключения к БД");
}