diff --git a/apps/wr/app/store/map/pbnstMap/excel.ts b/apps/wr/app/store/map/pbnstMap/excel.ts new file mode 100644 index 000000000..63484b12f --- /dev/null +++ b/apps/wr/app/store/map/pbnstMap/excel.ts @@ -0,0 +1,21 @@ + +export const excelHasuMapParsing = ( + excel:{data:any[]} +): string[][] => { + const excelExportData: string[][] = []; + + excel.data.forEach((item) => { + + excelExportData.push([ + item.sido??'', + item.gugun??'', + item.bscFctNm ?? "", + String(item.addr??""), + item.efflWqltStndrdNm ?? "", + String(item.fctCpc ?? ""), + String(item.ruse ?? ""), + String(item.rswtrYn ?? ""), + ]); + }); + return excelExportData; +}; \ No newline at end of file diff --git a/apps/wr/app/store/map/pbnstMap/index.tsx b/apps/wr/app/store/map/pbnstMap/index.tsx index c093431ff..4cd118caa 100644 --- a/apps/wr/app/store/map/pbnstMap/index.tsx +++ b/apps/wr/app/store/map/pbnstMap/index.tsx @@ -1,9 +1,10 @@ import { fetchType, postFectch } from "@/components/lib/api"; import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type"; import { checkWrRegList } from "../../ruseFcltMng/fcltReg/pbnstReg"; -import type { ReturnType } from "@common/business_components/ui"; +import type { ReturnType} from "@common/business_components/ui"; import { pubFacHeadListExport } from "../../ruseFcltMng/fcltReg/pbnstReg/headList"; import type { TableUpperProps } from "../../common/type/header"; +import { excelHasuMapParsing } from "./excel"; export const pbnMapTableSize = 20; @@ -61,12 +62,23 @@ export type pbnMapState = { pbnMapRes: pubHasuType[]; pbnMapCount: number; pbnMapHeadList: TableUpperProps[]; + hasuMapExcelList:[] }; }; type pbnMapActions = { pbnMapInit: (page: number, pageTotal: number, reurnValue: ReturnType) => void; - pbnMapDetaile: (featureCd: string, data: string) => Promise; + pbnMapSearch: ( + isExcel: boolean, + page: number, + pageTotal: number, + reurnValue: ReturnType, + txt: string, + ) => void; + pbnMapDetaile: ( + featureCd: string, + data: string + ) => Promise; }; export type pbnMapType = pbnMapState & pbnMapActions; @@ -77,6 +89,7 @@ export const pbnMapStateExport: pbnMapState = { pbnMapRes: [], pbnMapCount: 1, pbnMapHeadList: pubFacHeadListExport, + hasuMapExcelList:[] }, }; @@ -124,5 +137,44 @@ export const pbnMapActionsExport: (set: any) => pbnMapActions = (set: any) => { throw error; // 호출부에서 catch 가능하도록 } }, + pbnMapSearch: async ( + isExcel: boolean, + page: number, + pageTotal: number, + reurnValue: ReturnType, + txt: string, + ) => { + try { + const hasuMapRes = await hasuListFetch(page, pageTotal, reurnValue, txt); + if (isExcel) { + const hasuMapExcelList = excelHasuMapParsing( + hasuMapRes + ); + set((state: pbnMapState) => { + return { + ...state, + pbnMap: { + ...state.pbnMap, + hasuMapExcelList: hasuMapExcelList + }, + }; + }); + } else { + set((state: pbnMapState) => { + return { + ...state, + pbnMap: { + ...state.pbnMap, + pbnMapRes: hasuMapRes.data, + pbnMapCount: hasuMapRes.count, + isInit: false, + }, + }; + }); + } + } catch (e) { + console.log(e); + } + }, }; }; diff --git a/apps/wr/components/ui/map/LayerPopUp/HasuFacilty/HasuFacility.tsx b/apps/wr/components/ui/map/LayerPopUp/HasuFacilty/HasuFacility.tsx index 4f9d052de..2a8210aa0 100644 --- a/apps/wr/components/ui/map/LayerPopUp/HasuFacilty/HasuFacility.tsx +++ b/apps/wr/components/ui/map/LayerPopUp/HasuFacilty/HasuFacility.tsx @@ -2,7 +2,7 @@ import { useWrStore } from "@/app/store"; import { btnClass } from "@/app/store/common/code"; import { pbnMapTableSize } from "@/app/store/map/pbnstMap"; import type { pubHasuType } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type"; -import { tableData } from "@/components/lib/func/commom"; +import { excelDownload, tableData } from "@/components/lib/func/commom"; import { ContentsDiv, SearchBaseForm, @@ -13,14 +13,17 @@ import { } from "@common/business_components/ui"; import { Label } from "@common/components/ui"; import { useEffect, useRef, useState } from "react"; +import toast from "react-hot-toast"; +import { useTranslation } from "react-i18next"; export function HasuFacility({rtnFeature}:{rtnFeature:(feature:any)=>void } ) { - const { code, pbnMap, pbnMapInit } = useWrStore((state) => state); + const { code, pbnMap, pbnMapInit ,pbnMapSearch} = useWrStore((state) => state); const [hasuTable, setHasuTable] = useState(); const [isReset, setIsReset] = useState(false); const [pbnRuseNm, setPbnRuseNm] = useState(""); const ref = useRef({} as ReturnType); - const { pbnMapHeadList, pbnMapRes, pbnMapCount } = pbnMap; + const { pbnMapHeadList, pbnMapRes, pbnMapCount ,hasuMapExcelList} = pbnMap; + const { t } = useTranslation("base"); useEffect(() => { if (!pbnMap.isInit) { @@ -39,6 +42,22 @@ export function HasuFacility({rtnFeature}:{rtnFeature:(feature:any)=>void } ) { rtnFeature(pbnMapRes[index]) } }; + + + useEffect(() => { + if (hasuMapExcelList.length > 0) { + excelDownload( + hasuMapExcelList, + "하수처리시설 현황", + "sample_hasuMap.xlsx", + "A1:H1", + 2 + ); + } else { + toast.error(t("excelDownErrMsg")); + } + }, [hasuMapExcelList]); + return ( <> @@ -83,6 +102,10 @@ export function HasuFacility({rtnFeature}:{rtnFeature:(feature:any)=>void } ) { isAdmin={false} excelClick={function (returnType: ReturnType): void { console.log("pbnstSttnSearch ", returnType); + + + pbnMapSearch(true,1, 100000, returnType,'' ) + }} /> @@ -96,7 +119,9 @@ export function HasuFacility({rtnFeature}:{rtnFeature:(feature:any)=>void } ) { headName={""} cellClick={hasuCellClick} onPageChange={(page) => { - pbnMapInit(page, pbnMapTableSize, ref.current); + //pbnMapInit(page, pbnMapTableSize, ref.current); + + pbnMapSearch(false,page, pbnMapTableSize, ref.current,pbnRuseNm??'' ) setIsReset(false); }} resetPageNo={isReset} diff --git a/apps/wr/public/sample_hasuMap.xlsx b/apps/wr/public/sample_hasuMap.xlsx new file mode 100644 index 000000000..70fe3a0d1 Binary files /dev/null and b/apps/wr/public/sample_hasuMap.xlsx differ