diff --git a/apps/fo/app/pages/underWaterInput/modal/page.tsx b/apps/fo/app/pages/underWaterInput/modal/page.tsx index 9e49fb1bc..145612431 100644 --- a/apps/fo/app/pages/underWaterInput/modal/page.tsx +++ b/apps/fo/app/pages/underWaterInput/modal/page.tsx @@ -1,6 +1,6 @@ "use client" import { useFoStore } from "@/app/store"; -import type { UnderWaterInputModalProps } from "@/app/store/underWaterInput"; +import type { UnderWaterInputModalProps } from "@/app/store/underWaterInput/types"; import { DateMonthPicker, UITab, UiTable } from "@common/business_components/ui"; import ListDiv from "@common/business_components/ui/list_div"; import { Table, TableCell, TableHead, TableRow, TabsContent } from "@common/components/ui"; @@ -19,7 +19,7 @@ const tabList1 = [ export default function UnderWaterInputModal({fcltyName='', searchYear=new Date().getFullYear().toString()} : ModalProps) { // 그리드 관련 - const {UnderWaterDetail} = useFoStore((state) => state); + const {UnderWaterDetail, unserWaterModal} = useFoStore((state) => state); const [startYmDate, setStartYmDate] = useState(searchYear+'01'); const [endYmDate, setEndYmDate] = useState(searchYear+'12'); @@ -115,7 +115,10 @@ export default function UnderWaterInputModal({fcltyName='', searchYear=new Date( setPrevEndYmDate(searchYear+'12'); } }, [searchYear, tabTerm]); - + useEffect(()=>{ + console.log(fcltyName, searchYear); + unserWaterModal(fcltyName, searchYear); + }, []) useEffect(() => { if(endYmDate < startYmDate) { alert('종료일이 시작일보다 작습니다.') diff --git a/apps/fo/app/pages/underWaterInput/page.tsx b/apps/fo/app/pages/underWaterInput/page.tsx index 93a6f0863..d57c894dd 100644 --- a/apps/fo/app/pages/underWaterInput/page.tsx +++ b/apps/fo/app/pages/underWaterInput/page.tsx @@ -5,7 +5,7 @@ import { ContentsDiv, downloadExcel, MainDiv, SearchBaseForm, SearchInput, Selec import ListDiv from "@common/business_components/ui/list_div"; import { useCallback, useEffect, useRef, useState } from "react"; import UnderWaterInputModal from "./modal/page"; -import type { UnderWaterProps } from "@/app/store/underWaterInput"; +import type { UnderWaterProps } from "@/app/store/underWaterInput/types"; export default function UnderWaterInput() { const {Common @@ -115,7 +115,7 @@ export default function UnderWaterInput() { // 셀 클릭 시 모달 표시 const cellClick = (index: number) => { if (underWater[index]) { - setFcltyNm(underWater[index].bscFctNm); + setFcltyNm(underWater[index].bscFctCd); setSelectedRow(index); // 클릭한 행의 index 저장 } }; diff --git a/apps/fo/app/store/sewageOccur/index.tsx b/apps/fo/app/store/sewageOccur/index.tsx index 4bf285230..d27aaee49 100644 --- a/apps/fo/app/store/sewageOccur/index.tsx +++ b/apps/fo/app/store/sewageOccur/index.tsx @@ -140,12 +140,6 @@ const fetchSewageOccurList = async (pageNo: number, pageSize: number, searchYear return { data: res.data, count: res.count } */ } -const fetchSewageOccurDetailList = async (bscFctCd: string, searchYear: string) => { - const url = '/fclt/flow/' + bscFctCd + '/' + searchYear; - const res = await getFetch('fo', url); - return { data: res.data, count: res.count } -} - /**==================================== * Store - expaort ====================================*/ @@ -230,8 +224,7 @@ export const sewageOccurReducer:(set:any)=>SewageOccurActions=(set: any) => { const bscFctCd = item.bscFctCd; - const url2 = '/fclt/flow/' + bscFctCd + '/' + searchYear; - const res2 = await getFetch('fo', url2) as FlowResponse; + const res2 = await getFetch('fo', '/fclt/flow/' + bscFctCd + '/' + searchYear) as FlowResponse; let sumChungcunDay = 0; let chungcunSumFlow = 0; @@ -265,7 +258,7 @@ export const sewageOccurReducer:(set:any)=>SewageOccurActions=(set: any) => { }, searchSewageOccurDetailList: async (bscFctCd: string, searchYear: string) => { - const res = await fetchSewageOccurDetailList(bscFctCd, searchYear); + const res = await getFetch('fo', '/fclt/flow/' + bscFctCd + '/' + searchYear); const monthData: SewageOccurDetailProps[] = []; let tot = 0, cnt= 0 res.data.forEach((item: FlowDataItem) => { diff --git a/apps/fo/app/store/underWaterInput/index.tsx b/apps/fo/app/store/underWaterInput/index.tsx index ea6f4575b..6d067ae58 100644 --- a/apps/fo/app/store/underWaterInput/index.tsx +++ b/apps/fo/app/store/underWaterInput/index.tsx @@ -1,6 +1,8 @@ import DataForm from "@/app/components/common/DataForm"; import type { TableUpperProps } from "../dashboard"; import { getFetch } from "@/app/components/api"; +import type { ExcelType, UnderWaterInputModalProps, UnderWaterProps } from "./types"; +import type { modalTableType, SewageOccurDetailProps } from "../sewageOccur"; export type { TableUpperProps }; /**==================================== * Store - 타입 @@ -10,47 +12,6 @@ export type { TableUpperProps }; * (1) 메인페이지 */ // 시설별 강수현황 -export type UnderWaterProps = { - bscFctCd : string, - lclgvrnmntNm : string, - sidoNm : string, - sggNm : string, - bscFctNm : string, - daddr : string, - fctCpc : number, - underWaterInputYear : number, - underWaterInputSummer : number, - underWaterInputWinter : number, - infoRnDay : number, - rgnNm : string, - rvbsn : string, - lgbsn : string, - mdmbsn : string, -} -export interface UnderWaterInterface { - bscFctCd : string, - sidoNm : string, - sggNm : string, - bscFctNm : string, - daddr : string, - fctCpc : number, - underWaterInputYear : number, - underWaterInputSummer : number, - underWaterInputWinter : number, - infoRnDay : number, - rgnNm : string, - rvbsn : string, - lgbsn : string, - mdmbsn : string, -} - -// 모달 -export interface UnderWaterInputModalProps { - msrDt : string, - realSewageInput : number | '', - sewageOccur : number | '', - underWaterInput : number | '', -} /**==================================== * Store - data @@ -62,22 +23,6 @@ export interface UnderWaterInputModalProps { // 검색단 const LabelArray:string[] = ['구분', '시도', '시군구','용량별', '시설명', '조회기간', '시설상태', '권역', '단위유역', '중권역', '환경청별']; -export interface ExcelType { - 시설코드: string, - 권역:string|'', - 단위유역:string|'', - 중권역:string|'', - 환경청:string|'', - 시도: string, - 시군구: string, - 시설명: string, - 주소: string, - 시설용량: number, - 연간지하수유입량: number | '', - 하절기지하수유입량: number | '', - 동절기지하수유입량: number | '', -} - // 리스트 헤더 const upHeadList1:TableUpperProps[] = [ { id: "bscFctCd", title: "시설코드", row:0, rowSpan:2 }, @@ -247,6 +192,7 @@ const fetchUnderWaterList = async (pageNo: number, pageSize: number, searchYear: ====================================*/ export type UnderWaterActions = { searchUnderWaterList: (pageNo: number, pageSize: number, searchYear: string, part?: string, nameCd?: string, fcltCpct?: string, operationValue?: string, fcltyNm?: string) => void; + unserWaterModal:(bscFctCd:string, searchYear:string)=>void } export type UnderWaterType = { @@ -315,8 +261,7 @@ export const underWaterReducer:(set:(fn: (state: UnderWaterType) => UnderWaterTy item.fctCpc = parseFloat(item.fctCpc.toString().replace(/,/g, '')); const bscFctCd = item.bscFctCd; - const url2 = '/fclt/flow/' + bscFctCd + '/' + searchYear; - const res2 = await getFetch('fo', url2) as ApiResponse; + const res2 = await getFetch('fo', '/fclt/flow/' + bscFctCd + '/' + searchYear) as ApiResponse; let sumChungcunDay = 0; let chungcunSumFlow = 0; @@ -393,5 +338,77 @@ export const underWaterReducer:(set:(fn: (state: UnderWaterType) => UnderWaterTy } })) }, + unserWaterModal:async (bscFctCd, searchYear)=>{ + const res = await getFetch('fo', '/fclt/flow/' + bscFctCd + '/' + searchYear); + const monthData: SewageOccurDetailProps[] = []; + let tot = 0, cnt= 0 + res.data.forEach((item: FlowDataItem) => { + const month = item.msrDt?.substring(4, 6); + const monthIdx = month ? Number(month) - 1 : -1; + if (monthIdx >= 0) { + if (typeof monthData[monthIdx] === 'object') { + monthData[monthIdx].sum += Number(item.inflAmnt); + monthData[monthIdx].cnt++; + } else { + monthData[monthIdx] = {cnt:1, sum:Number(item.inflAmnt), yr:item.msrDt.substring(0,4), usege:0}; + } + } + tot += Number(item.inflAmnt) + cnt++ + }) + const tableData:UnderWaterInputModalProps[] = [] + + let maxWaterUsage = 0; + let minWaterUsage = 9999999999; + let avgWaterUsage = 0; + monthData.forEach((item, index) => { + item.usege = item.sum/item.cnt + tableData.push({ + msrDt: item.yr+'-'+(index+1>10?String(index+1):'0'+(index+1)), + realSewageInput:Math.round(item.usege*100) /100, + sewageOccur:Math.round(item.usege*0.65*0.8 * 100) / 100, + underWaterInput:Math.round((item.usege-(item.usege*0.65*0.8)) * 100) / 100, + }) + if (item.usege > maxWaterUsage) { + maxWaterUsage = item.usege; + } + + if (item.usege < minWaterUsage) { + minWaterUsage = item.usege; + } + + }); + avgWaterUsage = tot/cnt + + const newData= [ + { + msrDt: '평균', + realSewageInput:Math.round(avgWaterUsage*100) /100, + sewageOccur:Math.round(avgWaterUsage*0.65*0.8 * 100) / 100, + underWaterInput:Math.round((avgWaterUsage-(avgWaterUsage*0.65*0.8)) * 100) / 100, + }, + { + msrDt: '최대', + realSewageInput: Math.round(maxWaterUsage*100) /100, + sewageOccur: Math.round(maxWaterUsage*0.65*0.8 * 100) / 100, + underWaterInput: Math.round((maxWaterUsage-(maxWaterUsage*0.65*0.8)) * 100) / 100, + }, + { + msrDt: '최소', + realSewageInput: Math.round(minWaterUsage*100) /100, + sewageOccur: Math.round(minWaterUsage*0.65*0.8 * 100) / 100, + underWaterInput: Math.round((minWaterUsage-(minWaterUsage*0.65*0.8)) * 100) / 100, + }, + ...tableData + ] + + set((state: UnderWaterType) => ({ + ...state, + UnderWaterDetail: { + ...state.UnderWaterDetail, + gridListUnderWaterDetail:newData + } + })) + } } } \ No newline at end of file diff --git a/apps/fo/app/store/underWaterInput/types.tsx b/apps/fo/app/store/underWaterInput/types.tsx new file mode 100644 index 000000000..c90c654ad --- /dev/null +++ b/apps/fo/app/store/underWaterInput/types.tsx @@ -0,0 +1,58 @@ +export type UnderWaterProps = { + bscFctCd : string, + lclgvrnmntNm : string, + sidoNm : string, + sggNm : string, + bscFctNm : string, + daddr : string, + fctCpc : number, + underWaterInputYear : number, + underWaterInputSummer : number, + underWaterInputWinter : number, + infoRnDay : number, + rgnNm : string, + rvbsn : string, + lgbsn : string, + mdmbsn : string, +} +export interface UnderWaterInterface { + bscFctCd : string, + sidoNm : string, + sggNm : string, + bscFctNm : string, + daddr : string, + fctCpc : number, + underWaterInputYear : number, + underWaterInputSummer : number, + underWaterInputWinter : number, + infoRnDay : number, + rgnNm : string, + rvbsn : string, + lgbsn : string, + mdmbsn : string, +} + +// 모달 +export interface UnderWaterInputModalProps { + msrDt : string, + realSewageInput : number | '', + sewageOccur : number | '', + underWaterInput : number | '', +} + + +export interface ExcelType { + 시설코드: string, + 권역:string|'', + 단위유역:string|'', + 중권역:string|'', + 환경청:string|'', + 시도: string, + 시군구: string, + 시설명: string, + 주소: string, + 시설용량: number, + 연간지하수유입량: number | '', + 하절기지하수유입량: number | '', + 동절기지하수유입량: number | '', +} \ No newline at end of file