diff --git a/apps/wr/app/ruseFcltMng/fcltSttn/htdflSttn/page.tsx b/apps/wr/app/ruseFcltMng/fcltSttn/htdflSttn/page.tsx index 2e06b05b3..1bd6bda67 100644 --- a/apps/wr/app/ruseFcltMng/fcltSttn/htdflSttn/page.tsx +++ b/apps/wr/app/ruseFcltMng/fcltSttn/htdflSttn/page.tsx @@ -6,7 +6,11 @@ import type { chgBuilding, customRainBdst, } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; -import { getCityOrSgg, tableData } from "@/components/lib/func/commom"; +import { + excelDownload, + getCityOrSgg, + tableData, +} from "@/components/lib/func/commom"; import HeadChModal from "@/components/ui/modal/sttn/headChModal/headChModal"; import { ContentsDiv, @@ -22,9 +26,12 @@ import SttnDetailModal from "@/components/ui/modal/sttn/sttnDetailModal/sttnDeta import BdstChgModal from "@/components/ui/modal/fcltReg/bdstChgModal/bdstChgModal"; import { Button } from "@common/components/ui"; import { useCallback, useEffect, useRef, useState } from "react"; +import { excelHtdflSttnParsing } from "@/app/store/ruseFcltMng/fcltSttn/htdflSttn/excel"; export default function HtdflSttn() { - const { code, htdflSttn, htdflSttnSearch, initHtdfl} = useWrStore((state) => state); + const { code, htdflSttn, htdflSttnSearch, initHtdfl } = useWrStore( + (state) => state + ); const { htdflSttnRes } = htdflSttn; const ref = useRef({} as ReturnType); @@ -44,26 +51,52 @@ export default function HtdflSttn() { const codeData = getCityOrSgg(ref); const excelClick = useCallback(() => { - if (codeData) htdflSttnSearch(1, "10000", codeData); - }, []); + if (codeData) htdflSttnSearch(1, "10000", codeData); + }, [htdflSttnSearch, codeData]); useEffect(() => { if (codeData != null) htdflSttnSearch(pageNation, "20", codeData); }, [pageNation]); const cellClick = (index: number | undefined, headId: string) => { - if(headId!=='chBuildingYn' && index!==undefined && bdstTable!==undefined){ - setDetailModal({isOpen:true ,data:bdstTable[index] }) - }else if( headId==='chBuildingYn' && index!==undefined && bdstTable!==undefined){ + if ( + headId !== "chBuildingYn" && + index !== undefined && + bdstTable !== undefined + ) { + setDetailModal({ isOpen: true, data: bdstTable[index] }); + } else if ( + headId === "chBuildingYn" && + index !== undefined && + bdstTable !== undefined + ) { if ( bdstTable[index] && - bdstTable[index]?.chgBuilding[0]?.bdstChgNm!==null - + bdstTable[index]?.chgBuilding[0]?.bdstChgNm !== null ) { - setBdstChgProps({ isOpen:true , chBuilding: bdstTable[index].chgBuilding}); + setBdstChgProps({ + isOpen: true, + chBuilding: bdstTable[index].chgBuilding, + }); } } }; + useEffect(() => { + const excelDown = async () => { + if (htdflSttn.excelList.length > 0) { + if (htdflSttn.excelList.length === 0) return; + const excelData = await tableData(htdflSttn.excelList, { code }); + const htdflExcel = excelHtdflSttnParsing(excelData); + excelDownload( + htdflExcel as [[]], + "온배수시설 현황", + "sample_htdflSttn.xlsx", + "A1:S3" + ); + } + }; + excelDown(); + }, [htdflSttn.excelList, code]); useEffect(() => { if (!htdflSttn.isInit) { @@ -165,12 +198,13 @@ export default function HtdflSttn() { } /> { - setDetailModal({...detailModal, isOpen:!detailModal.isOpen}) - }} - bodyClass={"w-[40vw] max-w-none max-h-[calc(100%-70px)]"} - body={}/> + open={detailModal.isOpen} + onOpenChange={() => { + setDetailModal({ ...detailModal, isOpen: !detailModal.isOpen }); + }} + bodyClass={"w-[40vw] max-w-none max-h-[calc(100%-70px)]"} + body={} + /> new Date()), @@ -27,16 +29,8 @@ export const hdtflZod = z.object({ anlOperCst: z.number().default(0), instlCstSprtYn: z.enum(["Y", "N"]).nullish(), instlCstSprtAmt: z.number().nullish().default(0), - // grntchBdstCertYn: z.enum(["Y", "N"]), - // grntchBdstCertYr: z .string().default("") - // .refine((year) =>year.length ===0 || /^\d{4}$/.test(year),{ - // message:'4자리 연도만 입력하세요' - // }), grntchBdstCertNo: z.string().nullish().default(""), grntchBdstCertGrd: z.string().nullish().default(""), - // crgRdctYn: z.enum(["Y", "N"]), - // crgRdctBss: z.string().nullish().default(""), - // crgRdctAmt: z.number().nullish().default(0), ruseFcltFlg: z.string().nullish().default(""), bdstUsgCd: z.number().default(0), lawTrgtYn: z.enum(["Y", "N"]).nullish(), diff --git a/apps/wr/app/store/ruseFcltMng/fcltSttn/htdflSttn/excel.tsx b/apps/wr/app/store/ruseFcltMng/fcltSttn/htdflSttn/excel.tsx new file mode 100644 index 000000000..671eacae8 --- /dev/null +++ b/apps/wr/app/store/ruseFcltMng/fcltSttn/htdflSttn/excel.tsx @@ -0,0 +1,30 @@ +import type { customHtdflBdst } from "../../fcltReg/htdflReg"; + +export const excelHtdflSttnParsing = (data: customHtdflBdst[]): string[][] => { + const excelExportData: string[][] = []; + + data.forEach((item) => { + excelExportData.push([ + String(item.cityText??""), + String(item.sggText??""), + item.bdstNm ?? "", + item.daddr ?? "", + String(item.frstArchPrmsnDt ?? ""), + String(item.reuseBuilding?.[0]?.htdflObj.etgtType ?? ""), + String(item.reuseBuilding?.[0]?.htdflObj.fclCpct ?? ""), // fix: added missing parenthesis + String(item.reuseBuilding?.[0]?.htdflObj.plwtYn ? "Y" :"N"), // fix: added missing parenthesis + String(item.reuseBuilding?.[0]?.htdflObj.orgwtWtritSpt ?? ""), // fix: added missing parenthesis + String(item.reuseBuilding?.[0]?.htdflObj.wtritEntrcTp ?? ""), // fix: removed as it doesn't exist in the provided context + String(item.reuseBuilding?.[0]?.htdflObj.orgwtOcrnProcs ?? ""), // fix: removed as it doesn't exist in the provided context + String( item.reuseBuilding?.[0]?.htdflObj?.amtgnr ?? ""), // fix: removed as it doesn't exist in the provided context + String(item.reuseBuilding?.[0]?.htdflObj?.prcsProcsYn ?? ""), // fix: removed as it doesn't exist in the provided context + String( '컬럼확인'), // fix: removed as it doesn't exist in the provided context + String(item.reuseBuilding?.[0]?.htdflObj?.prcsFcltCpct ?? ""), // fix: removed as it doesn't exist in the provided context + String(item.reuseBuilding?.[0]?.htdflObj?.fmYn ?? ""), // fix: removed as it doesn't exist in the provided context + String(item.reuseBuilding?.[0]?.htdflObj?.utztnCpct ?? ""), // fix: removed as it doesn't exist in the provided context + String(item.reuseBuilding?.[0]?.htdflObj?.utztnUsg ?? ""), // fix: removed as it doesn't exist in the provided context + String(item.reuseBuilding?.[0]?.htdflObj?.emsnExitTp ?? ""), // fix: removed as it doesn't exist in the provided context + ]); + }); + return excelExportData; +}; diff --git a/apps/wr/app/store/ruseFcltMng/fcltSttn/htdflSttn/index.tsx b/apps/wr/app/store/ruseFcltMng/fcltSttn/htdflSttn/index.tsx index 0dedb1570..2df318c45 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltSttn/htdflSttn/index.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltSttn/htdflSttn/index.tsx @@ -5,6 +5,8 @@ import type { z } from "zod"; import { controlHeadView } from "../rainSttn"; import type { customHtdflBdst } from "../../fcltReg/htdflReg"; import { fetchType, getFetch } from "@/components/lib/api"; +import { excelHtdflSttnParsing } from "./excel"; +import { tableData } from "@/components/lib/func/commom"; const htdflSttHeadList = htdflSttHeadListExport; const htdflSttNodeList = htdflSttNodeListExport; @@ -15,6 +17,8 @@ export type htdflSttnState = { htdflSttHeadList: z.infer; htdflSttNodeList: CommonTableProps[]; htdflSttnRes:customHtdflBdst[] + excelList: []; + }; }; type htdflSttnActions = { @@ -32,6 +36,7 @@ export const htdflSttnStateExport: htdflSttnState = { htdflSttHeadList: htdflSttHeadList, htdflSttNodeList: htdflSttNodeList, htdflSttnRes:[], + excelList:[], isInit: false, }, }; @@ -66,18 +71,21 @@ export const htdflSttnActionsExport: (set: any) => htdflSttnActions = ( }, htdflSttnSearch: async (page: number, total: string, con: string) => { try { + console.log(page) const htdflSttnRes = await getFetch( fetchType.WR, `/drain/facilityList/${page}/${total}/${con}` ); if (Number(total) > 9000) { - // const htdflExcel = excelHtdflSttnParsing(htdflSttnRes); + + set((state: htdflSttnState) => { + return { ...state, htdflSttn: { ...state.htdflSttn, - // excelList: htdflExcel, + excelList: htdflSttnRes, }, }; }); @@ -111,5 +119,7 @@ export const htdflSttnActionsExport: (set: any) => htdflSttnActions = ( }, })); }, + + } } \ No newline at end of file diff --git a/apps/wr/public/sample_htdflSttn.xlsx b/apps/wr/public/sample_htdflSttn.xlsx new file mode 100644 index 000000000..fd1dc5a89 Binary files /dev/null and b/apps/wr/public/sample_htdflSttn.xlsx differ