fo:오수발생량 추정 수정
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { getFetch } from "@/app/components/api";
|
||||
import CalcRainEffect from "@/app/components/common/CalcRainEffect";
|
||||
import { getFetch, postFetch } from "@/app/components/api";
|
||||
// import CalcRainEffect from "@/app/components/common/CalcRainEffect";
|
||||
import { roundNumber } from "@/app/components/common/DataForm";
|
||||
import { OSU_PERCENT } from "../common";
|
||||
import type { TableUpperProps } from "../dashboard";
|
||||
@@ -138,11 +138,22 @@ const tempSewageOccurList:modalTableType[] = []
|
||||
return { data: res.data, count: res.count }
|
||||
}*/
|
||||
|
||||
const fetchSweageOccurListFlow = async(fcltyCd : string, searchYear : string) => {
|
||||
const url = '/fclt/flow/' + fcltyCd + '/' + searchYear;
|
||||
const res = await getFetch('fo', url);
|
||||
return res;
|
||||
}
|
||||
// const fetchSweageOccurListFlow = async(fcltyCd : string, searchYear : string) => {
|
||||
// const url = '/fclt/flow/' + fcltyCd + '/' + searchYear;
|
||||
// const res = await getFetch('fo', url);
|
||||
// return res;
|
||||
// }
|
||||
|
||||
// 시설정보 RDII 상세 [{BOD - inflAssctBfrWqltBod, 유입유량 inflAmnt, 강우량 infoRnDay, 측정일 msrDt}]
|
||||
export const fetchSweageOccurListFlow = async (searchYear: string|undefined, fcltCdList: string[]): Promise<SewageOccurProps | null> => {
|
||||
try {
|
||||
const res = await postFetch('fo', '/fclt/flow/'+searchYear, fcltCdList);
|
||||
return res;
|
||||
} catch (error) {
|
||||
console.error('시설정보 오수발생량 상세 데이터를 가져오는데 실패했습니다:', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/**====================================
|
||||
* Store - expaort
|
||||
@@ -201,15 +212,15 @@ export const sewageOccurInitState: SewageOccurType = {
|
||||
}
|
||||
|
||||
// 병렬 처리 제한용 헬퍼
|
||||
async function processInBatches(items, batchSize, callback) {
|
||||
const results:any = [];
|
||||
for (let i = 0; i < items.length; i += batchSize) {
|
||||
const batch = items.slice(i, i + batchSize);
|
||||
const batchResults = await Promise.all(batch.map(callback));
|
||||
results.push(...batchResults);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
// async function processInBatches(items, batchSize, callback) {
|
||||
// const results:any = [];
|
||||
// for (let i = 0; i < items.length; i += batchSize) {
|
||||
// const batch = items.slice(i, i + batchSize);
|
||||
// const batchResults = await Promise.all(batch.map(callback));
|
||||
// results.push(...batchResults);
|
||||
// }
|
||||
// return results;
|
||||
// }
|
||||
|
||||
export type SewageOccurStore = SewageOccurType & SewageOccurActions;
|
||||
|
||||
@@ -253,53 +264,75 @@ export const sewageOccurReducer:(set:any)=>SewageOccurActions=(set: any) => {
|
||||
}));
|
||||
}
|
||||
|
||||
const fcltylist = facilityInitData.data;
|
||||
|
||||
const calData = await processInBatches(fcltylist, 20, async (item: SewageOccurProps, index: number) => {
|
||||
const bscFctCd = item.bscFctCd;
|
||||
const res = await fetchSweageOccurListFlow(bscFctCd, searchYear).catch(() => {
|
||||
console.log('Error fetching flow data for facility code:', bscFctCd);
|
||||
return { data: [], count: 0 };
|
||||
const fcltylist = facilityInitData.data; // 시설목록
|
||||
const fcltCdList : string[] = []; // 시설코드목록
|
||||
const sewageOccurPropsList : SewageOccurProps[] = []; // 오수발생량시설목록
|
||||
fcltylist.forEach(item => {
|
||||
fcltCdList.push(item.bscFctCd);
|
||||
sewageOccurPropsList.push({
|
||||
bscFctCd : item.bscFctCd,
|
||||
sidoNm : item.sido,
|
||||
sggNm : item.gugun,
|
||||
lclgvrnmntNm : '',
|
||||
bscFctNm : item.bscFctNm,
|
||||
daddr : item.daddr,
|
||||
fctCpc : parseFloat(item.fctCpc.toString().replace(/,/g, '')),
|
||||
waterUsage : 0,
|
||||
swageChangePercent : 0,
|
||||
estimationSewage : 0,
|
||||
sewageInputYear : 0,
|
||||
sewageInputChungchun : 0,
|
||||
rgnNm : item.rgnNm,
|
||||
rvbsn : item.rvbsn,
|
||||
lgbsn : item.lgbsn,
|
||||
mdmbsn : item.mdmbsn,
|
||||
msrDt : '',
|
||||
});
|
||||
});
|
||||
|
||||
const soccurDetailRes : any = await fetchSweageOccurListFlow(searchYear, fcltCdList);
|
||||
console.log(soccurDetailRes);
|
||||
|
||||
for (const item of sewageOccurPropsList) {
|
||||
|
||||
const detailList = soccurDetailRes?.data[item.bscFctCd]
|
||||
|
||||
item.sidoNm = item.sidoNm || '';
|
||||
item.sggNm = item.sggNm || '';
|
||||
item.fctCpc = parseFloat(item.fctCpc.toString().replace(/,/g, ''));
|
||||
item.swageChangePercent = 90;
|
||||
let sumChungcunDay = 0; // 청천일수
|
||||
let chungcunSumFlow = 0;// 청천시 하수유입량
|
||||
let totWaterUsage = 0; // 연간 하수유입량
|
||||
detailList?.forEach(item2 => {
|
||||
|
||||
let sumChungcunDay = 0;
|
||||
let chungcunSumFlow = 0;
|
||||
let totWaterUsage = 0;
|
||||
|
||||
// 강우영향일 계산 (강우량이 3 초과이면 무조건 강우영향일)
|
||||
const rainEffectData = CalcRainEffect(res.data);
|
||||
|
||||
rainEffectData.forEach((item: FlowDataItem) => {
|
||||
|
||||
if(Number(item.rainEffectDay) === 0){
|
||||
chungcunSumFlow += Number(item.inflAmnt);
|
||||
let rainEffectDay = 0;
|
||||
if (item2.infoRnDay == null) item2.infoRnDay = 0;
|
||||
if(item2.infoRnDay >= 3) {
|
||||
rainEffectDay = 2;
|
||||
}else{
|
||||
rainEffectDay--;
|
||||
}
|
||||
if(rainEffectDay<0){ //청천시
|
||||
chungcunSumFlow += Number(item2.inflAmnt);
|
||||
sumChungcunDay += 1;
|
||||
}
|
||||
totWaterUsage += Number(item.inflAmnt);
|
||||
totWaterUsage += Number(item2.inflAmnt);
|
||||
});
|
||||
|
||||
const avg = res.count == 0 ? 0 : totWaterUsage /res.count;
|
||||
item.waterUsage = parseFloat((avg * 0.65).toFixed(2));
|
||||
item.sewageInputYear = parseFloat(avg.toFixed(2));
|
||||
item.sewageInputChungchun = parseFloat((chungcunSumFlow===0?0:(chungcunSumFlow / sumChungcunDay)).toFixed(2));
|
||||
item.estimationSewage = parseFloat((item.waterUsage * (item.swageChangePercent/100)).toFixed(2));
|
||||
const count = detailList ? detailList.length : 0;
|
||||
const avg = count == 0 ? 0 : totWaterUsage / count; // 일평균 유입량
|
||||
item.waterUsage = parseFloat((avg * 0.65).toFixed(2)); // 물사용량 = 일평균 유입량 * 65%
|
||||
item.sewageInputYear = parseFloat(avg.toFixed(2)); // 연간 하수유입량(m³/일)
|
||||
item.sewageInputChungchun = parseFloat((chungcunSumFlow===0?0:(chungcunSumFlow / sumChungcunDay)).toFixed(2)); // 청천시 하수유입량
|
||||
item.estimationSewage = parseFloat((item.waterUsage * (item.swageChangePercent/100)).toFixed(2)); // 오수발생량 추정(m³/일)
|
||||
|
||||
// 반올림 처리
|
||||
["fctCpc", "waterUsage", "swageChangePercent", "estimationSewage", "sewageInputYear", "sewageInputChungchun"].forEach(
|
||||
(key) => (item[key] = roundNumber(item[key], 0))
|
||||
);
|
||||
|
||||
return {...item, index:index};
|
||||
});
|
||||
}
|
||||
|
||||
if(pageSize >= 5000){
|
||||
const excelDownList: ExcelType[] = [];
|
||||
calData.forEach((item: SewageOccurProps) => {
|
||||
sewageOccurPropsList.forEach((item: SewageOccurProps) => {
|
||||
excelDownList.push({
|
||||
시설코드: item.bscFctCd,
|
||||
권역: item.rvbsn,
|
||||
@@ -331,7 +364,7 @@ export const sewageOccurReducer:(set:any)=>SewageOccurActions=(set: any) => {
|
||||
...state,
|
||||
SewageOccur: {
|
||||
...state.SewageOccur,
|
||||
sewageOccurList : calData,
|
||||
sewageOccurList : sewageOccurPropsList,
|
||||
sewageOccurCount : facilityInitData.count,
|
||||
isLoading: false,
|
||||
excelList: [],
|
||||
|
||||
Reference in New Issue
Block a user