From 748aa5f21d97dba5b190e7d81d74120c4c17b5fd Mon Sep 17 00:00:00 2001 From: ljpark Date: Mon, 14 Jul 2025 14:44:49 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8B=A4=EC=9A=B4=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EC=86=8D=EB=8F=84=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sn/app/(map-layout)/map/SearchModal.tsx | 19 ++----- .../map/components/searchModalReportApi.ts | 49 +++++++++++++------ 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/apps/sn/app/(map-layout)/map/SearchModal.tsx b/apps/sn/app/(map-layout)/map/SearchModal.tsx index 821907b87..4cace8cc0 100644 --- a/apps/sn/app/(map-layout)/map/SearchModal.tsx +++ b/apps/sn/app/(map-layout)/map/SearchModal.tsx @@ -11,7 +11,7 @@ import { SidoSigunguSelectBox } from '@/components/ui/SidoSigunguSelectBox'; import { MsSwagePplCol2, SwtrmtFcltCol2, SwtrmtPrcsZoneCol2, MsSwageMhlCol2, ExclnSewagePumpCol2, stofcbrCol2 } from './components/common/table'; import LoadingOverlay from '@/components/ui/LoadingBar'; //import { useDcTree, flattenFolders, useSggCd, useCityCd } from './components/searchModalReportApi'; -import { getDcTree,useDcTree,flattenFolders, useSggCd, useCityCd,getDcFile,addFileName,getDcFileDownload } from './components/searchModalReportApi'; +import { useDcTree,flattenFolders, useSggCd, useCityCd, addFileName, getFileDownload } from './components/searchModalReportApi'; import { useCityCdStore, type SelectDataType } from './commonStore'; const API_URL = `${process.env.NEXT_PUBLIC_SEWERAGE_API_URL}`; @@ -180,23 +180,12 @@ const SearchModal: React.FC = ({ } }; // 하수도정비기본계획.table cellClick - const handleReportCellClick = (index: number, headId?: string) => { + const handleReportCellClick = (index: number) => { console.log(index); const reportData = tableData[index]; - console.log(reportData); const fileName = reportData.fileName; - if (reportData.filePath) { - console.log(reportData.filePath); - getDcFileDownload(reportData.filePath).then((data) => { - const url = window.URL.createObjectURL(data); - const link = document.createElement('a'); - link.href = url; - link.download = fileName; // 원하는 파일명 지정 - document.body.appendChild(link); - link.click(); - link.remove(); - window.URL.revokeObjectURL(url); - }); + if (reportData.fileSn !== "") { + getFileDownload(reportData.fileSn, fileName); } }; diff --git a/apps/sn/app/(map-layout)/map/components/searchModalReportApi.ts b/apps/sn/app/(map-layout)/map/components/searchModalReportApi.ts index f26f6cbb2..9d1ae43e0 100644 --- a/apps/sn/app/(map-layout)/map/components/searchModalReportApi.ts +++ b/apps/sn/app/(map-layout)/map/components/searchModalReportApi.ts @@ -105,6 +105,22 @@ export const getDcFile = async (clsfSystmSn:string) => { const result = await getDcData(`/api/v1/dc/file${queryString ? `?${queryString}` : ''}`); return result; }; +export const addFileName = async (data:FlattenedFolder[]) => { + const fileReportData = await Promise.all( + data.map(async (item) => { + const filenameArr:ReportDataFile[] = await getDcFile(String(item.clsfSystmSn)); + const f = filenameArr[0]; + const result = {...item, fileName:f?.fileTitle, regDate:f?.regDt, fileSn:f?.fileSn, filePath:""}; + // if (f !== undefined && f.fileSn !== "") { + // const fprcs = await getDcFileprcs(f?.fileSn); + // if (fprcs.length>0) + // result.filePath = fprcs[0].filePath; + // } + return result; + }) + ); + return fileReportData; +} export const getDcFileprcs = async (fileSn:string) => { const queryString = 'fileSn='+fileSn; console.log("getDcTree queryString:", queryString); @@ -112,22 +128,6 @@ export const getDcFileprcs = async (fileSn:string) => { return result; }; -export const addFileName = async (data:FlattenedFolder[]) => { - const fileReportData = await Promise.all( - data.map(async (item) => { - const filenameArr:ReportDataFile[] = await getDcFile(String(item.clsfSystmSn)); - const f = filenameArr[0]; - const result = {...item, fileName:f?.fileTitle, regDate:f?.regDt, fileSn:f?.fileSn, filePath:""}; - if (f !== undefined && f.fileSn !== "") { - const fprcs = await getDcFileprcs(f?.fileSn); - if (fprcs.length>0) - result.filePath = fprcs[0].filePath; - } - return result; - }) - ); - return fileReportData; -} export const getDcFileDownload = async (filePath:string) => { const queryString = 'filePath='+ encodeURIComponent(filePath); const response = await fetch(`/dc-service/api/v1/dc/file/download?${queryString}`, { @@ -139,6 +139,23 @@ export const getDcFileDownload = async (filePath:string) => { const blob = await response.blob(); // PDF, image 등은 blob으로 받아야 함 return blob; }; +export const fileDownload = (data:Blob, fileName:string) => { // Blob데이터 임시link로 연결 + const url = window.URL.createObjectURL(data); + const link = document.createElement('a'); + link.href = url; + link.download = fileName; // 원하는 파일명 지정 + document.body.appendChild(link); + link.click(); + link.remove(); + window.URL.revokeObjectURL(url); +} +export const getFileDownload = async (fileSn:string, fileName:string) => { + const fileprcsData = await getDcFileprcs(fileSn); // filePath 조회 + if (fileprcsData?.length === 0 ) { alert("filePath 조회 오류"); } + if (fileprcsData[0].filePath === "") alert("filePath 정보 없으므로 다운로드 불가"); + const blobData = await getDcFileDownload(fileprcsData[0].filePath); // 실제 다운로드 API + fileDownload(blobData, fileName); +} // 시도 데이터 export const getCityCd = async (): Promise => { try {