diff --git a/apps/wr/app/stats/rainStat/page.tsx b/apps/wr/app/stats/rainStat/page.tsx index 7b822875a..b2f2006bf 100644 --- a/apps/wr/app/stats/rainStat/page.tsx +++ b/apps/wr/app/stats/rainStat/page.tsx @@ -1,7 +1,9 @@ "use client"; import { useWrStore } from "@/app/store"; -import { yearOptions } from "@/components/lib/func/commom"; +import type { RainStatProps } from "@/app/store/stats/rainStat"; +import { tableData, yearOptions } from "@/components/lib/func/commom"; +import { downloadExcel } from "@common/business_components"; import { ContentsDiv, SearchDiv, @@ -11,19 +13,72 @@ import { } from "@common/business_components/ui"; import ListDiv from "@common/business_components/ui/list_div"; import { Button } from "@common/components/ui"; -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; export default function RainStat() { - const { rainStat, searchRainStatList } = useWrStore((state) => state) - const [ pageNation, setPageNation] = useState(1); + const { code, rainStat, searchRainStatList } = useWrStore((state) => state); + const { rainStatHeadList, rainStatList, excelList } = rainStat; + + const [pageNation, setPageNation] = useState(1); const [searchYear, setSearchYear] = useState( String(new Date().getFullYear()) ); + const [exData, setExData] = useState>>(); + const [bdstTable, setBdstTable] = useState(); useEffect(() => { searchRainStatList(searchYear); }, [searchRainStatList, searchYear]) + const excelClick = () => { + downloadExcel({ + data: (exData as unknown as JSON[]) ?? [], + fileName: "재이용통계", + sheetNameArray: ["Sheet1"], + headerRange: "A1:M1" + }) + } + + + useEffect(() => { + const transExcel = Array.isArray(excelList) ? excelList : [excelList]; + const excelData = tableData(transExcel, { code }); + const tbData = Array.isArray(excelData) + ? excelData.map((item: RainStatProps) => { + return { + "시도": item.cityText, + "개소": item.tmp, + "설치비(백만원)": item.instlCst, + "저류조용량(m³/년)": item.dtfcltCpct, + "연간사용량(m³/년)": item.wtrUsqty, + "조경용수": item.lndwtr, + "청소화장실용수": item.cleanToilUswtr, + "세척살수용수": item.resn, + "농업용수": item.farmUswtr, + "공업용수": item.indstUswtr, + "친수용수": item.hydUswtr, + "기타": item.ithlEtcUswtr, + "연간운영비(백만원/년)": item.anlOperCst, + }; + }) + : []; + setExData(tbData); + }, [excelList]) + + useEffect(() => { + const transData = Array.isArray(rainStatList) ? rainStatList : [rainStatList]; + const data = tableData(transData, { code }); + const tbData = Array.isArray(data) + ? data.map((item: RainStatProps) => { + return { + ...item, + ctpvCd: item.cityText + }; + }) + : []; + setBdstTable(tbData); + }, [rainStatList]); + return ( <> @@ -45,13 +100,13 @@ export default function RainStat() { />
- - -
@@ -66,12 +121,12 @@ export default function RainStat() { {/* */} {}} + headName={""} + cellClick={(val, headId) => { }} onPageChange={setPageNation} > {/* */} diff --git a/apps/wr/app/store/stats/rainStat/headList.tsx b/apps/wr/app/store/stats/rainStat/headList.tsx index 412b79178..664e060c4 100644 --- a/apps/wr/app/store/stats/rainStat/headList.tsx +++ b/apps/wr/app/store/stats/rainStat/headList.tsx @@ -2,72 +2,78 @@ import type { TableUpperProps } from "../../common/type/header"; export const rainStatHeadListExport: TableUpperProps[] = [ { - id: "시도", + id: "ctpvCd", title: "시도", row:0, rowSpan:2 }, { - id: "개소", + id: "tmp", title: "개소", row:0, rowSpan:2 }, { - id: "설치비", + id: "instlCst", title: "설치비(백만원)", row:0, rowSpan:2 }, { - id: "저류조용량", + id: "dtfcltCpct", title: "저류조용량(m³/년)", row:0, rowSpan:2 }, { - id: "이용용도", + id: "wtrUsqty", + title: "연간사용량(㎥/년)", + row:0, + rowSpan:2 + }, + { + id: "a", title: "이용용도", row:0, colSpan:7 }, { - id: "조경용수", + id: "lndwtr", title: "조경용수", row:1, }, { - id: "청소화장실용수", + id: "cleanToilUswtr", title: "청소화장실용수", row:1, }, { - id:"세척살수용수", + id:"resn", title:"세척살수용수", row:1, }, { - id: "농업용수", + id: "farmUswtr", title: "농업용수", row:1, }, { - id: "공업용수", + id: "indstUswtr", title: "공업용수", row:1, }, { - id: "친수용수", + id: "hydUswtr", title: "친수용수", row:1, }, { - id: "기타", + id: "ithlEtcUswtr", title: "기타", row:1, }, { - id: "연간운영비", + id: "anlOperCst", title: "연간운영비(백만원/년)", row:0, rowSpan:2 diff --git a/apps/wr/app/store/stats/rainStat/index.tsx b/apps/wr/app/store/stats/rainStat/index.tsx index ed34c539e..edb5ab0d5 100644 --- a/apps/wr/app/store/stats/rainStat/index.tsx +++ b/apps/wr/app/store/stats/rainStat/index.tsx @@ -3,47 +3,61 @@ import type { TableUpperProps } from "../../common/type/header"; import { rainStatHeadListExport } from "./headList"; export type RainStatProps = { - ctpvCd : string //시도 - sggCd : string //시군구 - areaNm : string //행정구역명 - bdstNm : string //시설명 - bdstUsgCd : string //건축물용도코드 - daddr : string //주소 - lawTrgtYn : string //법적의무대상여부 - instlCmptnDt : string //설치완료일자 - instlCst : number //설치비용 - pntfColKnd : string //접수면종류 - filtrTrtmfctYn : string //여과등처리시설유무 - archArea : number //건축연면적 - dtfcltCpct : number //처리용량(저류조용량) - wtrUsqty : number //연간사용량 - utztnUsgCd : string //이용용도코드 - anlOperCst : number //연간운영비 - annRnwtQty : number //물사용량 - jungsudo : number //중수도​이용량 - dachae : number //대체수​이용량 - way1 : number //방법1 - way2 : number //방법2 - way3 : number //방법3 - way4 : number //방법4 - way5 : number //방법5 - way6 : number //방법6 - way7 : number //방법7 + ctpvCd: string //시도 + sggCd: string //시군구 + areaNm: string //행정구역명 + bdstNm: string //시설명 + bdstUsgCd: string //건축물용도코드 + daddr: string //주소 + lawTrgtYn: string //법적의무대상여부 + instlCmptnDt: string //설치완료일자 + instlCst: number //설치비용 + pntfColKnd: string //접수면종류 + filtrTrtmfctYn: string //여과등처리시설유무 + archArea: number //건축연면적 + dtfcltCpct: number //처리용량(저류조용량) + wtrUsqty: number //연간사용량 + utztnUsgCd: string //이용용도코드 + anlOperCst: number //연간운영비 + annRnwtQty: number //물사용량 + jungsudo: number //중수도​이용량 + dachae: number //대체수​이용량 + lndwtr: number //조경용수 + cleanToilUswtr: number //청소화장실용수 + resn: number //세척살수용수 + farmUswtr: number //농업용수 + indstUswtr: number //공업용수 + hydUswtr: number //친수용수 + ithlEtcUswtr: number //기타 + tmp: number //개소 + guideStats: GuideStatProps[] } -const fetchRainStatList = async (year:string) => { - const res = await getFetch(fetchType.WR,`/reuseChk/rainy/stat/${year}`) +export type GuideStatProps = { + utztnUsgCd: string + ruseFcltUtztnQnt: number +} + +type ExcelType = { + [key: string]: string | number | undefined; +}; + +const excelDownList: ExcelType[] = []; + +const fetchRainStatList = async (year: string) => { + const res = await getFetch(fetchType.WR, `/reuseChk/rainy/stat/${year}`) return res; } type rainStatActions = { - searchRainStatList : (year:string) => void + searchRainStatList: (year: string) => void } export type rainStatState = { rainStat: { - rainStatHeadList:TableUpperProps[], - rainStatList : RainStatProps[] + rainStatHeadList: TableUpperProps[], + rainStatList: RainStatProps[], + excelList: ExcelType[] } } @@ -51,38 +65,17 @@ export type rainStatType = rainStatState & rainStatActions; export const rainStatExport: rainStatState = { rainStat: { - rainStatHeadList:rainStatHeadListExport, - rainStatList : [] + rainStatHeadList: rainStatHeadListExport, + rainStatList: [], + excelList: [] } } export const rainStatActionsExport = ( set: (fn: (state: rainStatState) => rainStatState) => void ) => { return { - searchRainStatList : async (year:string) => { + searchRainStatList: async (year: string) => { const res = await fetchRainStatList(year); -<<<<<<< Updated upstream - const rainStatList: never[] = []; - /* const rainStatHeadList = data.map((item:RainStatProps) => ({ - ...item, - ctpvCd:item.ctpvCd, - sggCd:item.sggCd, - areaNm:item.areaNm, - archArea:item.archArea, - dtfcltCpct:item.dtfcltCpct, - annRnwtQty:item.annRnwtQty, - jungsudo:item.jungsudo, - dachae:item.dachae, - way1:item.way1, - way2:item.way2, - way3:item.way3, - way4:item.way4, - way5:item.way5, - way6:item.way6, - way7:item.way7, - yearMoney:item.yearMoney, - })) */ -======= let cityArr: any[] = []; res.forEach((item: RainStatProps) => { @@ -124,13 +117,32 @@ export const rainStatActionsExport = ( }) } }) ->>>>>>> Stashed changes + + cityArr.forEach(item => { + excelDownList.push({ + ctpvCd: item.ctpvCd, + tmp: item.tmp, + instlCst: item.instlCst, //설치비 + dtfcltCpct: item.dtfcltCpct, //저류조용량 + bdstUsgCd: item.bdstUsgCd, //연간사용량 + lndwtr: item.lndwtr, //조경용수 + cleanToilUswtr: item.cleanToilUswtr, //청소화장실용수 + resn: item.resn, //세척살수용수 + farmUswtr: item.farmUswtr, //농업용수 + indstUswtr: item.indstUswtr, //공업용수 + hydUswtr: item.hydUswtr, //친수용수 + ithlEtcUswtr: item.ithlEtcUswtr, //기타 + anlOperCst: item.anlOperCst, //연간운영비 + }) + }) + set((state: rainStatState) => ({ rainStat: { ...state.rainStat, - rainStatList: rainStatList, + rainStatList: cityArr, + excelList: excelDownList } })); } } -} \ No newline at end of file +}