53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
/** 노후관로 목록의 엑셀 다운로드 데이터와 서식을 생성한다. */
|
|
"use client";
|
|
|
|
import { postBlobData } from "@/components/lib/api";
|
|
import { fileDownload } from "@/components/lib/utils/fileDownload";
|
|
import {
|
|
AGED_PIPE_EXCEL_FIELDS,
|
|
normalizeAgedPipeFilters,
|
|
type AgedPipeFilters,
|
|
} from "./agedPipeUtils";
|
|
|
|
type AgedPipeExportProgress = {
|
|
fileName?: string;
|
|
progressPercent?: number;
|
|
status: "QUEUED" | "RUNNING" | "COMPLETED";
|
|
};
|
|
|
|
/** 노후관로 XLSX 다운로드를 요청한다. */
|
|
export const downloadAgedPipeExcel = async (
|
|
filters: AgedPipeFilters,
|
|
onProgress?: (progress: AgedPipeExportProgress) => void,
|
|
expectedTotal?: number,
|
|
) => {
|
|
const normalizedFilters = normalizeAgedPipeFilters(filters);
|
|
|
|
onProgress?.({ status: "RUNNING", progressPercent: 0 });
|
|
|
|
const { blob, fileName } = await postBlobData(
|
|
"v1/fclts/agedPipes/exportJobs/download",
|
|
{
|
|
elapsedYears: normalizedFilters.elapsedYears,
|
|
ctpvCd: normalizedFilters.ctpvCd,
|
|
sggCd: normalizedFilters.sggCd,
|
|
format: "xlsx",
|
|
columns: [...AGED_PIPE_EXCEL_FIELDS],
|
|
expectedTotal,
|
|
},
|
|
);
|
|
|
|
const resolvedFileName = fileName || "노후관로_현황.xlsx";
|
|
fileDownload(blob, resolvedFileName);
|
|
onProgress?.({
|
|
status: "COMPLETED",
|
|
fileName: resolvedFileName,
|
|
progressPercent: 100,
|
|
});
|
|
|
|
return {
|
|
status: "COMPLETED" as const,
|
|
fileName: resolvedFileName,
|
|
};
|
|
};
|