экспорт по фильтру

This commit is contained in:
Sergey Yarkov 2026-08-25 13:41:55 +03:00
parent 8a844c12fe
commit 9cff9624a8
4 changed files with 28 additions and 103 deletions

View File

@ -11,7 +11,9 @@ import ExcelJS from "exceljs";
* @type {HttpRouteHandler} * @type {HttpRouteHandler}
*/ */
export default async (ctx) => { export default async (ctx) => {
const { res } = ctx; const { res, searchParams } = ctx;
const systemIdsParam = searchParams.get("systemIds")?.split(",");
const wb = new ExcelJS.Workbook(); const wb = new ExcelJS.Workbook();
const ws = wb.addWorksheet("Перечень систем", { const ws = wb.addWorksheet("Перечень систем", {
@ -19,7 +21,7 @@ export default async (ctx) => {
}); });
const filename = encodeURIComponent("АСУ промплощадка.xlsx"); const filename = encodeURIComponent("АСУ промплощадка.xlsx");
const equipmentData = await equipmentRepository.getAll(); const equipmentData = await equipmentRepository.getAll({ filter: { systemIds: systemIdsParam } });
const excelData = []; const excelData = [];

96
package-lock.json generated
View File

@ -15,7 +15,6 @@
"p-limit": "^7.3.0", "p-limit": "^7.3.0",
"serialize-error": "^13.0.1", "serialize-error": "^13.0.1",
"xlsx": "^0.18.5", "xlsx": "^0.18.5",
"xlsx-js-style": "^1.2.0",
"yup": "^1.7.1" "yup": "^1.7.1"
}, },
"devDependencies": { "devDependencies": {
@ -1465,15 +1464,6 @@
"node": ">= 6" "node": ">= 6"
} }
}, },
"node_modules/exit-on-epipe": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz",
"integrity": "sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/fast-csv": { "node_modules/fast-csv": {
"version": "4.3.6", "version": "4.3.6",
"resolved": "https://registry.npmjs.org/fast-csv/-/fast-csv-4.3.6.tgz", "resolved": "https://registry.npmjs.org/fast-csv/-/fast-csv-4.3.6.tgz",
@ -1515,12 +1505,6 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/fflate": {
"version": "0.3.11",
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.3.11.tgz",
"integrity": "sha512-Rr5QlUeGN1mbOHlaqcSYMKVpPbgLy0AWT/W0EHxA6NGI12yO1jpoui2zBBvU2G824ltM6Ut8BFgfHSBGfkmS0A==",
"license": "MIT"
},
"node_modules/file-entry-cache": { "node_modules/file-entry-cache": {
"version": "8.0.0", "version": "8.0.0",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz",
@ -2489,18 +2473,6 @@
"node": ">=6.0.0" "node": ">=6.0.0"
} }
}, },
"node_modules/printj": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/printj/-/printj-1.1.2.tgz",
"integrity": "sha512-zA2SmoLaxZyArQTOPj5LXecR+RagfPSU5Kw1qP+jkWeNlrq+eJZyY2oS68SU1Z/7/myXM4lo9716laOFAVStCQ==",
"license": "Apache-2.0",
"bin": {
"printj": "bin/printj.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/process": { "node_modules/process": {
"version": "0.11.10", "version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
@ -3095,74 +3067,6 @@
"node": ">=0.8" "node": ">=0.8"
} }
}, },
"node_modules/xlsx-js-style": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/xlsx-js-style/-/xlsx-js-style-1.2.0.tgz",
"integrity": "sha512-DDT4FXFSWfT4DXMSok/m3TvmP1gvO3dn0Eu/c+eXHW5Kzmp7IczNkxg/iEPnImbG9X0Vb8QhROda5eatSR/97Q==",
"license": "Apache-2.0",
"dependencies": {
"adler-32": "~1.2.0",
"cfb": "^1.1.4",
"codepage": "~1.14.0",
"commander": "~2.17.1",
"crc-32": "~1.2.0",
"exit-on-epipe": "~1.0.1",
"fflate": "^0.3.8",
"ssf": "~0.11.2",
"wmf": "~1.0.1",
"word": "~0.3.0"
},
"bin": {
"xlsx": "bin/xlsx.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/xlsx-js-style/node_modules/adler-32": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.2.0.tgz",
"integrity": "sha512-/vUqU/UY4MVeFsg+SsK6c+/05RZXIHZMGJA+PX5JyWI0ZRcBpupnRuPLU/NXXoFwMYCPCoxIfElM2eS+DUXCqQ==",
"license": "Apache-2.0",
"dependencies": {
"exit-on-epipe": "~1.0.1",
"printj": "~1.1.0"
},
"bin": {
"adler32": "bin/adler32.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/xlsx-js-style/node_modules/codepage": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/codepage/-/codepage-1.14.0.tgz",
"integrity": "sha512-iz3zJLhlrg37/gYRWgEPkaFTtzmnEv1h+r7NgZum2lFElYQPi0/5bnmuDfODHxfp0INEfnRqyfyeIJDbb7ahRw==",
"license": "Apache-2.0",
"dependencies": {
"commander": "~2.14.1",
"exit-on-epipe": "~1.0.1"
},
"bin": {
"codepage": "bin/codepage.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/xlsx-js-style/node_modules/codepage/node_modules/commander": {
"version": "2.14.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==",
"license": "MIT"
},
"node_modules/xlsx-js-style/node_modules/commander": {
"version": "2.17.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz",
"integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==",
"license": "MIT"
},
"node_modules/xmlchars": { "node_modules/xmlchars": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",

View File

@ -20,7 +20,6 @@
"p-limit": "^7.3.0", "p-limit": "^7.3.0",
"serialize-error": "^13.0.1", "serialize-error": "^13.0.1",
"xlsx": "^0.18.5", "xlsx": "^0.18.5",
"xlsx-js-style": "^1.2.0",
"yup": "^1.7.1" "yup": "^1.7.1"
}, },
"imports": { "imports": {

View File

@ -1,9 +1,25 @@
import { UOW } from "./index.js"; import { UOW } from "./index.js";
import sql from "mssql";
export const equipmentRepository = { export const equipmentRepository = {
async getAll() { /**
* @param {{ filter?: { systemIds?: string[] | number[] } }} [options]
*/
async getAll(options) {
const request = UOW.request; const request = UOW.request;
const result = await request.query(` const systemIds = options?.filter?.systemIds;
const hasFilterBySystemIds = systemIds !== undefined && systemIds.length !== 0;
let whereClause = "";
if (hasFilterBySystemIds) {
const idsString = systemIds.map(Number).filter(Boolean).join(",");
request.input("sysIdsString", sql.VarChar, idsString);
whereClause = `WHERE systemsTbl.id IN (SELECT value FROM STRING_SPLIT(@sysIdsString, ','))`;
}
const query = `
SELECT systemsTbl.id as id, SELECT systemsTbl.id as id,
systemsTbl.name as name, systemsTbl.name as name,
baseLocTbl.name as baseLocationName, baseLocTbl.name as baseLocationName,
@ -51,8 +67,12 @@ export const equipmentRepository = {
where jt.systemlist_id = systemsTbl.id where jt.systemlist_id = systemsTbl.id
FOR JSON PATH) as subsystems FOR JSON PATH) as subsystems
from asu_system_api_systemlist as systemsTbl from asu_system_api_systemlist as systemsTbl
inner join asu_system_api_baselocation as baseLocTbl on systemsTbl.location_id = baseLocTbl.id FOR JSON PATH inner join asu_system_api_baselocation as baseLocTbl on systemsTbl.location_id = baseLocTbl.id
`); ${whereClause}
FOR JSON PATH
`;
const result = await request.query(query);
const jsonStringData = result.recordset.map((row) => Object.values(row)[0]).join(""); const jsonStringData = result.recordset.map((row) => Object.values(row)[0]).join("");