import { getFetch } from "@/app/components/api"; import DataForm from "@/app/components/common/DataForm"; import type { TableUpperProps } from "../dashboard"; export type { TableUpperProps }; /**==================================== * Store - 타입 * * tn, tp는 소수점 3자리까지, 나머지는 소수점 1자리까지 ====================================*/ /** * (1) 메인페이지 */ // 시설수질리스트 타입 export interface FacilityWaterQltyProps { bscFctCd: string, bscFctNm: string, msrDt: string sidoNm: string, sggNm: string, addr: string, fctCpc: number, inflAssctBfrWqltBod: string | '', inflAssctAftWqltBod: string | '', inflAssctBfrWqltToc: string | '', inflAssctAftWqltToc: string | '', inflAssctBfrWqltSs: string | '', inflAssctAftWqltSs: string | '', inflAssctBfrWqltTn: string | '', inflAssctAftWqltTn: string | '', inflAssctBfrWqltTp: string | '', inflAssctAftWqltTp: string | '', efflWqltBod: string | '', efflWqltToc: string | '', efflWqltSs: string | '', efflWqltTn: string | '', efflWqltTp: string | '', rgnNm:string|'', rvbsn:string|'', lgbsn:string|'', mdmbsn:string|'', inflAmnt: number | '', lclgvrnmntNm: string, infoRnDay: number | '', rainEffectDay: number | '', tpInflWqltTmprtr: number | '', tpInflWqltPh: string | '', tpInflWqltBod: string | '', tpInflWqltCod: string | '', tpInflWqltSs: string | '', tpInflWqltTn: string | '', tpInflWqltTp: string | '', tpInflWqltEclgyTox: string | '', tpInflWqltClfgrpcnt: string | '', } export interface ExcelType { 시설코드: string, 권역:string|'', 단위유역:string|'', 중권역:string|'', 환경청:string|'', 시도: string, 시군구: string, 시설이름: string, 주소: string, 용량: number, 유입BOD: string | '', 유입TOC: string | '', 유입SS: string | '', 유입TN: string | '', 유입TP: string | '', 유출BOD: string | '', 유출TOC: string | '', 유출SS: string | '', 유출TN: string | '', 유출TP: string | '', } /** * (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)": 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; /* "강우량(mm/일)": string; */ } /**==================================== * Store - data ====================================*/ /** * (1) 메인페이지 */ // 메인 라벨 배열 const mainLabelArray: string[] = ['구분', '시도', '시군구', '용량별', '시설명', '조회기간', '시설상태', '권역', '단위유역', '중권역', '환경청별']; // 시설수질리스트 헤더(행정별) const upHeadList1: TableUpperProps[] = [ { id: "bscFctCd", title: "시설코드", rowSpan: 2, row:0 }, { id: "C", title: "행정명", colSpan: 2, row: 0 }, { id: "sidoNm", title: "시도", row: 1 }, { id: "sggNm", title: "시군구", row: 1 }, { id: "bscFctNm", title: "시설명", rowSpan: 2, row: 0 }, { id: "addr", title: "주소", rowSpan: 2, row: 0 }, { id: "fctCpc", title: "시설용량(m³/일)", align: "right", rowSpan: 2, row: 0 }, { id: "A", title: "유입", colSpan: 5, row: 0 }, { id: "B", title: "방류", colSpan: 5, row: 0 }, { id: "inflAssctBfrWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe3", upSequnce: 1, align: "right", row: 1 }, { id: "inflAssctBfrWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row: 1 }, { id: "inflAssctBfrWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row: 1 }, { id: "inflAssctBfrWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe3", upSequnce: 4, align: "right", row: 1 }, { id: "inflAssctBfrWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row: 1 }, { id: "efflWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe4", upSequnce: 1, align: "right", row: 1 }, { id: "efflWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row: 1 }, { id: "efflWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row: 1 }, { id: "efflWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe4", upSequnce: 4, align: "right", row: 1 }, { id: "efflWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row: 1 }, ]; // 시설수질리스트 헤더(권역별) const upHeadList2: TableUpperProps[] = [ { id: "bscFctCd", title: "시설코드", row:0, rowSpan:2 }, { id: "C", title: "유역", colSpan: 3, row: 0 }, { id: "rvbsn", title: "권역", upName: "upChangeRe1", upSequnce: 1, row:1 }, { id: "lgbsn", title: "단위유역", upName: "upChangeRe1", upSequnce: 2, row:1 }, { id: "mdmbsn", title: "중권역", upName: "upChangeRe1", upSequnce: 3, row:1 }, { id: "bscFctNm", title: "시설명", row:0, rowSpan:2 }, { id: "addr", title: "주소", row:0, rowSpan:2 }, { id: "fctCpc", title: "시설용량(m³/L)", align: "right", row:0, rowSpan:2 }, { id: "A", title: "유입", colSpan: 5, row: 0 }, { id: "B", title: "방류", colSpan: 5, row: 0 }, { id: "inflAssctBfrWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe3", upSequnce: 1, align: "right", row:1 }, { id: "inflAssctBfrWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row:1 }, { id: "inflAssctBfrWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row:1 }, { id: "inflAssctBfrWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row:1 }, { id: "inflAssctBfrWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row:1 }, { id: "efflWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe4", upSequnce: 1, align: "right", row:1 }, { id: "efflWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row:1 }, { id: "efflWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row:1 }, { id: "efflWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row:1 }, { id: "efflWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row:1 }, ]; // 시설수질리스트 헤더(환경청별) const upHeadList3: TableUpperProps[] = [ { id: "bscFctCd", title: "시설코드", row:0, rowSpan:2 }, { id: "C", title: "유역", colSpan: 3, row: 0 }, { id: "rvbsn", title: "권역", row:1 }, { id: "lgbsn", title: "단위유역", row:1 }, { id: "mdmbsn", title: "중권역", row:1 }, { id: "rgnNm", title: "환경청", row:0, rowSpan:2 }, { id: "D", title: "행정명", colSpan: 2, row: 0 }, { id: "sidoNm", title: "시도", upName: "upChangeRe2", row:1 }, { id: "sggNm", title: "시군구", upName: "upChangeRe2", row:1 }, { id: "bscFctNm", title: "시설명", row:0, rowSpan:2 }, { id: "addr", title: "주소", row:0, rowSpan:2 }, { id: "fctCpc", title: "시설용량(m³/L)", align: "right", row:0, rowSpan:2 }, { id: "A", title: "유입", colSpan: 5, row: 0 }, { id: "B", title: "방류", colSpan: 5, row: 0 }, { id: "inflAssctBfrWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe3", upSequnce: 1, align: "right", row:1 }, { id: "inflAssctBfrWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row:1 }, { id: "inflAssctBfrWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row:1 }, { id: "inflAssctBfrWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe3", upSequnce: 2, align: "right", row:1 }, { id: "inflAssctBfrWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe3", upSequnce: 3, align: "right", row:1 }, { id: "efflWqltBod", title: "BOD\n(mg/L)", upName: "upChangeRe4", upSequnce: 1, align: "right", row:1 }, { id: "efflWqltToc", title: "TOC\n(COD)\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row:1 }, { id: "efflWqltSs", title: "SS\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row:1 }, { id: "efflWqltTn", title: "T-N\n(mg/L)", upName: "upChangeRe4", upSequnce: 2, align: "right", row:1 }, { id: "efflWqltTp", title: "T-P\n(mg/L)", upName: "upChangeRe4", upSequnce: 3, align: "right", row:1 }, ]; /** * (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: "강우량(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 }> => { 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 } } catch (error) { console.error('시설정보 수질현황 데이터를 가져오는데 실패했습니다:', error); return { data: [], count: 0 }; } } // 시설정보 수질 리스트 데이터 호출(모달-수질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 }; } }; // 시설정보 수질 리스트 데이터 호출(모달-이력) const fetchFacilityWaterQltyListHist = async (searchYear: string|undefined, facilityCd: string|undefined): Promise => { try {// const res = await getFetch('fo', '/fclt/qlty/hist/' + searchYear + '/' + facilityCd); return res; } catch (error) { console.error('시설정보 수질현황 이력 데이터를 가져오는데 실패했습니다:', 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[]; 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, 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; /** * 시설정보 수질현황 이력 데이터 호출 * @param searchYear : 검색 년도 * @param facilityCd : 시설코드 */ searchFacilityWaterQltyListHist: (searchYear: string, facilityCd: string) => Promise; } /** * @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 }); } export type FacilityWaterQltyStore = FacilityWaterQltyType & FacilityWaterQltyActions; export const facilityWaterQltyReducer = (set: (fn: (state: FacilityWaterQltyType) => FacilityWaterQltyType) => void): 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 rtnData = res.data.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 => { dataFormSetting(item) item.fctCpc = parseFloat(item.fctCpc.toString().replace(/,/g, '')); item.sidoNm = item.lclgvrnmntNm.split(' ')[0]?.toString() || ''; item.sggNm = item.lclgvrnmntNm.split(' ')[1]?.toString() || ''; excelDownList.push({ 시설코드: item.bscFctCd, 권역: item.rvbsn, 단위유역: item.lgbsn, 중권역: item.mdmbsn, 환경청: item.rgnNm, 시도: item.sidoNm, 시군구: item.sggNm, 시설이름: item.bscFctNm, 주소: item.addr, 용량: item.fctCpc, 유입BOD: item.inflAssctBfrWqltBod, 유입TOC: item.inflAssctBfrWqltToc, 유입SS: item.inflAssctBfrWqltSs, 유입TN: item.inflAssctBfrWqltTn, 유입TP: item.inflAssctBfrWqltTp, 유출BOD: item.efflWqltBod, 유출TOC: item.efflWqltToc, 유출SS: item.efflWqltSs, 유출TN: item.efflWqltTn, 유출TP: item.efflWqltTp, }); }); }else{ res.data.forEach((item: FacilityWaterQltyProps) => { dataFormSetting(item) item.fctCpc = parseFloat(item.fctCpc.toString().replace(/,/g, '')); item.sidoNm = item.lclgvrnmntNm.split(' ')[0]?.toString() || ''; item.sggNm = item.lclgvrnmntNm.split(' ')[1]?.toString() || ''; }); } set((state: FacilityWaterQltyType) => ({ ...state, FacilityWaterQltyMain: pageSize<5000?{ ...state.FacilityWaterQltyMain, facilityWaterQltyList: rtnData, facilityWaterQltyCount: res.count, 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 = res.data.wqltObjs; // 강우영향일 계산 (강우량이 3 초과이면 무조건 강우영향일) for(let idx = 0; idx < data.length; idx++) { const item = data[idx]; if(item){ if(item.infoRnDay && Number(item.infoRnDay) > 3) { item.rainEffectDay = 1; } else { item.rainEffectDay = 0; } } } // 이틀 전, 하루 전이 강우영향일(3 이상)인 경우 해당 날도 강우영향일로 설정 for(let idx = 0; idx < data.length; idx++) { if(data[idx]) { // 하루 전이 강우영향일(3 이상)인 경우 if(idx > 0 && data[idx-1]?.infoRnDay && Number(data[idx-1]?.infoRnDay) >= 3) { data[idx]!.rainEffectDay = 1; } // 이틀 전이 강우영향일(3 이상)인 경우 if(idx > 1 && data[idx-2]?.infoRnDay && Number(data[idx-2]?.infoRnDay) >= 3) { data[idx]!.rainEffectDay = 1; } } } for(let idx = 0; idx < data.length; idx++) { if(data[idx] && data[idx]?.rainEffectDay === 1) { if(idx > 1){ if(data[idx-1]?.infoRnDay && Number(data[idx-1]?.infoRnDay) > 3) { data[idx]!.infoRnDay = data[idx-1]!.infoRnDay; } } if(idx > 2){ if(data[idx-2]?.infoRnDay && Number(data[idx-2]?.infoRnDay) > 3) { data[idx]!.infoRnDay = data[idx-2]!.infoRnDay; } } } } 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.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){ 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){ item.tpInflWqltTp = item.tpInflWqltTp?Number(Math.round(Number(item.tpInflWqltTp) * 1000)/1000).toFixed(3): Number(item.tpInflWqltTp)===0?'0.000':''; }else{ item.tpInflWqltTp = ''; } return item; }) set((state: FacilityWaterQltyType) => ({ ...state, FacilityWaterQltyModal: { ...state.FacilityWaterQltyModal, facilityWaterQltyYearList: rtnData, tmsList : rtnTmsList, msrmtDate : rtnMsrmtDate } })) }, } }