유량현황, 수질현황 모달 엑셀다운로드 완료

This commit is contained in:
YangJinSoo94
2025-07-16 17:13:19 +09:00
parent 114293bb00
commit e4f4f70bc9
4 changed files with 94 additions and 10 deletions
@@ -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<modalExcelType[] | null>(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 (
<>
<UITab tabList={tabList1} defaultValue="tab_num1">
<Button className={btnClass} style={{float: 'right'}} color="green" onClick={excelDownload}>
{"엑셀다운로드"}
</Button>
{/* 처리시설 수질현황 */}
<TabsContent value="tab_num1">
<UITab tabList={tabList2} defaultValue="tab_term_year">
+32 -5
View File
@@ -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<FlowRateModalInterface[]>([]);
const [isLoading, setIsLoading] = useState(true);
const prevExcelListRef = useRef<modalExcelType[] | null>(null);
const {
modalFlowRateListYear,
upHeadListFlowRateModalYear,
@@ -150,9 +151,35 @@ export default function FlowRateModal(props: { fcltyName: string; facilityCd: st
return <div>로딩 중...</div>;
}
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 (
<>
<UITab tabList={tabList} defaultValue="tab_term_year">
<Button className={btnClass} style={{float: 'right'}} color="green" onClick={excelDownload}>
{"엑셀다운로드"}
</Button>
<TabsContent value="tab_term_year">
<FacilityTermModalHeader<FlowRateModalInterface>
searchList={modalFlowRateListYear}
@@ -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
====================================*/
+9 -1
View File
@@ -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) 모달
*/