forked from CITKParus/P8-ExchangeService
ЦИТК-917 - Публикация аналитических данных - поддержка PG
This commit is contained in:
parent
0807b99b42
commit
ca64cbd6b4
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
const { ServerError } = require("./../core/server_errors"); //Типовая ошибка
|
const { ServerError } = require("./../core/server_errors"); //Типовая ошибка
|
||||||
const { SERR_APP_SERVER_BEFORE, SERR_DB_SERVER } = require("./../core/constants"); //Общесистемные константы
|
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.options.qs && prms.options.qs.STOKEN && prms.options.qs.NPREVIEW && prms.options.qs.NACTUAL_CHECK) {
|
||||||
//И есть подключение к БД
|
//И есть подключение к БД
|
||||||
if (prms.dbConn.bConnected) {
|
if (prms.dbConn.bConnected) {
|
||||||
let pooledConnection;
|
let olappExtractData = await prms.dbConn.executeStored({
|
||||||
try {
|
sName: "PKG_EXS_EXT_OLAPP_RUN.EXTRACT",
|
||||||
//Считаем курсор с данными публикации
|
inPrms: {
|
||||||
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,
|
STOKEN: prms.options.qs.STOKEN,
|
||||||
NPREVIEW: prms.options.qs.NPREVIEW,
|
NPREVIEW: prms.options.qs.NPREVIEW,
|
||||||
NACTUAL_CHECK: prms.options.qs.NACTUAL_CHECK,
|
NACTUAL_CHECK: prms.options.qs.NACTUAL_CHECK
|
||||||
RCDATA: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
||||||
},
|
},
|
||||||
{ outFormat: oracledb.OBJECT }
|
outPrms: {
|
||||||
);
|
RCDATA: prms.dbConn.connector.DT_CURSOR
|
||||||
|
}
|
||||||
|
});
|
||||||
//Установим заголовок ответа и начнём выдачу данных
|
//Установим заголовок ответа и начнём выдачу данных
|
||||||
prms.res.set({
|
prms.res.set({
|
||||||
"content-type": "application/json;charset=utf-8"
|
"content-type": "application/json;charset=utf-8"
|
||||||
});
|
});
|
||||||
prms.res.write("[");
|
prms.res.write("[");
|
||||||
//Обходим курсор и выдаём порционно ответ
|
if (olappExtractData)
|
||||||
const rs = res.outBinds.RCDATA;
|
if (olappExtractData.RCDATA) {
|
||||||
let cnt = 1;
|
let cnt = 1;
|
||||||
let row;
|
olappExtractData.RCDATA.map(row => {
|
||||||
while ((row = await rs.getRow())) {
|
|
||||||
prms.res.write(Buffer.from(`${cnt > 1 ? "," : ""}${JSON.stringify(row)}`));
|
prms.res.write(Buffer.from(`${cnt > 1 ? "," : ""}${JSON.stringify(row)}`));
|
||||||
cnt++;
|
cnt++;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
//Завершаем передачу
|
//Завершаем передачу
|
||||||
prms.res.write("]");
|
prms.res.write("]");
|
||||||
prms.res.end();
|
prms.res.end();
|
||||||
await rs.close();
|
|
||||||
//Дальше обрабатывать не надо
|
//Дальше обрабатывать не надо
|
||||||
return {
|
return {
|
||||||
bStopPropagation: true
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new ServerError(SERR_DB_SERVER, "Нет подключения к БД");
|
throw new ServerError(SERR_DB_SERVER, "Нет подключения к БД");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user