From 7235999ecd3da2db23ee847f4402ba4fd991fff9 Mon Sep 17 00:00:00 2001 From: jyha00 Date: Wed, 18 Jun 2025 14:35:48 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=EB=B9=97=EB=AC=BC=EC=8B=9C=EC=84=A4?= =?UTF-8?q?=ED=86=B5=EA=B3=84=20=EC=8B=9C=EB=8F=84=20groupby?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wr/app/store/stats/rainStat/index.tsx | 95 +++++++++++++++------- 1 file changed, 67 insertions(+), 28 deletions(-) diff --git a/apps/wr/app/store/stats/rainStat/index.tsx b/apps/wr/app/store/stats/rainStat/index.tsx index 2a1a5bc5a..447c2d54a 100644 --- a/apps/wr/app/store/stats/rainStat/index.tsx +++ b/apps/wr/app/store/stats/rainStat/index.tsx @@ -3,40 +3,40 @@ import type { TableUpperProps } from "../../common/type/header"; import { rainStatHeadListExport } from "./headList"; export type RainStatProps = { - ctpvCd : string //시도 - sggCd : string //시군구 - areaNm : string //행정구역명 - instlCst : number //설치비용 - archArea : number //건축연면적 - dtfcltCpct : number //처리용량(저류조용량) - wtrUsqty : number //연간사용량 - 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 //행정구역명 + instlCst: number //설치비용 + archArea: number //건축연면적 + dtfcltCpct: number //처리용량(저류조용량) + wtrUsqty: number //연간사용량 + 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 } -const fetchRainStatList = async (year:string) => { - const res = await getFetch(fetchType.WR,`/reuseChk/rainy/stat/${year}`) - console.log(res); - return []; +const fetchRainStatList = async (year: string) => { + const res = await getFetch(fetchType.WR, `/reuseChk/rainy/stat/${year}`) + // console.log(res); + return res; } type rainStatActions = { - searchRainStatList : (year:string) => void + searchRainStatList: (year: string) => void } export type rainStatState = { rainStat: { - rainStatHeadList:TableUpperProps[], - rainStatList : RainStatProps[] + rainStatHeadList: TableUpperProps[], + rainStatList: RainStatProps[] } } @@ -44,17 +44,56 @@ export type rainStatType = rainStatState & rainStatActions; export const rainStatExport: rainStatState = { rainStat: { - rainStatHeadList:rainStatHeadListExport, - rainStatList : [] + rainStatHeadList: rainStatHeadListExport, + rainStatList: [] } } export const rainStatActionsExport = ( set: (fn: (state: rainStatState) => rainStatState) => void ) => { return { - searchRainStatList : async (year:string) => { + searchRainStatList: async (year: string) => { const res = await fetchRainStatList(year); const rainStatList: never[] = []; + + const grouped = Object.groupBy(res, (item: RainStatProps) => item.ctpvCd); + console.log("grouped", grouped); + + Object.values(grouped).forEach((item) => { + if (!item) return; + let instlCst = 0; + let dtfcltCpct = 0; + let wtrUsqty = 0; + let anlOperCst = 0; + let way1 = 0; + let way2 = 0; + let way3 = 0; + let way4 = 0; + let way5 = 0; + let way6 = 0; + let way7 = 0; + + item.forEach((element) => { + instlCst += element.instlCst; + dtfcltCpct += element.dtfcltCpct; + wtrUsqty += element.wtrUsqty; + anlOperCst += element.anlOperCst; + way1 += element.way1; + way2 += element.way2; + way3 += element.way3; + way4 += element.way4; + way5 += element.way5; + way6 += element.way6; + way7 += element.way7; + }) + + console.log("instlCst", instlCst) + console.log("dtfcltCpct", dtfcltCpct) + + }) + + + /* const rainStatHeadList = data.map((item:RainStatProps) => ({ ...item, ctpvCd:item.ctpvCd, From d52f0137ca8782af64fe85bcea1ae69c2a1fa8c5 Mon Sep 17 00:00:00 2001 From: jyha00 Date: Wed, 18 Jun 2025 16:48:03 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EB=B9=97=EB=AC=BC=ED=86=B5=EA=B3=84=20?= =?UTF-8?q?=EC=A7=84=ED=96=89=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wr/app/stats/rainStat/page.tsx | 10 ++- apps/wr/app/store/stats/rainStat/headList.tsx | 16 +++-- apps/wr/app/store/stats/rainStat/index.tsx | 62 ++++++++++--------- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/apps/wr/app/stats/rainStat/page.tsx b/apps/wr/app/stats/rainStat/page.tsx index 7b822875a..26fc6340a 100644 --- a/apps/wr/app/stats/rainStat/page.tsx +++ b/apps/wr/app/stats/rainStat/page.tsx @@ -1,6 +1,7 @@ "use client"; import { useWrStore } from "@/app/store"; +import type { RainStatProps } from "@/app/store/stats/rainStat"; import { yearOptions } from "@/components/lib/func/commom"; import { ContentsDiv, @@ -14,7 +15,9 @@ import { Button } from "@common/components/ui"; import { useEffect, useState } from "react"; export default function RainStat() { - const { rainStat, searchRainStatList } = useWrStore((state) => state) + const { rainStat, searchRainStatList } = useWrStore((state) => state); + const { rainStatHeadList, rainStatList } = rainStat; + const [ pageNation, setPageNation] = useState(1); const [searchYear, setSearchYear] = useState( String(new Date().getFullYear()) @@ -22,6 +25,7 @@ export default function RainStat() { useEffect(() => { searchRainStatList(searchYear); + console.log("rainStatList", rainStatList) }, [searchRainStatList, searchYear]) return ( @@ -66,11 +70,11 @@ export default function RainStat() { {/* */} {}} onPageChange={setPageNation} > diff --git a/apps/wr/app/store/stats/rainStat/headList.tsx b/apps/wr/app/store/stats/rainStat/headList.tsx index 412b79178..3b01c40c5 100644 --- a/apps/wr/app/store/stats/rainStat/headList.tsx +++ b/apps/wr/app/store/stats/rainStat/headList.tsx @@ -2,29 +2,35 @@ 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: "wtrUsqty", + title: "연간사용량(㎥/년)", + row:0, + rowSpan:2 + }, { id: "이용용도", title: "이용용도", @@ -67,7 +73,7 @@ export const rainStatHeadListExport: TableUpperProps[] = [ 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 08e17b2ce..d22ae7a1a 100644 --- a/apps/wr/app/store/stats/rainStat/index.tsx +++ b/apps/wr/app/store/stats/rainStat/index.tsx @@ -22,6 +22,7 @@ export type RainStatProps = { way5 : number //방법5 way6 : number //방법6 way7 : number //방법7 + tmp : number //개소 } const fetchRainStatList = async (year:string) => { @@ -54,17 +55,19 @@ export const rainStatActionsExport = ( return { searchRainStatList: async (year: string) => { const res = await fetchRainStatList(year); - const rainStatList: never[] = []; + const rainStatList: RainStatProps[] = []; const grouped = Object.groupBy(res, (item: RainStatProps) => item.ctpvCd); console.log("grouped", grouped); Object.values(grouped).forEach((item) => { if (!item) return; + let ctpvCd = ""; let instlCst = 0; - let dtfcltCpct = 0; - let wtrUsqty = 0; - let anlOperCst = 0; + let tmp = 0; //개소 + let dtfcltCpct = 0; //설치비용 + let wtrUsqty = 0; //연간사용량 + let anlOperCst = 0; //연간운영비 let way1 = 0; let way2 = 0; let way3 = 0; @@ -74,7 +77,9 @@ export const rainStatActionsExport = ( let way7 = 0; item.forEach((element) => { + ctpvCd = element.ctpvCd; instlCst += element.instlCst; + tmp += 1; dtfcltCpct += element.dtfcltCpct; wtrUsqty += element.wtrUsqty; anlOperCst += element.anlOperCst; @@ -85,34 +90,33 @@ export const rainStatActionsExport = ( way5 += element.way5; way6 += element.way6; way7 += element.way7; + + }) + + rainStatList.push({ + instlCst, + tmp, + dtfcltCpct, + wtrUsqty, + anlOperCst, + way1, + way2, + way3, + way4, + way5, + way6, + way7, + ctpvCd, + // sggCd: "", + // areaNm: "", + // bdstNm: "", + // archArea: 0, + // annRnwtQty: 0, + // jungsudo: 0, + // dachae: 0 }) - - console.log("instlCst", instlCst) - console.log("dtfcltCpct", dtfcltCpct) - }) - - - /* 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, - })) */ set((state: rainStatState) => ({ rainStat: { ...state.rainStat, From 421eedb6f28259df34e7c3c89eaefa9b273a85ff Mon Sep 17 00:00:00 2001 From: jyha00 Date: Wed, 18 Jun 2025 20:18:53 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EB=B9=97=EB=AC=BC=EC=9E=AC=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=86=B5=EA=B3=84=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EB=82=98=ED=83=80=EB=82=B4=EA=B8=B0=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wr/app/store/stats/rainStat/headList.tsx | 16 +- apps/wr/app/store/stats/rainStat/index.tsx | 164 ++++++++---------- 2 files changed, 84 insertions(+), 96 deletions(-) diff --git a/apps/wr/app/store/stats/rainStat/headList.tsx b/apps/wr/app/store/stats/rainStat/headList.tsx index 3b01c40c5..664e060c4 100644 --- a/apps/wr/app/store/stats/rainStat/headList.tsx +++ b/apps/wr/app/store/stats/rainStat/headList.tsx @@ -32,43 +32,43 @@ export const rainStatHeadListExport: TableUpperProps[] = [ rowSpan:2 }, { - id: "이용용도", + 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, }, diff --git a/apps/wr/app/store/stats/rainStat/index.tsx b/apps/wr/app/store/stats/rainStat/index.tsx index 67baed954..c7c073bca 100644 --- a/apps/wr/app/store/stats/rainStat/index.tsx +++ b/apps/wr/app/store/stats/rainStat/index.tsx @@ -3,37 +3,43 @@ 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 - tmp : number //개소 + 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 +} + +const fetchRainStatList = async (year: string) => { + const res = await getFetch(fetchType.WR, `/reuseChk/rainy/stat/${year}`) return res; } @@ -62,74 +68,56 @@ export const rainStatActionsExport = ( return { searchRainStatList: async (year: string) => { const res = await fetchRainStatList(year); - const rainStatList: RainStatProps[] = []; - const grouped = Object.groupBy(res, (item: RainStatProps) => item.ctpvCd); - console.log("grouped", grouped); - - Object.values(grouped).forEach((item) => { - if (!item) return; - let ctpvCd = ""; - let instlCst = 0; - let tmp = 0; //개소 - let dtfcltCpct = 0; //설치비용 - let wtrUsqty = 0; //연간사용량 - let anlOperCst = 0; //연간운영비 - let way1 = 0; - let way2 = 0; - let way3 = 0; - let way4 = 0; - let way5 = 0; - let way6 = 0; - let way7 = 0; - - item.forEach((element) => { - ctpvCd = element.ctpvCd; - instlCst += element.instlCst; - tmp += 1; - dtfcltCpct += element.dtfcltCpct; - wtrUsqty += element.wtrUsqty; - anlOperCst += element.anlOperCst; - way1 += element.way1; - way2 += element.way2; - way3 += element.way3; - way4 += element.way4; - way5 += element.way5; - way6 += element.way6; - way7 += element.way7; - - }) + let cityArr: any[] = []; + res.forEach((item: RainStatProps) => { - rainStatList.push({ - instlCst, - tmp, - dtfcltCpct, - wtrUsqty, - anlOperCst, - way1, - way2, - way3, - way4, - way5, - way6, - way7, - ctpvCd, - // sggCd: "", - // areaNm: "", - // bdstNm: "", - // archArea: 0, - // annRnwtQty: 0, - // jungsudo: 0, - // dachae: 0 + let obj = cityArr.find((e) => { + return e.ctpvCd == item.ctpvCd }) + + if (obj) { + obj.instlCst += item.instlCst + obj.dtfcltCpct += item.dtfcltCpct + obj.wtrUsqty += item.wtrUsqty + obj.anlOperCst += item.anlOperCst + obj.tmp += 1 + } else { + obj = {}; + obj.ctpvCd = item.ctpvCd + obj.instlCst = item.instlCst + obj.tmp = 1 + obj.dtfcltCpct = item.dtfcltCpct + obj.wtrUsqty = item.wtrUsqty + obj.anlOperCst = item.anlOperCst + + cityArr.push(obj) + } + + if (item.guideStats && item.guideStats.length > 0) { + item.guideStats.forEach((guide: GuideStatProps) => { + rainStatHeadListExport.forEach((headItem: TableUpperProps) => { + + if (headItem.title == guide.utztnUsgCd) { + if (!obj[headItem.id] || typeof obj[headItem.id] !== "number") obj[headItem.id] = 0; + if (typeof obj[headItem.id] === "number") { + + obj[headItem.id] += guide.ruseFcltUtztnQnt; + console.log("obj", obj) + } + } + }); + }) + } + }) set((state: rainStatState) => ({ rainStat: { ...state.rainStat, - rainStatList: rainStatList, + rainStatList: cityArr, } })); } } -} \ No newline at end of file +}