From d53115e872d120285c5814b465a2423f54ae4f15 Mon Sep 17 00:00:00 2001 From: leedj312 Date: Sun, 8 Jun 2025 19:19:51 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=AC=EC=9D=B4=EC=9A=A9=EC=8B=9C=EC=84=A4?= =?UTF-8?q?=20=ED=98=84=ED=99=A9=20=EC=A1=B0=ED=9A=8C=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=A1=B0=EB=A6=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruseFcltMng/fcltSttn/pbnstSttn/page.tsx | 38 ++++-- .../ruseFcltMng/fcltSttn/pbnstSttn/excel.tsx | 34 ++--- .../fcltSttn/pbnstSttn/headList.tsx | 32 ++--- .../ruseFcltMng/fcltSttn/pbnstSttn/index.tsx | 119 ++++++++++++++---- 4 files changed, 161 insertions(+), 62 deletions(-) diff --git a/apps/wr/app/ruseFcltMng/fcltSttn/pbnstSttn/page.tsx b/apps/wr/app/ruseFcltMng/fcltSttn/pbnstSttn/page.tsx index 837cf23f1..dd04974e5 100644 --- a/apps/wr/app/ruseFcltMng/fcltSttn/pbnstSttn/page.tsx +++ b/apps/wr/app/ruseFcltMng/fcltSttn/pbnstSttn/page.tsx @@ -18,7 +18,7 @@ import type { customPbnst } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type" import { excelDownload, getCityOrSgg } from "@/components/lib/func/commom"; export default function PbnstSttn() { - const { code, pbnstSttn, pbnstSttnSearch } = useWrStore((state) => state); + const { code, pbnstSttn, pbnstSttnSearch,pbnSttnInit } = useWrStore((state) => state); const ref = useRef({} as ReturnType); const codeData = getCityOrSgg(ref); @@ -28,15 +28,37 @@ export default function PbnstSttn() { const [bdstTable, setBdstTable] = useState(); const excelClick = useCallback(() => { - // if (codeData) pbnstSttnSearch(1, "10000", codeData); - excelDownload( - [[]], - "하수재이용시설 현황", - "sample_pbnstSttn.xlsx", - "A1:U2" - ); + if (codeData) pbnstSttnSearch('1', "10000", codeData); + }, [pbnstSttnSearch, codeData]); + + useEffect(() => { + if(pbnstSttn.excelList.length > 0){ + excelDownload( + pbnstSttn.excelList, + "하수재이용시설 현황", + "sample_pbnstSttn.xlsx", + "A1:U2" + ); + } + + }, [pbnstSttn.excelList]); + useEffect(() => { + if (!pbnstSttn.isInit) { + pbnSttnInit('1','11') + } + + },[pbnstSttn.isInit,pbnSttnInit]) + useEffect(() => { + console.log('pbnstSttn.pbnstSttnRes ', pbnstSttn.pbnstSttnRes) + + + + setBdstTable(pbnstSttn.pbnstSttnRes) + + },[pbnstSttn.pbnstSttnRes]) + return ( <> diff --git a/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/excel.tsx b/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/excel.tsx index a85a009a4..8a1db05a2 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/excel.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/excel.tsx @@ -5,23 +5,23 @@ export const excelPbnstSttnParsing = (data: any[]): string[][] => { data.forEach((item) => { excelExportData.push([ - item.a, - String(item.aaa), - item.aaaa ?? "", - item.operMngCd ?? "", - String(item.cityText ?? ""), - String(item.sggText ?? ""), - String(item.bdnstNm ?? ""), - String(item.archArea ?? ""), - String(item.archArea ?? ""), - String(item.archArea ?? ""), - String(item.archArea ?? ""), - String(item.archArea ?? ""), - String(item.archArea ?? ""), - String(item.archArea ?? ""), - String(item.archArea ?? ""), - String(item.archArea ?? ""), - String(item.archArea ?? ""), + item.rvbsn, + String(item.lgbsn), + item.mdmbsn ?? "", + item.rgnNm ?? "", + String(item.sido ?? ""), + String(item.gugun ?? ""), + String(item.bscFctNm ?? ""), + String(item.efflWqltStndrdNm ?? ""), + String(item.fctCpc ?? ""), + String(item.tel ?? ""), + String(item.ruseUtztnFcltNm ?? ""), + String(item.fcltCpct ?? ""), + String(item.splyExtraCpct ?? ""), + String(item.ruseCpct ?? ""), + String(item.usageTotal ?? ""), + String(item.inUsage ?? ""), + String(item.outUsage ?? ""), ]) }) return excelExportData; diff --git a/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/headList.tsx b/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/headList.tsx index 9439153d2..cb3cf1731 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/headList.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/headList.tsx @@ -3,34 +3,34 @@ import type { CommonTableProps } from "@/app/store/common/type/header"; import { z } from "zod"; export const pbnSttHeadListExport: z.infer = [ - { id: "a", title: "권역", visible: true }, + { id: "rvbsn", title: "권역", visible: true }, { - id: "aaa", + id: "lgbsn", title: "단위유역", visible: true, }, { - id: "aaaa", + id: "mdmbsn", title: "중권역", visible: true, }, - { id: "operMngCd", title: "환경청", visible: true }, + { id: "rgnNm", title: "환경청", visible: true }, { - id: "cityText", + id: "sido", title: "시도", visible: true, }, { - id: "sggText", + id: "gugun", title: "시군구", visible: true, }, - { id: "bdnstNm", title: "시설명", visible: true }, - { id: "locDiv", title: "지역구분", visible: true }, - { id: "phone", title: "전화번호", visible: true }, - - { id: "fcltQuantity", title: "시설용량(톤/일)", visible: true }, - { id: "rusNm", title: "재이용시설명", visible: true }, + { id: "bscFctNm", title: "시설명", visible: true }, + { id: "efflWqltStndrdNm", title: "지역구분", visible: true }, + + { id: "fctCpc", title: "시설용량(톤/일)", visible: true }, + { id: "tel", title: "전화번호", visible: true }, + { id: "ruseUtztnFcltNm", title: "재이용시설명", visible: true }, { id: "fcltCpct", @@ -38,7 +38,7 @@ export const pbnSttHeadListExport: z.infer = [ visible: true, }, { - id: "trbt", + id: "splyExtraCpct", title: "하수처리량(m³/일)", visible: true, }, @@ -49,17 +49,17 @@ export const pbnSttHeadListExport: z.infer = [ }, { - id: "total", + id: "usageTotal", title: "합계", visible: true, }, { - id: "ithlWtr", + id: "inUsage", title: "장내용수", visible: true, }, { - id: "othlWtr", + id: "outUsage", title: "장외용수", visible: true, }, diff --git a/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/index.tsx b/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/index.tsx index 8b06db529..deb2176a6 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/index.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltSttn/pbnstSttn/index.tsx @@ -1,14 +1,12 @@ import type { CommonTableProps } from "@/app/store/common/type/header"; import type { z } from "zod"; -import { - pbnSttHeadListExport, - pbnstSttNodeListExport -} from "./headList"; -import { fetchType, getFetch } from "@/components/lib/api"; +import { pbnSttHeadListExport, pbnstSttNodeListExport } from "./headList"; +import { fetchType, getFetch, postFectch } from "@/components/lib/api"; import { controlHeadView } from "../rainSttn"; import type { sttnHeadListType } from "../rainSttn/headList"; -import type { customPbnst } from "../../fcltReg/pbnstReg/type"; +import type { customPbnst, pubHasuType } from "../../fcltReg/pbnstReg/type"; import { excelPbnstSttnParsing } from "./excel"; +import type { FcPrfType } from "@/app/store/prfmncReg/pbnstPrfmncReg/type"; const pbnstSttHeadList = pbnSttHeadListExport; const pbnstSttNodeList = pbnstSttNodeListExport; @@ -24,10 +22,9 @@ export type pbnstSttnState = { }; type pbnstSttnActions = { - pbnstChSttnHead: ( - headList: z.infer, - ) => void; - pbnstSttnSearch: (page: number, total: string, con: string) => void; + pbnstChSttnHead: (headList: z.infer) => void; + pbnstSttnSearch: (page: string, total: string, con: string) => void; + pbnSttnInit: (page: string, sggOrCity: string) => void; }; export type pbnstSttnType = pbnstSttnState & pbnstSttnActions; @@ -42,6 +39,72 @@ export const pbnstSttnStateExport: pbnstSttnState = { }, }; +const checkWrRegList = async () => { + const wrRegList = await getFetch("wr", `/reuseFc/pubDetailList`); + return wrRegList; +}; +const hasuListFetch = async (page: string, sggOrCity: string) => { + const checkWrRegListRes = await checkWrRegList(); + const rainRes = await postFectch( + `/prcsFclt/ruseInfo/${page ? page : 1}/10/A/${sggOrCity ? sggOrCity : "11"}/0/1/SW`, + checkWrRegListRes?.fcltCds, + fetchType.COMMON + ); + const data = checkWrRegListRes.fcPrfList.map((item: FcPrfType) => { + const findData = rainRes.data.find( + (fclt: pubHasuType) => + fclt.bscFctCd === item.pbnstRuseFcltPk.substring(0, 11) + ); + const usage = item.prfList.reduce( + (acc, cur) => { + acc.inUsage += + cur.wshwtr + + cur.coolUswtr + + cur.cleanUswtr + + cur.drwtUswtr + + cur.dltnUswtr + + cur.ithlRswtr + + cur.ithlEtcUswtr + + cur.cleanToilUswtr + + cur.resn; + acc.outUsage += + cur.lndwtr + + cur.hydUswtr + + cur.ugwtChr + + cur.farmUswtr + + cur.rvrKeepUswtr + + cur.indstUswtr; + acc.total = acc.inUsage + acc.outUsage; + + return acc; + }, + { total: 0, inUsage: 0, outUsage: 0 } + ); + return { + rvbsn: findData?.rvbsn, + lgbsn: findData?.lgbsn, + mdmbsn: findData?.mdmbsn, + rgnNm: findData?.rgnNm, + sido: findData?.sido, + gugun: findData?.gugun, + bscFctNm: findData?.bscFctNm, + efflWqltStndrdNm: findData?.efflWqltStndrdNm, + fctCpc: findData.fctCpc, + tel: findData?.lclgvrnmnt ?? "-", + ruseUtztnFcltNm: item.ruseUtztnFcltNm, + fcltCpct: item.fcltCpct, + splyExtraCpct: item.splyExtraCpct, + ruseCpct: item.ruseCpct, + pbnstRuseFcltPk: item.pbnstRuseFcltPk, + usageTotal: usage.total, + inUsage: usage.inUsage, + outUsage: usage.outUsage, + fcOpers: item?.fcOpers ?? [], + }; + }); + return data; +}; + export const pbnstSttnActionsExport: (set: any) => pbnstSttnActions = ( set: any ) => { @@ -49,9 +112,7 @@ export const pbnstSttnActionsExport: (set: any) => pbnstSttnActions = ( pbnstChSttnHead: async ( headList: z.infer ): Promise => { - - console.log('head ', headList) - const changeNodeList = controlHeadView(headList, pbnstSttNodeList) + const changeNodeList = controlHeadView(headList, pbnstSttNodeList); return set((state: pbnstSttnState) => ({ pbnstSttn: { @@ -61,12 +122,11 @@ export const pbnstSttnActionsExport: (set: any) => pbnstSttnActions = ( }, })); }, - pbnstSttnSearch: async (page: number, total: string, con: string) => { + pbnstSttnSearch: async (page: string, total: string, con: string) => { try { - const pbnstSttnRes = await getFetch( - fetchType.WR, - `/reuseFc/waterreuseFc/${page}/${total}/${con}` - ); + + const pbnstSttnRes = await hasuListFetch(page, con); + console.log("pbnstSttnRes", pbnstSttnRes); if (Number(total) > 9000) { const pbnstExcel = excelPbnstSttnParsing(pbnstSttnRes); set((state: pbnstSttnState) => { @@ -80,7 +140,6 @@ export const pbnstSttnActionsExport: (set: any) => pbnstSttnActions = ( }); } else set((state: pbnstSttnState) => { - return { ...state, pbnstSttn: { @@ -94,5 +153,23 @@ export const pbnstSttnActionsExport: (set: any) => pbnstSttnActions = ( console.log("error", erTxt); } }, - } -} + pbnSttnInit: async (page: string, sggOrCity: string) => { + try { + const pbnstSttnRes = await hasuListFetch(page, sggOrCity); + console.log("pbnstSttnRes", pbnstSttnRes); + set((state: pbnstSttnState) => { + return { + ...state, + pbnstSttn: { + ...state.pbnstSttn, + pbnstSttnRes: pbnstSttnRes, + isInit: false, + }, + }; + }); + } catch (erTxt) { + console.log("error", erTxt); + } + }, + }; +};