Files
frontend/apps/fo/app/store/facilityWaterQlty/index.tsx
T

741 lines
36 KiB
TypeScript

import { getFetch, postFetch } from "@/app/components/api";
import DataForm, { roundNumber } from "@/app/components/common/DataForm";
import type { TableUpperProps } from "../dashboard";
import CalcRainEffect from "@/app/components/common/CalcRainEffect";
import { COD_YEAR } from "../common"; // 2021년
import CommaToNumber from "@/app/components/common/CommaToNumber";
export type { TableUpperProps };
/**====================================
* Store - 타입
*
* tn, tp는 소수점 3자리까지, 나머지는 소수점 1자리까지
====================================*/
/**
* (1) 메인페이지
*/
// RDII 상세 타입
export interface FacilityRdiiDetailProps {
msrDt: string, // 측정일
inflAssctBfrWqltBod: string | '', // 유입연계전수질_BOD(mg/L)
inflAmnt: number | '', // 실제유입량(반류수제거)(m³/일)
infoRnDay: number | string | '', // 강수량 (mm/일)
}
// 시설수질리스트 타입
export interface FacilityWaterQltyProps {
bscFctCd: string,
bscFctNm: string,
msrDt: string,
sido: string,
gugun: string,
// sidoNm: string,
// sggNm: string,
addr: string,
fctCpc: number,
inflAssctBfrWqltBod: string | '',
inflAssctAftWqltBod: string | '',
inflAssctBfrWqltToc: string | '',
inflAssctAftWqltToc: string | '',
inflAssctBfrWqltCod: string | '',
inflAssctAftWqltCod: string | '',
inflAssctBfrWqltSs: string | '',
inflAssctAftWqltSs: string | '',
inflAssctBfrWqltTn: string | '',
inflAssctAftWqltTn: string | '',
inflAssctBfrWqltTp: string | '',
inflAssctAftWqltTp: string | '',
efflWqltBod: string | '',
efflWqltToc: string | '',
efflWqltCod: string | '',
efflWqltSs: string | '',
efflWqltTn: string | '',
efflWqltTp: string | '',
rgnNm: string | '',
rvbsn: string | '',
lgbsn: string | '',
mdmbsn: string | '',
inflAmnt: number | '',
lclgvrnmntNm: string,
infoRnDay: number | string | '',
rainEffectDay: number | '',
tpInflWqltTmprtr: number | '',
tpInflWqltPh: string | '',
tpInflWqltBod: string | '',
tpInflWqltCod: string | '',
tpInflWqltSs: string | '',
tpInflWqltTn: string | '',
tpInflWqltTp: string | '',
tpInflWqltEclgyTox: string | '',
tpInflWqltClfgrpcnt: string | '',
noProcessInflAmnt: string | number | '',
}
export interface ExcelType {
시설코드: string,
권역: string | '',
단위유역: string | '',
중권역: string | '',
환경청: string | '',
시도: string,
시군구: string,
시설이름: string,
주소: string,
"시설용량(m³/일)": number | '',
"유입BOD(mg/L)": number | '',
"유입TOC(mg/L)": number | '',
"유입SS(mg/L)": number | '',
"유입TN(mg/L)": number | '',
"유입TP(mg/L)": number | '',
"유출BOD(mg/L)": number | '',
"유출TOC(mg/L)": number | '',
"유출SS(mg/L)": number | '',
"유출TN(mg/L)": number | '',
"유출TP(mg/L)": number | '',
}
/**
* (2) 모달페이지
*/
// 시설수질리스트 타입
export type FacilityWaterQltyTmsProps = {
part: string,
toc: number,
ss: number,
tn: number,
tp: number,
}
// API 응답 데이터 타입
export interface WaterQualityHistoryResponse {
data: {
wqltObjs: FacilityWaterQltyProps[];
};
}
export type modalExcelType = {
날짜: string;
"유입BOD(mg/L)": number | '';
"유입TOC(COD)(mg/L)": number | '';
"유입SS(mg/L)": number | '';
"유입TN(mg/L)": number | '';
"유입TP(mg/L)": number | '';
"유출BOD(mg/L)": number | '';
"유출TOC(COD)(mg/L)": number | '';
"유출SS(mg/L)": number | '';
"유출TN(mg/L)": number | '';
"유출TP(mg/L)": number | '';
"강우량(mm/일)": number | '';
}
export type modalChoinginExcelType = {
날짜: string;
"유입BOD(mg/L)": number | '';
"유입TP(mg/L)": number | '';
"유출BOD(mg/L)": number | '';
"유출TP(mg/L)": number | '';
}
/**====================================
* Store - data
====================================*/
/**
* (1) 메인페이지
*/
// 메인 라벨 배열
const mainLabelArray: string[] = ['구분', '시도', '시군구', '용량별', '시설명', '조회기간', '시설상태', '권역', '단위유역', '중권역', '환경청별'];
// 시설수질리스트 헤더(행정별)
const upHeadList1: TableUpperProps[] = [
{ id: "C", title: "행정명", colSpan: 2, row: 0, widthPercent: 10 },
{ id: "sido", title: "시도", row: 1, widthPercent: 5 },
{ id: "gugun", title: "시군구", row: 1, widthPercent: 5 },
{ id: "bscFctNm", title: "시설명", rowSpan: 2, row: 0, widthPercent: 10 },
{ id: "addr", title: "주소", rowSpan: 2, row: 0 },
{ id: "fctCpc", title: "시설용량(m³/일)", align: "right", rowSpan: 2, row: 0, widthPercent: 10 },
{ id: "A", title: "유입", colSpan: 5, row: 0, widthPercent: 25 },
{ id: "B", title: "방류", colSpan: 5, row: 0, widthPercent: 25 },
{ id: "inflAssctBfrWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe3", upSequnce: 1, align: "right", row: 1, widthPercent: 5 },
{ id: "inflAssctBfrWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row: 1, widthPercent: 5 },
{ id: "inflAssctBfrWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row: 1, widthPercent: 5 },
{ id: "inflAssctBfrWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe3", upSequnce: 4, align: "right", row: 1, widthPercent: 5 },
{ id: "inflAssctBfrWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe4", upSequnce: 1, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe4", upSequnce: 4, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row: 1, widthPercent: 5 },
];
// 시설수질리스트 헤더(권역별)
const upHeadList2: TableUpperProps[] = [
{ id: "C", title: "유역", colSpan: 3, row: 0, widthPercent: 15 },
{ id: "rvbsn", title: "권역", upName: "upChangeRe1", upSequnce: 1, row: 1, widthPercent: 5 },
{ id: "lgbsn", title: "단위유역", upName: "upChangeRe1", upSequnce: 2, row: 1, widthPercent: 5 },
{ id: "mdmbsn", title: "중권역", upName: "upChangeRe1", upSequnce: 3, row: 1, widthPercent: 5 },
{ id: "bscFctNm", title: "시설명", row: 0, rowSpan: 2, widthPercent: 10 },
{ id: "addr", title: "주소", row: 0, rowSpan: 2 },
{ id: "fctCpc", title: "시설용량(m³/L)", align: "right", row: 0, rowSpan: 2, widthPercent: 8 },
{ id: "A", title: "유입", colSpan: 5, row: 0, widthPercent: 25 },
{ id: "B", title: "방류", colSpan: 5, row: 0, widthPercent: 25 },
{ id: "inflAssctBfrWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe3", upSequnce: 1, align: "right", row: 1, widthPercent: 5 },
{ id: "inflAssctBfrWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row: 1, widthPercent: 5 },
{ id: "inflAssctBfrWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row: 1, widthPercent: 5 },
{ id: "inflAssctBfrWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row: 1, widthPercent: 5 },
{ id: "inflAssctBfrWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe4", upSequnce: 1, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row: 1, widthPercent: 5 },
{ id: "efflWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row: 1, widthPercent: 5 },
];
// 시설수질리스트 헤더(환경청별)
const upHeadList3: TableUpperProps[] = [
{ id: "C", title: "유역", colSpan: 3, row: 0, widthPercent: 15 },
{ id: "rvbsn", title: "권역", row: 1, widthPercent: 5 },
{ id: "lgbsn", title: "단위유역", row: 1, widthPercent: 5 },
{ id: "mdmbsn", title: "중권역", row: 1, widthPercent: 5 },
{ id: "rgnNm", title: "환경청", row: 0, rowSpan: 2, widthPercent: 7 },
{ id: "D", title: "행정명", colSpan: 2, row: 0, widthPercent: 10 },
{ id: "sido", title: "시도", upName: "upChangeRe2", row: 1, widthPercent: 5 },
{ id: "gugun", title: "시군구", upName: "upChangeRe2", row: 1, widthPercent: 5 },
{ id: "bscFctNm", title: "시설명", row: 0, rowSpan: 2, widthPercent: 8 },
{ id: "addr", title: "주소", row: 0, rowSpan: 2 },
{ id: "fctCpc", title: "시설용량(m³/L)", align: "right", row: 0, rowSpan: 2, widthPercent: 5 },
{ id: "A", title: "유입", colSpan: 5, row: 0, widthPercent: 20 },
{ id: "B", title: "방류", colSpan: 5, row: 0, widthPercent: 20 },
{ id: "inflAssctBfrWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe3", upSequnce: 1, align: "right", row: 1, widthPercent: 4 },
{ id: "inflAssctBfrWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row: 1, widthPercent: 4 },
{ id: "inflAssctBfrWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row: 1, widthPercent: 4 },
{ id: "inflAssctBfrWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row: 1, widthPercent: 4 },
{ id: "inflAssctBfrWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row: 1, widthPercent: 4 },
{ id: "efflWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe4", upSequnce: 1, align: "right", row: 1, widthPercent: 4 },
{ id: "efflWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row: 1, widthPercent: 4 },
{ id: "efflWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row: 1, widthPercent: 4 },
{ id: "efflWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row: 1, widthPercent: 4 },
{ id: "efflWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row: 1, widthPercent: 4 },
];
/**
* (2) 모달페이지
*/
// 처리시설 수질현황 헤더(모달-연간)
const upHeadListModalYear: TableUpperProps[] = [
{ id: "msrDt", title: "날짜" },
{ id: "inflAssctBfrWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe1", upSequnce: 1, align: "right" },
{ id: "inflAssctBfrWqltToc", title: "TOC(COD)\n(mg/L)", upName: "upChangeRe1", upSequnce: 2, align: "right" },
{ id: "inflAssctBfrWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe1", upSequnce: 3, align: "right" },
{ id: "inflAssctBfrWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe1", upSequnce: 2, align: "right" },
{ id: "inflAssctBfrWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe1", upSequnce: 3, align: "right" },
{ id: "efflWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe2", upSequnce: 1, align: "right" },
{ id: "efflWqltToc", title: "TOC(COD)\n(mg/L)", upName: "upChangeRe2", upSequnce: 2, align: "right" },
{ id: "efflWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe2", upSequnce: 3, align: "right" },
{ id: "efflWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe2", upSequnce: 2, align: "right" },
{ id: "efflWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe2", upSequnce: 3, align: "right" },
{ id: "infoRnDay", title: "강우량\n(mm/일)", align: "right" }
];
// 처리시설 수질현황 헤더(모달-연간)
const upHeadListModalYearCod: TableUpperProps[] = [
{ id: "msrDt", title: "날짜" },
{ id: "inflAssctBfrWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe1", upSequnce: 1, align: "right" },
{ id: "inflAssctBfrWqltCod", title: "TOC(COD)\n(mg/L)", upName: "upChangeRe1", upSequnce: 2, align: "right" },
{ id: "inflAssctBfrWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe1", upSequnce: 3, align: "right" },
{ id: "inflAssctBfrWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe1", upSequnce: 2, align: "right" },
{ id: "inflAssctBfrWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe1", upSequnce: 3, align: "right" },
{ id: "efflWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe2", upSequnce: 1, align: "right" },
{ id: "efflWqltCod", title: "TOC(COD)\n(mg/L)", upName: "upChangeRe2", upSequnce: 2, align: "right" },
{ id: "efflWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe2", upSequnce: 3, align: "right" },
{ id: "efflWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe2", upSequnce: 2, align: "right" },
{ id: "efflWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe2", upSequnce: 3, align: "right" },
{ id: "infoRnDay", title: "강우량\n(mm/일)", align: "right" }
];
// 처리시설 수질현황 헤더(모달-수질TMS)
const upHeadListModalTms: TableUpperProps[] = [
{ id: "part", title: "구분" },
{ id: "toc", title: "TOC(mg/L)", upName: "upChangeRe", upSequnce: 1, align: "right" },
{ id: "ss", title: "SS(mg/L)", upName: "upChangeRe", upSequnce: 2, align: "right" },
{ id: "tn", title: "T-N(mg/L)", upName: "upChangeRe", upSequnce: 3, align: "right" },
{ id: "tp", title: "T-P(mg/L)", upName: "upChangeRe", upSequnce: 4, align: "right" },
];
// 처리시설 수질현황 데이터(모달-연간)
const facilityWaterQltyYearList: FacilityWaterQltyProps[] = [
];
// 처리시설 수질현황 데이터(모달-수질TMS)
const facilityWaterQltyTmsList: FacilityWaterQltyTmsProps[] = [
];
// 총인설비 수질현황 헤더 데이터
const upHeadListModalChongIn: TableUpperProps[] = [
{ id: "msrDt", title: "날짜" },
{ id: "tpInflWqltBod", title: "BOD(mg/L)", upName: "upChangeRe1", upSequnce: 1, align: "right" },
{ id: "tpInflWqltTp", title: "T-P(mg/L)", upName: "upChangeRe1", upSequnce: 2, align: "right" },
{ id: "efflWqltBod", title: "BOD(mg/L)", upName: "upChangeRe2", upSequnce: 1, align: "right" },
{ id: "efflWqltTp", title: "T-P(mg/L)", upName: "upChangeRe2", upSequnce: 2, align: "right" },
];
/**====================================
* Store - api (데이터 호출)
====================================*/
// 메인페이지
// 시설정보 수질 리스트 데이터 호출
const fetchFacilityWaterQltyList = async (
pageNo: number, pageSize: number, searchYear: string, partCd?: string | undefined
, nameCd?: string | undefined, fcltCpct?: string | undefined
, operationValue?: string | undefined, fcltyNm?: string | undefined
): Promise<{ data: FacilityWaterQltyProps[], count: number, status: number }> => {
try {
const tailStr = partCd ? '/' + partCd + '/' + nameCd + '/' + fcltCpct + '/' + operationValue + (fcltyNm && fcltyNm !== '' ? '/' + fcltyNm : '') : '';
const url = '/fclt/qlty/' + pageNo + '/' + pageSize + '/' + searchYear + tailStr;
const res = await getFetch('fo', url);
return { data: res.data, count: res.count, status: res.status };
} catch (error) {
console.error('시설정보 수질현황 데이터를 가져오는데 실패했습니다:', error);
return { data: [], count: 0, status: 300 };
}
}
// 시설정보 수질 리스트 데이터 호출(모달-수질TMS)
const fetchFacilityWaterQltyTmsList = async (facilityCd: string | undefined) => {
try {
const res = await getFetch('wr', '/il/getTms/' + facilityCd);
return { data: res.data, count: res.count };
} catch (error) {
console.error('시설정보 수질현황 TMS 데이터를 가져오는데 실패했습니다:', error);
return { data: [], count: 0 };
}
};
// 시설정보 수질 리스트 데이터 호출(모달-이력)
export const fetchFacilityWaterQltyListHist = async (searchYear: string | undefined, facilityCd: string | undefined): Promise<WaterQualityHistoryResponse | null> => {
try {//
const res = await getFetch('fo', '/fclt/qlty/hist/' + searchYear + '/' + facilityCd);
return res;
} catch (error) {
console.error('시설정보 수질현황 이력 데이터를 가져오는데 실패했습니다:', error);
return null;
}
};
// 시설정보 RDII 상세 [{BOD - inflAssctBfrWqltBod, 유입유량 inflAmnt, 강우량 infoRnDay, 측정일 msrDt}]
export const fetchFacilityRdiiDetailList = async (searchYear: string | undefined, swtrmtFcltCdList: string[]): Promise<FacilityRdiiDetailProps | null> => {
try {
const res = await postFetch('fo', '/rdii/detail/' + searchYear, swtrmtFcltCdList);
return res;
} catch (error) {
console.error('시설정보 RDII 상세 데이터를 가져오는데 실패했습니다:', error);
return null;
}
};
/**====================================
* Store - export
====================================*/
export type FacilityWaterQltyType = {
FacilityWaterQltyMain: {
facilityWaterQltyList: FacilityWaterQltyProps[];
excelList: ExcelType[];
facilityWaterQltyCount: number;
isInit: boolean;
mainLabelArray: string[];
upHeadList1: TableUpperProps[];
upHeadList2: TableUpperProps[];
upHeadList3: TableUpperProps[];
isLoading: boolean;
},
FacilityWaterQltyModal: {
// 처리시설 수질현황
upHeadListModalYear: TableUpperProps[];
upHeadListModalYearCod: TableUpperProps[];
facilityWaterQltyYearList: FacilityWaterQltyProps[];
upHeadListModalTms: TableUpperProps[];
facilityWaterQltyTmsList: FacilityWaterQltyTmsProps[];
// 수질tms
tmsList: FacilityWaterQltyTmsProps[];
msrmtDate: string;
// 총인시설 수질현황
upHeadListModalChongIn: TableUpperProps[];
}
}
export const facilityWaterQltyInitState: FacilityWaterQltyType = {
FacilityWaterQltyMain: {
facilityWaterQltyCount: 0,
facilityWaterQltyList: [],
excelList: [],
isLoading: true,
isInit: false,
mainLabelArray: mainLabelArray,
upHeadList1: upHeadList1,
upHeadList2: upHeadList2,
upHeadList3: upHeadList3,
},
FacilityWaterQltyModal: {
// 처리시설 수질현황
upHeadListModalYear: upHeadListModalYear,
upHeadListModalYearCod: upHeadListModalYearCod,
facilityWaterQltyYearList: facilityWaterQltyYearList,
upHeadListModalTms: upHeadListModalTms,
facilityWaterQltyTmsList: facilityWaterQltyTmsList,
// 수질tms
tmsList: [],
msrmtDate: '',
// 총인시설 수질현황
upHeadListModalChongIn: upHeadListModalChongIn,
}
}
export type FacilityWaterQltyActions = {
/**
* 시설정보 수질현황 리스트 데이터 호출(구분 선택 후 시설명 있을 경우)
* @param pageNo : 페이지 번호
* @param pageSize : 페이지 크기
* @param searchYear : 검색 년도
* @param part : 구분
* @param nameCd : 시설명
* @param fcltCpct : 시설용량
* @param operationValue : 운영상태코드
* @param fcltyNm : 시설명
*/
searchFacilityWaterQltyList: (pageNo: number, pageSize: number, searchYear: string, part?: string, nameCd?: string, fcltCpct?: string, operationValue?: string, fcltyNm?: string) => Promise<void>;
/**
* 시설정보 수질현황 이력 데이터 호출
* @param searchYear : 검색 년도
* @param facilityCd : 시설코드
*/
searchFacilityWaterQltyListHist: (searchYear: string, facilityCd: string) => Promise<void>;
}
/**
* @param item : 시설수질리스트 타입
* @returns : 없음
* @description : 시설수질리스트 타입의 데이터를 표현 방식으로 바꿔주는 함수
* - msrDt : YYYY-MM-DD 형식으로 변환
* - inflAssctBfrWqltBod : 소수점 1자리까지 표현
* - inflAssctBfrWqltTn : 소수점 1자리까지 표현
* - inflAssctBfrWqltTp : 소수점 1자리까지 표현
* - efflWqltBod : 소수점 2자리까지 표현
* - efflWqltTn : 소수점 2자리까지 표현
* - efflWqltTp : 소수점 2자리까지 표현
* @author : 박진우
* @date : 2025-04-24
*/
const dataFormSetting = (item: FacilityWaterQltyProps) => {
DataForm({ type: 'date', column: 'msrDt', item: item as unknown as Record<string, unknown> });
DataForm({ type: 'float1', column: 'infoRnDay', item: item as unknown as Record<string, unknown> });
}
export type FacilityWaterQltyStore = FacilityWaterQltyType & FacilityWaterQltyActions;
type SetFunc = (fn: (state: FacilityWaterQltyType) => FacilityWaterQltyType) => void;
export const facilityWaterQltyReducer = (set: SetFunc): FacilityWaterQltyActions => {
return {
// 메인페이지
/**
* 시설정보 수질현황 리스트 데이터 호출(구분 선택 후 시설명 있을 경우)
* @param pageNo : 페이지 번호
* @param pageSize : 페이지 크기
* @param searchYear : 검색 년도
* @param part : 구분
* @param nameCd : 시설명
* @param fcltCpct : 시설용량
* @param operationValue : 운영상태코드
* @param fcltyNm : 시설명
*/
searchFacilityWaterQltyList: async (pageNo: number, pageSize: number, searchYear: string, part?: string
, nameCd?: string, fcltCpct?: string, operationValue?: string, fcltyNm?: string) => {
set((state: FacilityWaterQltyType) => ({
...state,
FacilityWaterQltyMain: {
...state.FacilityWaterQltyMain,
isLoading: true,
},
}));
// const res = await fetchFacilityWaterQltyList(pageNo, pageSize, searchYear, part, nameCd, fcltCpct, operationValue, fcltyNm);
//---------
const waterQltyList: any[] = [];
let recordCount = 0;
if (pageSize < 5000) {
const res = await fetchFacilityWaterQltyList(pageNo, pageSize, searchYear, part, nameCd, fcltCpct, operationValue, fcltyNm);
waterQltyList.push(...res.data);
recordCount = res.count;
} else {
for (let idx = 0; idx < pageSize; idx += 100) {
const tmpPageNo = Math.floor(idx / 100) + 1;
const tmpPageSize = Math.min(100, pageSize - idx);
const result = await fetchFacilityWaterQltyList(tmpPageNo, tmpPageSize, searchYear, part, nameCd, fcltCpct, operationValue, fcltyNm);
if (result?.status === 200 && Array.isArray(result?.data)) {
waterQltyList.push(...result.data);
}
recordCount = result?.count || 0;
if (result?.count < tmpPageNo * tmpPageSize) {
break; // 더 이상 데이터가 없으면 중지
}
}
}
//-------
// const rtnData = res.data.map(item => {
const rtnData = waterQltyList.map(item => {
dataFormSetting(item)
if (item.inflAssctBfrWqltTn) {
item.inflAssctBfrWqltTn = Number(Math.round(Number(item.inflAssctBfrWqltTn) * 1000) / 1000).toFixed(3);
}
if (item.efflWqltTn) {
item.efflWqltTn = Number(Math.round(Number(item.efflWqltTn) * 1000) / 1000).toFixed(3);
}
if (item.inflAssctBfrWqltTp) {
item.inflAssctBfrWqltTp = Number(Math.round(Number(item.inflAssctBfrWqltTp) * 1000) / 1000).toFixed(3);
}
if (item.efflWqltTp) {
item.efflWqltTp = Number(Math.round(Number(item.efflWqltTp) * 1000) / 1000).toFixed(3);
}
if (item.inflAssctBfrWqltToc) {
item.inflAssctBfrWqltToc = Number(Math.round(Number(item.inflAssctBfrWqltToc) * 10) / 10).toFixed(1);
}
if (item.efflWqltToc) {
item.efflWqltToc = Number(Math.round(Number(item.efflWqltToc) * 10) / 10).toFixed(1);
}
if (item.inflAssctBfrWqltBod) {
item.inflAssctBfrWqltBod = Number(Math.round(Number(item.inflAssctBfrWqltBod) * 10) / 10).toFixed(1);
}
if (item.efflWqltBod) {
item.efflWqltBod = Number(Math.round(Number(item.efflWqltBod) * 10) / 10).toFixed(1);
}
if (item.inflAssctBfrWqltSs) {
item.inflAssctBfrWqltSs = Number(Math.round(Number(item.inflAssctBfrWqltSs) * 10) / 10).toFixed(1);
}
if (item.efflWqltSs) {
item.efflWqltSs = Number(Math.round(Number(item.efflWqltSs) * 10) / 10).toFixed(1);
}
if (item.inflAssctBfrWqltToc) {
item.inflAssctBfrWqltToc = Number(Math.round(Number(item.inflAssctBfrWqltToc) * 10) / 10).toFixed(1);
}
if (item.efflWqltToc) {
item.efflWqltToc = Number(Math.round(Number(item.efflWqltToc) * 10) / 10).toFixed(1);
}
return item;
});
const excelDownList: ExcelType[] = [];
if (pageSize > 5000) {
// res.data.forEach(item => {
waterQltyList.forEach(item => {
dataFormSetting(item)
item.fctCpc = parseFloat(item.fctCpc.toString().replace(/,/g, ''));
// item.sidoNm = item.lclgvrnmntNm.split(' ')[0]?.toString() || '';
// item.sggNm = item.lclgvrnmntNm.split(' ')[1]?.toString() || '';
item.inflAssctBfrWqltToc = Number(searchYear) < COD_YEAR ? "(" + item.inflAssctBfrWqltToc + ")" : item.inflAssctBfrWqltToc;
item.efflWqltToc = Number(searchYear) < COD_YEAR ? "(" + item.efflWqltToc + ")" : item.efflWqltToc;
excelDownList.push({
시설코드: item.bscFctCd,
권역: item.rvbsn,
단위유역: item.lgbsn,
중권역: item.mdmbsn,
환경청: item.rgnNm,
시도: item.sido,
시군구: item.gugun,
시설이름: item.bscFctNm,
주소: item.addr,
"시설용량(m³/일)": CommaToNumber(item.fctCpc),
"유입BOD(mg/L)": CommaToNumber(item.inflAssctBfrWqltBod),
"유입TOC(mg/L)": CommaToNumber(item.inflAssctBfrWqltToc),
"유입SS(mg/L)": CommaToNumber(item.inflAssctBfrWqltSs),
"유입TN(mg/L)": CommaToNumber(item.inflAssctBfrWqltTn),
"유입TP(mg/L)": CommaToNumber(item.inflAssctBfrWqltTp),
"유출BOD(mg/L)": CommaToNumber(item.efflWqltBod),
"유출TOC(mg/L)": CommaToNumber(item.efflWqltToc),
"유출SS(mg/L)": CommaToNumber(item.efflWqltSs),
"유출TN(mg/L)": CommaToNumber(item.efflWqltTn),
"유출TP(mg/L)": CommaToNumber(item.efflWqltTp),
});
});
} else {
// res.data.forEach((item: FacilityWaterQltyProps) => {
waterQltyList.forEach((item: FacilityWaterQltyProps) => {
dataFormSetting(item)
item.fctCpc = parseFloat(item.fctCpc.toString().replace(/,/g, ''));
// item.sidoNm = item.;
// item.sggNm = item.lclgvrnmntNm.split(' ')[1]?.toString() || '';
item.inflAssctBfrWqltToc = Number(searchYear) < COD_YEAR ? "(" + item.inflAssctBfrWqltToc + ")" : item.inflAssctBfrWqltToc;
item.efflWqltToc = Number(searchYear) < COD_YEAR ? "(" + item.efflWqltToc + ")" : item.efflWqltToc;
});
}
set((state: FacilityWaterQltyType) => ({
...state,
FacilityWaterQltyMain: pageSize < 5000 ? {
...state.FacilityWaterQltyMain,
facilityWaterQltyList: rtnData,
facilityWaterQltyCount: recordCount,
isLoading: false,
} : {
...state.FacilityWaterQltyMain,
excelList: excelDownList,
isLoading: false,
},
}))
},
searchFacilityWaterQltyListHist: async (searchYear: string, facilityCd: string) => {
const res = await fetchFacilityWaterQltyListHist(searchYear, facilityCd);
const res1 = await fetchFacilityWaterQltyTmsList(facilityCd);
let rtnMsrmtDate = '';
const rtnTmsList: FacilityWaterQltyTmsProps[] = [];
if (res1.data) {
rtnTmsList.push({
part: '평균',
toc: res1.data.tocAvgVl,
ss: res1.data.ssAvgVl,
tn: res1.data.tnAvgVl,
tp: res1.data.tpAvgVl,
});
rtnTmsList.push({
part: '최대',
toc: res1.data.tocMaxVl,
ss: res1.data.ssMaxVl,
tn: res1.data.tnMaxVl,
tp: res1.data.tpMaxVl,
});
rtnTmsList.push({
part: '최소',
toc: res1.data.tocMinVl,
ss: res1.data.ssMinVl,
tn: res1.data.tnMinVl,
tp: res1.data.tpMinVl,
});
rtnMsrmtDate = res1.data.msrmtDate;
} else {
rtnTmsList.push({ part: '평균', toc: 0, ss: 0, tn: 0, tp: 0, });
rtnTmsList.push({ part: '최대', toc: 0, ss: 0, tn: 0, tp: 0, });
rtnTmsList.push({ part: '최소', toc: 0, ss: 0, tn: 0, tp: 0, });
rtnMsrmtDate = '';
}
if (Array.isArray(res) || !res || !('data' in res) || !res.data || !res.data.wqltObjs || res.data.wqltObjs.length === 0) {
set((state: FacilityWaterQltyType) => ({
...state,
FacilityWaterQltyModal: {
...state.FacilityWaterQltyModal,
facilityWaterQltyYearList: [],
tmsList: rtnTmsList,
msrmtDate: rtnMsrmtDate
}
}))
return;
}
// facilityPrecipitation의 rainEffectDay 계산 로직을 적용
const data = CalcRainEffect(res.data.wqltObjs);
/**
* [(강우시 일별유입유량*강우시 일별유입BOD)-(청천시 연평균유입유량*청천시 연평균유입BOD)]​
/강우시 일별유입BOD)
*/
let sunnyInflAmnt = 0;
let sunnyBod = 0;
let sunnyDay = 0;
data.forEach(item => {
if (item.rainEffectDay == 1) {
//rainDay += 1;
//rainInflAmnt += Number(item.inflAmnt);
} else {
sunnyDay += 1;
sunnyInflAmnt += Number(item.inflAmnt);
sunnyBod += Number(item.inflAssctBfrWqltBod);
}
});
//const yearRainAmnt = rainInflAmnt===0?0:rainInflAmnt / rainDay;
const yearSunnyAmnt = sunnyInflAmnt === 0 ? 0 : sunnyInflAmnt / sunnyDay;
const yearSunnyBod = sunnyBod === 0 ? 0 : sunnyBod / sunnyDay;
//
const rtnData = data.map((item: FacilityWaterQltyProps) => {
dataFormSetting(item)
if (item.inflAssctBfrWqltTn) {
item.inflAssctBfrWqltTn = Number(Math.round(Number(item.inflAssctBfrWqltTn) * 1000) / 1000).toFixed(3);
}
if (item.efflWqltTn) {
item.efflWqltTn = Number(Math.round(Number(item.efflWqltTn) * 1000) / 1000).toFixed(3);
}
if (item.inflAssctBfrWqltTp) {
item.inflAssctBfrWqltTp = Number(Math.round(Number(item.inflAssctBfrWqltTp) * 1000) / 1000).toFixed(3);
}
if (item.efflWqltTp) {
item.efflWqltTp = Number(Math.round(Number(item.efflWqltTp) * 1000) / 1000).toFixed(3);
}
if (item.inflAssctBfrWqltToc) {
item.inflAssctBfrWqltToc = Number(Math.round(Number(item.inflAssctBfrWqltToc) * 10) / 10).toFixed(1);
}
if (item.efflWqltToc) {
item.efflWqltToc = Number(Math.round(Number(item.efflWqltToc) * 10) / 10).toFixed(1);
}
if (item.inflAssctBfrWqltCod) {
item.inflAssctBfrWqltCod = "(" + Number(Math.round(Number(item.inflAssctBfrWqltCod) * 10) / 10).toFixed(1) + ")";
}
if (item.efflWqltCod) {
item.efflWqltCod = "(" + Number(Math.round(Number(item.efflWqltCod) * 10) / 10).toFixed(1) + ")";
}
if (item.inflAssctBfrWqltBod) {
item.inflAssctBfrWqltBod = Number(Math.round(Number(item.inflAssctBfrWqltBod) * 10) / 10).toFixed(1);
}
if (item.efflWqltBod) {
item.efflWqltBod = Number(Math.round(Number(item.efflWqltBod) * 10) / 10).toFixed(1);
}
if (item.inflAssctBfrWqltSs) {
item.inflAssctBfrWqltSs = Number(Math.round(Number(item.inflAssctBfrWqltSs) * 10) / 10).toFixed(1);
}
if (item.efflWqltSs) {
item.efflWqltSs = Number(Math.round(Number(item.efflWqltSs) * 10) / 10).toFixed(1);
}
if (item.inflAssctBfrWqltToc) {
item.inflAssctBfrWqltToc = Number(Math.round(Number(item.inflAssctBfrWqltToc) * 10) / 10).toFixed(1);
}
if (item.efflWqltToc) {
item.efflWqltToc = Number(Math.round(Number(item.efflWqltToc) * 10) / 10).toFixed(1);
}
if (item.tpInflWqltBod) { // 총인 유입수질 BOD(mg/L)
item.tpInflWqltBod = item.tpInflWqltBod ? Number(Math.round(Number(item.tpInflWqltBod) * 10) / 10).toFixed(1) : Number(item.tpInflWqltBod) === 0 ? '0.0' : '';
} else {
item.tpInflWqltBod = '';
}
if (item.tpInflWqltTp) { // 총인 유입수질 TP(mg/L)
item.tpInflWqltTp = item.tpInflWqltTp ? Number(Math.round(Number(item.tpInflWqltTp) * 1000) / 1000).toFixed(3) : Number(item.tpInflWqltTp) === 0 ? '0.000' : '';
} else {
item.tpInflWqltTp = '';
}
const dayBod = Number(item.inflAssctBfrWqltBod);
const noProcessInflAmnt = roundNumber(((Number(item.inflAmnt) * dayBod) - (yearSunnyAmnt * yearSunnyBod)) / dayBod, 0)
item.noProcessInflAmnt = noProcessInflAmnt && Number(noProcessInflAmnt.replaceAll(',', '')) > 0 ? noProcessInflAmnt : '';
return item;
})
set((state: FacilityWaterQltyType) => ({
...state,
FacilityWaterQltyModal: {
...state.FacilityWaterQltyModal,
facilityWaterQltyYearList: rtnData,
tmsList: rtnTmsList,
msrmtDate: rtnMsrmtDate
}
}))
},
}
}