diff --git a/apps/wr/app/ruseFcltMng/prfmncSttn/pbnstPrfmncSttn/page.tsx b/apps/wr/app/ruseFcltMng/prfmncSttn/pbnstPrfmncSttn/page.tsx index 9267f8ae6..dd2d0999b 100644 --- a/apps/wr/app/ruseFcltMng/prfmncSttn/pbnstPrfmncSttn/page.tsx +++ b/apps/wr/app/ruseFcltMng/prfmncSttn/pbnstPrfmncSttn/page.tsx @@ -3,39 +3,43 @@ import { useWrStore } from "@/app/store"; import { btnClass } from "@/app/store/common/code"; import type { FcPrfType, PrfType } from "@/app/store/prfmncReg/pbnstPrfmncReg/type"; +import type { prfmncType } from "@/app/store/prfmncSttn/pbnstPrfmncSttn/headList"; import { yearOptions } from "@/components/lib/func/commom"; -import { ContentsDiv, Title, SearchBaseForm, SelectBox, SearchInput, UiTable } from "@common/business_components"; +import { ContentsDiv, Title, SearchBaseForm, SelectBox, SearchInput, UiTable, type ReturnType, } from "@common/business_components"; +import DoughnutChart from "@common/business_components/ui/chart/DoughnutChart"; import ListDiv from "@common/business_components/ui/list_div"; import { Button, Label } from "@common/components/ui"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; export default function PbnstPrfmncSttn() { - const { code, tableHeadMaker, pbnstPrfmncSttn, pbnstPrfmncInit } = useWrStore((state) => state); + const { code, tableHeadMaker, pbnstPrfmncSttn, pbnstPrfmncInit, pbnstPrfmncSearch } = useWrStore((state) => state); const { pbnstPrfHeadList, pbnstPrfmncRes, prfmncRes } = pbnstPrfmncSttn; const [isChHead, setIsChHead] = useState(false); const [fromDate, setFromDate] = useState(String(new Date().getFullYear())); const [toDate, setToDate] = useState(String(new Date().getFullYear())); - const [pbnstTable, setPbnstTable] = useState(); + const [year, setYear] = useState(String(new Date().getFullYear())); + const [pbnstTable, setPbnstTable] = useState(); const [bdstTable, setbdstTable] = useState(); + const ref = useRef({} as ReturnType); + const [swtrmtFcltNm, setSwtrmtFcltNm] = useState(); + + useEffect(() => { - console.log("pbnstPrfmncRes", pbnstPrfmncRes ) - setPbnstTable([]); - }, [pbnstPrfmncRes]); - + if (!pbnstPrfmncSttn.isInit) { + pbnstPrfmncInit("1", "11"); + } + }, [pbnstPrfmncSttn.isInit, pbnstPrfmncInit]); useEffect(() => { - console.log("prfmncRes",prfmncRes) + console.log("prfmncRes", prfmncRes) setbdstTable(prfmncRes); }, [prfmncRes]); useEffect(() => { - pbnstPrfmncInit(); - }, [pbnstPrfmncInit]); - - + }, [ref.current]); return ( <> @@ -79,8 +83,9 @@ export default function PbnstPrfmncSttn() { { + setSwtrmtFcltNm(e) }} /> { }} /> } - queryClick={function (): void { + queryClick={function (returnType: ReturnType): void { + pbnstPrfmncSearch(returnType, swtrmtFcltNm ?? "", fromDate, toDate); if (fromDate && toDate) { const fromNum = Number(fromDate); const toNum = Number(toDate); @@ -109,7 +115,7 @@ export default function PbnstPrfmncSttn() { excelClick={() => { }} initClick={function (): void { }} btnClass={btnClass} - /> + ref={ref} />
@@ -117,17 +123,38 @@ export default function PbnstPrfmncSttn() { { }} onPageChange={() => { }} /> + +
+

하수재이용실적 상세현황

+ + setYear(String(val))} /> +

장내·외 용도별 하수재이용실적 현황(계)

+ +
+
{ }} chartData={[]} chartTitle={"장내·외 용수 총 실적"}> +
+
{ }} chartData={[]} chartTitle={"장내용수 실적"}> +
+
{ }} chartData={[]} chartTitle={"장외용수 실적"}> +
+
+

장내·외 월별 하수재이용실적 현황

-
) diff --git a/apps/wr/app/store/prfmncSttn/pbnstPrfmncSttn/headList.tsx b/apps/wr/app/store/prfmncSttn/pbnstPrfmncSttn/headList.tsx index 2953d3b6a..d04ef7b20 100644 --- a/apps/wr/app/store/prfmncSttn/pbnstPrfmncSttn/headList.tsx +++ b/apps/wr/app/store/prfmncSttn/pbnstPrfmncSttn/headList.tsx @@ -1,3 +1,4 @@ +import { z } from "zod"; import type { TableUpperProps } from "../../ruseFcltMng/fcltReg/rainReg"; export const pbnstPrfmncSttnHeadListExport: TableUpperProps[] = [ @@ -5,55 +6,54 @@ export const pbnstPrfmncSttnHeadListExport: TableUpperProps[] = [ id: "number", title: "No", rowSpan: 2, - row:0 + row: 0 }, { id: "sido", title: "시도", rowSpan: 2, - row:0 + row: 0 }, { id: "gugun", title: "시군구", rowSpan: 2, - row:0 + row: 0 }, { id: "bscFctNm", title: "시설명", rowSpan: 2, - row:0 + row: 0 }, { id: "ruseUtztnFcltNm", title: "재이용시설명", rowSpan: 2, - row:0 + row: 0 }, ] export const pbnstYearHeadListExport: TableUpperProps[] = [ { - id: "ym", title: "년도", colSpan: 3, - row:0 + row: 0 }, { id: "total", title: "계", - row:1 + row: 1 }, { - id: "jangnae", + id: "inUsage", title: "장내용수", - row:1 + row: 1 }, { - id: "jangoi", + id: "outUsage", title: "장외용수", - row:1 + row: 1 }, ] diff --git a/apps/wr/app/store/prfmncSttn/pbnstPrfmncSttn/index.tsx b/apps/wr/app/store/prfmncSttn/pbnstPrfmncSttn/index.tsx index da8215404..e3b7b941b 100644 --- a/apps/wr/app/store/prfmncSttn/pbnstPrfmncSttn/index.tsx +++ b/apps/wr/app/store/prfmncSttn/pbnstPrfmncSttn/index.tsx @@ -1,11 +1,14 @@ -import { fetchType, getFetch } from "@/components/lib/api"; +import { fetchType, getFetch, postFectch } from "@/components/lib/api"; import type { TableUpperProps } from "../../common/type/headder"; import { pbnstPrfmncSttnHeadListExport, pbnstYearHeadListExport } from "./headList"; import type { FcPrfType, PrfType } from "../../prfmncReg/pbnstPrfmncReg/type"; +import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type"; +import type { ReturnType } from "@common/business_components"; type pbnstPrfmncSttnActions = { tableHeadMaker: (startYear: number, endYear: number) => void; - pbnstPrfmncInit: () => void; + pbnstPrfmncInit: (page: string, sggOrCity: string) => void; + pbnstPrfmncSearch: (returnType: ReturnType, swtrmtFcltNm: string, fromDate: string, toDate: string) => void; } const pbnstPrfmncRes: PrfType[] = []; @@ -15,7 +18,7 @@ export type pbnstPrfmncSttnState = { pbnstPrfmncSttn: { pbnstPrfHeadList: TableUpperProps[]; pbnstPrfmncRes: PrfType[]; - prfmncRes: FcPrfType[]; + prfmncRes: any[]; isInit: boolean; } } @@ -31,6 +34,33 @@ export const pbnstPrfmncSttnExport: pbnstPrfmncSttnState = { } } +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) + ); + return { + sido: findData?.sido, + gugun: findData?.gugun, + bscFctNm: findData?.bscFctNm, + ruseUtztnFcltNm: item.ruseUtztnFcltNm, + pbnstRuseFcltPk: item.pbnstRuseFcltPk, + }; + }); + return data; +} + export const pbnstPrfmncSttnActionsExport: (set: any) => pbnstPrfmncSttnActions = ( set: any ) => { @@ -40,7 +70,7 @@ export const pbnstPrfmncSttnActionsExport: (set: any) => pbnstPrfmncSttnActions for (let i = startYear; i <= endYear; i++) { const yearHead = JSON.parse(JSON.stringify(pbnstYearHeadListExport)); if (yearHead) { - yearHead.forEach((item: { id: number; }) => (item.id = i + item.id)) + yearHead.forEach((item: { id?: number; }) => {if(item.id)item.id = i + item.id;}) if (yearHead[0]) yearHead[0].title = i + "년도" } @@ -55,31 +85,93 @@ export const pbnstPrfmncSttnActionsExport: (set: any) => pbnstPrfmncSttnActions }; }); }, - pbnstPrfmncInit: async () => { + pbnstPrfmncInit: async (page: string, sggOrCity: string) => { try { - const pbnstPrfmncSttnRes = await getFetch('wr', `/reuseFc/pubDetailList`); - console.log("이안에", pbnstPrfmncSttnRes) - const ruseFcltPk = pbnstPrfmncSttnRes.fcltCds; - console.log("이거다", ruseFcltPk) - const ruseFcltRes = await getFetch('wr', `/reuseFc/pubFc/${ruseFcltPk}`); - console.log("이제나올듯", ruseFcltRes) - - - set((state: pbnstPrfmncSttnState) => { - return { - ...state, - pbnstPrfmncSttn: { - ...state.pbnstPrfmncSttn, - pbnstPrfmncSttnRes: pbnstPrfmncSttnRes, - ruseFcltRes: ruseFcltRes, - isInit: false, - }, - }; - }); + const prfmncRes = await hasuListFetch(page, sggOrCity); + return set((state: pbnstPrfmncSttnState) => ({ + ...state, + pbnstPrfmncSttn: { + ...state.pbnstPrfmncSttn, + prfmncRes: prfmncRes, + isInit: false, + }, + })); } catch (e) { console.log(e) } }, + pbnstPrfmncSearch: async (returnType: ReturnType, swtrmtFcltNm: string, fromDate: string, toDate: string) => { + let searchUrl = ""; + if (returnType.sigunValue !== undefined) { + if (swtrmtFcltNm !== "") { + searchUrl = `/prcsFclt/info/1/20/${returnType.partValue}/${returnType.sigunValue}/0/1/SW${'/' + swtrmtFcltNm}`; + } else { + searchUrl = `/prcsFclt/info/1/20/${returnType.partValue}/${returnType.sigunValue}/0/1/SW`; + } + } else { + if (swtrmtFcltNm !== "") { + searchUrl = `/prcsFclt/info/1/20/${returnType.partValue}/${returnType.sidoValue}/0/1/SW${'/' + swtrmtFcltNm}`; + } else { + searchUrl = `/prcsFclt/info/1/20/${returnType.partValue}/${returnType.sidoValue}/0/1/SW`; + } + } + + const pbnstRes = await getFetch( + fetchType.COMMON, + searchUrl + ); + const bscFctCdList = pbnstRes.map((item: any) => { + return item.bscFctCd; + }) + const res = await postFectch( + `/reuseFc/pubDetailList/${fromDate}/${toDate}`, + bscFctCdList, + `wr`, + ) + + let inUsageSum = 0; + let outUsageSum = 0; + let usageSum = 0; + let year = ""; + const yearsData = [] + res.data.forEach((item) => { + item.prfList.forEach((acc) => { + year = acc.ym.substring(0, 4); + inUsageSum = acc.wshwtr + acc.coolUswtr + acc.cleanUswtr + acc.drwtUswtr + + acc.dltnUswtr + acc.ithlRswtr + acc.ithlEtcUswtr + acc.cleanToilUswtr + acc.resn; + outUsageSum = acc.lndwtr + acc.hydUswtr + acc.ugwtChr + acc.farmUswtr + acc.rvrKeepUswtr + acc.indstUswtr; + const yearData = yearsData.find(yearItem => yearItem.year === year && yearItem.pbnstRuseFcltPk == acc.pbnstRuseFcltPk) + + if (yearData) { + yearData.inUsageSum += inUsageSum; + yearData.outUsageSum += outUsageSum; + } else { + const yearVal = { year: year, pbnstRuseFcltPk: acc.pbnstRuseFcltFk } + yearVal[year + 'inUsage'] = inUsageSum; + yearVal[year + 'outUsage'] = outUsageSum; + yearVal[year + 'total'] = inUsageSum+outUsageSum; + yearsData.push(yearVal); + } + + }) + }) + const resData:any[] = [] + pbnstRes.forEach((acc) => { let data = yearsData.find((item) => item.pbnstRuseFcltPk.substring(0, 11) === acc.bscFctCd) + if(data){ + resData.push({...data, ...acc}) + } + }) + + + + return set((state: pbnstPrfmncSttnState) => ({ + ...state, + pbnstPrfmncSttn: { + ...state.pbnstPrfmncSttn, + prfmncRes:resData + }, + })); + } } -} +} \ No newline at end of file diff --git a/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx b/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx index 5a59c21e4..719e9c271 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx @@ -83,7 +83,7 @@ export type chgBuilding={ } export type customRainBdst = z.infer export type TableUpperProps = { - id: string; + id?: string; title: string; upName?: string; upSequnce?: number;