diff --git a/apps/fo/app/pages/facilityWaterQlty/modal/page.tsx b/apps/fo/app/pages/facilityWaterQlty/modal/page.tsx index ede0175aa..19129762e 100644 --- a/apps/fo/app/pages/facilityWaterQlty/modal/page.tsx +++ b/apps/fo/app/pages/facilityWaterQlty/modal/page.tsx @@ -1,8 +1,8 @@ "use client" import { useFoStore } from "@/app/store"; -import type { FacilityWaterQltyProps } from "@/app/store/facilityWaterQlty"; -import { UITab, UiTable } from "@common/business_components/ui"; -import { TabsContent } from "@common/components/ui"; +import type { FacilityWaterQltyProps, modalExcelType } from "@/app/store/facilityWaterQlty"; +import { downloadExcel, UITab, UiTable } from "@common/business_components/ui"; +import { Button, TabsContent } from "@common/components/ui"; import { useCallback, useEffect, useRef, useState } from "react"; import type { ReturnType } from "../../../components/common/FacilityTermModalHeader"; import FacilityTermModalHeader from "../../../components/common/FacilityTermModalHeader"; @@ -37,8 +37,9 @@ export default function WaterQualityModal({fcltyName='', facilityCd='', searchYe // 그리드 관련 const {FacilityWaterQltyModal, searchFacilityWaterQltyListHist, + Common } = useFoStore((state) => state); - + const {btnClass} = Common; const { upHeadListModalYear, facilityWaterQltyYearList, @@ -48,6 +49,8 @@ export default function WaterQualityModal({fcltyName='', facilityCd='', searchYe upHeadListModalChongIn, } = FacilityWaterQltyModal; + const prevExcelListRef = useRef(null); + // 필터링 된 후 최대, 최소, 평균 값 계산 const setFilterAfterData = (filteredData: FacilityWaterQltyProps[]) => { // 쉼표가 포함된 문자열을 숫자로 변환하는 함수 @@ -284,9 +287,40 @@ export default function WaterQualityModal({fcltyName='', facilityCd='', searchYe setCopyYearList(filteredData as FacilityWaterQltyProps[]); }, []); + const excelDownload = () => { + const excelDownList: modalExcelType[] = []; + if(copyYearList.length > 0){ + copyYearList.forEach((item) => { + excelDownList.push({ + 날짜: item.msrDt, + "유입BOD(mg/L)": item.inflAssctAftWqltBod, + "유입TOC(COD)(mg/L)": item.inflAssctAftWqltToc, + "유입SS(mg/L)": item.inflAssctAftWqltSs, + "유입TN(mg/L)": item.inflAssctAftWqltTn, + "유입TP(mg/L)": item.inflAssctBfrWqltTp, + "유출BOD(mg/L)": item.efflWqltBod, + "유출TOC(COD)(mg/L)": item.efflWqltCod, + "유출SS(mg/L)": item.efflWqltSs, + "유출TN(mg/L)": item.efflWqltTn, + "유출TP(mg/L)": item.efflWqltTp, + "강우량(일)": item.infoRnDay?item.infoRnDay.toString():"0.0", + }); + }); + } + if (excelDownList && excelDownList.length > 0) { + downloadExcel({ data: JSON.parse(JSON.stringify(excelDownList)), fileName: searchYear+'년 '+fcltyName + ' 수질현황', sheetNameArray: [fcltyName + ' 수질현황'], headerRange: 'A1:L1' }); + } else if (prevExcelListRef.current && prevExcelListRef.current.length > 0) { + alert('다운받을 데이터가 없습니다.'); + } + prevExcelListRef.current = excelDownList; + } + return ( <> + {/* 처리시설 수질현황 */} diff --git a/apps/fo/app/pages/flowRate/modal/page.tsx b/apps/fo/app/pages/flowRate/modal/page.tsx index f30ea0794..8d78ab804 100644 --- a/apps/fo/app/pages/flowRate/modal/page.tsx +++ b/apps/fo/app/pages/flowRate/modal/page.tsx @@ -1,9 +1,9 @@ "use client" import FacilityTermModalHeader from "@/app/components/common/FacilityTermModalHeader"; import { useFoStore } from "@/app/store"; -import type { FlowRateModalInterface } from "@/app/store/flowRate"; -import { UITab, UiTable } from "@common/business_components/ui"; -import { TabsContent } from "@common/components/ui"; +import type { FlowRateModalInterface, modalExcelType } from "@/app/store/flowRate"; +import { downloadExcel, UITab, UiTable } from "@common/business_components/ui"; +import { Button, TabsContent } from "@common/components/ui"; import { useCallback, useEffect, useRef, useState } from "react"; import type { ReturnType } from "../../../components/common/FacilityTermModalHeader"; @@ -17,10 +17,11 @@ const tabList = [ export default function FlowRateModal(props: { fcltyName: string; facilityCd: string; searchYear: string }) { // 그리드 관련 - const { FlowRateModal, searchFlowRateModalList } = useFoStore((state) => state); + const { Common, FlowRateModal, searchFlowRateModalList } = useFoStore((state) => state); + const { btnClass } = Common; const [copyYearList, setCopyYearList] = useState([]); const [isLoading, setIsLoading] = useState(true); - + const prevExcelListRef = useRef(null); const { modalFlowRateListYear, upHeadListFlowRateModalYear, @@ -150,9 +151,35 @@ export default function FlowRateModal(props: { fcltyName: string; facilityCd: st return
로딩 중...
; } + const excelDownload = () => { + const excelDownList: modalExcelType[] = []; + if(copyYearList.length > 0){ + copyYearList.forEach((item) => { + excelDownList.push({ + "날짜": item.msrDt, + "총유입량(m³/일)": item.totInflAmnt, + "하수유입량(m³/일)": item.inflAmnt, + "연계처리량(m³/일)": item.sumFlow, + "총인반류수량(m³/일)": item.returnAmnt, + "방류량(m³/일)": item.efflAmnt, + "강우량": item.infoRnDay, + }); + }); + } + if (excelDownList && excelDownList.length > 0) { + downloadExcel({ data: JSON.parse(JSON.stringify(excelDownList)), fileName: props.searchYear+'년 '+props.fcltyName + ' 유량현황', sheetNameArray: [props.fcltyName + ' 유량현황'], headerRange: 'A1:G1' }); + } else if (prevExcelListRef.current && prevExcelListRef.current.length > 0) { + alert('다운받을 데이터가 없습니다.'); + } + prevExcelListRef.current = excelDownList; + } + return ( <> + searchList={modalFlowRateListYear} diff --git a/apps/fo/app/store/facilityWaterQlty/index.tsx b/apps/fo/app/store/facilityWaterQlty/index.tsx index d1bff7723..6430522f4 100644 --- a/apps/fo/app/store/facilityWaterQlty/index.tsx +++ b/apps/fo/app/store/facilityWaterQlty/index.tsx @@ -92,6 +92,21 @@ export interface WaterQualityHistoryResponse { }; } +export type modalExcelType = { + 날짜: string; + "유입BOD(mg/L)": string; + "유입TOC(COD)(mg/L)": string; + "유입SS(mg/L)": string; + "유입TN(mg/L)": string; + "유입TP(mg/L)": string; + "유출BOD(mg/L)": string; + "유출TOC(COD)(mg/L)": string; + "유출SS(mg/L)": string; + "유출TN(mg/L)": string; + "유출TP(mg/L)": string; + "강우량(일)": string; +} + /**==================================== * Store - data ====================================*/ diff --git a/apps/fo/app/store/flowRate/index.tsx b/apps/fo/app/store/flowRate/index.tsx index b26df617e..cd847b628 100644 --- a/apps/fo/app/store/flowRate/index.tsx +++ b/apps/fo/app/store/flowRate/index.tsx @@ -47,9 +47,17 @@ export interface ExcelType { 총인반류수량: number | '', 방류량: number | '', 환경청:string|'', - } +export type modalExcelType = { + 날짜: string, + "총유입량(m³/일)": number | '', + "하수유입량(m³/일)": number | '', + "연계처리량(m³/일)": number | '', + "총인반류수량(m³/일)": number | '', + "방류량(m³/일)": number | '', + "강우량": number | '', +} /** * (2) 모달 */