서버페이징 변경
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { deleteData, getData, postRawJson } from "@/components/lib/api";
|
||||
|
||||
/** 대량 Excel은 서버 작업으로 생성한다. 목록의 현재 page/size를 전달하지 않는다. */
|
||||
export async function requestGridExcel(url: string, body: object = {}, fileName = "grid.xlsx"): Promise<void> {
|
||||
const submitted = await postRawJson(url, body);
|
||||
const job = submitted?.data ?? submitted;
|
||||
if (!job?.jobId) throw new Error("Excel 생성 작업을 접수하지 못했습니다.");
|
||||
const jobPath = `v1/gridExportJobs/${encodeURIComponent(job.jobId)}`;
|
||||
const started = Date.now();
|
||||
while (Date.now() - started < 30 * 60 * 1000) {
|
||||
const status = await getData(jobPath);
|
||||
if (status?.status === "READY") {
|
||||
// 브라우저 JS 메모리에 완성 파일까지 적재하지 않도록 동일 출처 스트리밍 경로를 사용한다.
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = `/api/gridDownload/${encodeURIComponent(job.jobId)}?fileName=${encodeURIComponent(fileName)}`;
|
||||
anchor.download = fileName;
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
return;
|
||||
}
|
||||
if (status?.status === "FAILED") {
|
||||
await deleteData(jobPath).catch(() => undefined);
|
||||
throw new Error(status.message || "Excel 생성에 실패했습니다.");
|
||||
}
|
||||
await new Promise((resolve) => window.setTimeout(resolve, 1000));
|
||||
}
|
||||
throw new Error("Excel 생성 대기시간이 초과되었습니다. 검색조건을 좁혀 다시 시도해주세요.");
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { requestGridExcel } from "@/shared/api/grid-export";
|
||||
|
||||
/** I/I 일반 화면과 지도 팝업에서 선택 분석의 전체 결과를 동일한 서버 작업으로 내려받는다. */
|
||||
export const downloadAnalysisExcel = async (kind: "inftwt" | "rdii", id: string | number, fileName: string) => {
|
||||
await requestGridExcel(`v1/analysisExports/${kind}/${encodeURIComponent(id)}`, {}, `${fileName}.xlsx`);
|
||||
};
|
||||
Reference in New Issue
Block a user