Files
frontend/apps/fo/app/store/underWaterInput/index.tsx
T
2025-07-15 20:54:38 +09:00

397 lines
15 KiB
TypeScript

import DataForm from "@/app/components/common/DataForm";
import type { TableUpperProps } from "../dashboard";
import { getFetch } from "@/app/components/api";
export type { TableUpperProps };
/**====================================
* Store - 타입
====================================*/
/**
* (1) 메인페이지
*/
// 시설별 강수현황
export type UnderWaterProps = {
bscFctCd : string,
lclgvrnmntNm : string,
sidoNm : string,
sggNm : string,
bscFctNm : string,
daddr : string,
fctCpc : number,
underWaterInputYear : number,
underWaterInputSummer : number,
underWaterInputWinter : number,
infoRnDay : number,
rgnNm : string,
rvbsn : string,
lgbsn : string,
mdmbsn : string,
}
export interface UnderWaterInterface {
bscFctCd : string,
sidoNm : string,
sggNm : string,
bscFctNm : string,
daddr : string,
fctCpc : number,
underWaterInputYear : number,
underWaterInputSummer : number,
underWaterInputWinter : number,
infoRnDay : number,
rgnNm : string,
rvbsn : string,
lgbsn : string,
mdmbsn : string,
}
// 모달
export interface UnderWaterInputModalProps {
msrDt : string,
realSewageInput : number | '',
sewageOccur : number | '',
underWaterInput : number | '',
}
/**====================================
* Store - data
====================================*/
/**
* (1) 메인페이지
*/
// 검색단
const LabelArray:string[] = ['구분', '시도', '시군구','용량별', '시설명', '조회기간', '시설상태', '권역', '단위유역', '중권역', '환경청별'];
export interface ExcelType {
시설코드: string,
권역:string|'',
단위유역:string|'',
중권역:string|'',
환경청:string|'',
시도: string,
시군구: string,
시설명: string,
주소: string,
시설용량: number,
연간지하수유입량: number | '',
하절기지하수유입량: number | '',
동절기지하수유입량: number | '',
}
// 리스트 헤더
const upHeadList1:TableUpperProps[] = [
{ id: "bscFctCd", title: "시설코드", row:0, rowSpan:2 },
{ id: "A", title: "행정구역", row:0, colSpan:2 },
{ id: "sidoNm", title: "시도", upName:"upChangeRe", upSequnce:1, row:1 },
{ id: "sggNm", title: "시군구", upName:"upChangeRe",upSequnce:2, row:1 },
{ id: "bscFctNm", title: "시설명", row:0, rowSpan:2 },
{ id: "daddr", title: "주소", row:0, rowSpan:2 },
{ id: "fctCpc", title: "시설용량(m³/일)", align:"right", row:0, rowSpan:2 },
{ id: "C", title: "지하수 유입량 추정", align:"right", row:0, colSpan:3 },
{ id: "underWaterInputYear", title: "연간\n(m³/일)", align:"right", row:1 },
{ id: "underWaterInputSummer", title: "하절기\n(m³/일)", align:"right", row:1 },
{ id: "underWaterInputWinter", title: "동절기\n(m³/일)", align:"right", row:1 },
];
const upHeadList2:TableUpperProps[] = [
{ id: "bscFctCd", title: "시설코드", row:0, rowSpan:2 },
{ id: "A", title: "유역", row:0, colSpan:3 },
{ id: "rvbsn", title: "권역", upName:"upChangeRe", upSequnce:1, row:1 },
{ id: "lgbsn", title: "단위유역", upName:"upChangeRe", upSequnce:2, row:1 },
{ id: "mdmbsn", title: "중권역", upName:"upChangeRe", upSequnce:3, row:1 },
{ id: "bscFctNm", title: "시설명", row:0, rowSpan:2 },
{ id: "daddr", title: "주소", row:0, rowSpan:2 },
{ id: "fctCpc", title: "시설용량(m³/일)", align:"right", row:0, rowSpan:2 },
{ id: "C", title: "지하수 유입량 추정", align:"right", row:0, colSpan:3 },
{ id: "underWaterInputYear", title: "연간\n(m³/일)", align:"right", row:1 },
{ id: "underWaterInputSummer", title: "하절기\n(m³/일)", align:"right", row:1 },
{ id: "underWaterInputWinter", title: "동절기\n(m³/일)", align:"right", row:1 },
];
const upHeadList3:TableUpperProps[] = [
{ id: "bscFctCd", title: "시설코드", row:0, rowSpan:2 },
{ id: "A", title: "유역", row:0, colSpan:3 },
{ 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: "rgnNm", title: "환경청", row:0, rowSpan:2 },
{ id: "B", title: "행정구역", row:0, colSpan:2 },
{ id: "sidoNm", title: "시도", upName:"upChangeRe2", upSequnce:1, row:1 },
{ id: "sggNm", title: "시군구", upName:"upChangeRe2",upSequnce:2, row:1 },
{ id: "bscFctNm", title: "시설명", row:0, rowSpan:2 },
{ id: "daddr", title: "주소", row:0, rowSpan:2 },
{ id: "fctCpc", title: "시설용량(m³/일)", align:"right", row:0, rowSpan:2 },
{ id: "C", title: "지하수 유입량 추정", align:"right", row:0, colSpan:3 },
{ id: "underWaterInputYear", title: "연간\n(m³/일)", align:"right", row:1 },
{ id: "underWaterInputSummer", title: "하절기\n(m³/일)", align:"right", row:1 },
{ id: "underWaterInputWinter", title: "동절기\n(m³/일)", align:"right", row:1 },
];
// 모달
const upHeadListUnderWaterDetail:TableUpperProps[] = [
{ id: "msrDt", title: "날짜" },
{ id: "realSewageInput", title: "실제 하수유입량\n(m³/일)" },
{ id: "sewageOccur", title: "오수발생량\n(m³/일)" },
{ id: "underWaterInput", title: "지하수 유입량\n(m³/일)" },
];
const underWaterList:UnderWaterProps[] = [
]
const underWaterDetailList:UnderWaterInputModalProps[] = [
{
msrDt : "2024-01",
realSewageInput : 178007,
sewageOccur : 10.5,
underWaterInput : 80.6,
},
{
msrDt : "2024-02",
realSewageInput : 123007,
sewageOccur : 10.7,
underWaterInput : 80.6,
},
{
msrDt : "2024-03",
realSewageInput : 213007,
sewageOccur : 10.1,
underWaterInput : 80.6,
},
{
msrDt : "2024-04",
realSewageInput : 83007,
sewageOccur : 9.57,
underWaterInput : 80.6,
},
{
msrDt : "2024-05",
realSewageInput : 15007,
sewageOccur : 3.57,
underWaterInput : 80.6,
},
{
msrDt : "2024-06",
realSewageInput : 123007,
sewageOccur : '',
underWaterInput : 80.6,
},
{
msrDt : "2024-07",
realSewageInput : 101007,
sewageOccur : 1,
underWaterInput : 80.6,
},
{
msrDt : "2024-08",
realSewageInput : 103807,
sewageOccur : 10.57,
underWaterInput : '',
},
{
msrDt : "2024-09",
realSewageInput : 9007,
sewageOccur : 10.57,
underWaterInput : 80.6,
},
{
msrDt : "2024-10",
realSewageInput : 163007,
sewageOccur : 10.57,
underWaterInput : 80.6,
},
{
msrDt : "2024-11",
realSewageInput : 123007,
sewageOccur : 10.57,
underWaterInput : 80.6,
},
{
msrDt : "2024-12",
realSewageInput : 1007,
sewageOccur : 10.57,
underWaterInput : 80.6,
},
]
/**====================================
* Store - API
====================================*/
// API response types
interface FlowDataItem {
inflAmnt: number;
infoRnDay: number;
msrDt: string;
}
interface ApiResponse {
data: FlowDataItem[];
count: number;
}
const fetchUnderWaterList = async (pageNo: number, pageSize: number, searchYear: string, partCd?: string, nameCd?: string, fcltCpct?: string, operationValue?: string, fcltyNm?: string) => {
const tailStr = partCd ? '/'+ partCd + '/' + nameCd + '/' + fcltCpct + '/' + operationValue + (fcltyNm && fcltyNm !== '' ? '/' + fcltyNm : '') : '';
const url = '/fclt/flow/' + pageNo + '/' + pageSize + '/' + searchYear + tailStr;
const res = await getFetch('fo', url);
return { data: res.data, count: res.count }
/*
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 } */
//return { data: underWaterList, count: 2 };
}
/**====================================
* Store - expaort
====================================*/
export type UnderWaterActions = {
searchUnderWaterList: (pageNo: number, pageSize: number, searchYear: string, part?: string, nameCd?: string, fcltCpct?: string, operationValue?: string, fcltyNm?: string) => void;
}
export type UnderWaterType = {
UnderWaterSearch: {
isInit: boolean;
labelArray:string[];
},
UnderWater : {
isInit: boolean;
upHeadList1: TableUpperProps[];
upHeadList2: TableUpperProps[];
upHeadList3: TableUpperProps[];
underWaterList: UnderWaterProps[]; // Changed from facilityAreaProps to ProcessAreaProps
underWaterCount: number;
excelList: ExcelType[];
},
UnderWaterDetail : {
isInit: boolean;
upHeadListUnderWaterDetail: TableUpperProps[];
gridListUnderWaterDetail: UnderWaterInputModalProps[];
}
}
export const underWaterInitState: UnderWaterType = {
UnderWaterSearch: {
isInit: false,
labelArray: LabelArray,
},
UnderWater : {
isInit : false,
upHeadList1 : upHeadList1,
upHeadList2 : upHeadList2,
upHeadList3 : upHeadList3,
underWaterList : underWaterList,
underWaterCount : 4,
excelList : []
},
UnderWaterDetail : {
isInit: false,
upHeadListUnderWaterDetail: upHeadListUnderWaterDetail,
gridListUnderWaterDetail: underWaterDetailList,
}
}
const dataFormSetting=(item : UnderWaterProps)=> {
DataForm({ type: 'float1', column: 'fctCpc', item: item as unknown as Record<string, unknown> });
DataForm({ type: 'float1', column: 'underWaterInputYear', item: item as unknown as Record<string, unknown>});
DataForm({ type: 'float2', column: 'underWaterInputSummer', item: item as unknown as Record<string, unknown>});
DataForm({ type: 'float2', column: 'underWaterInputWinter', item: item as unknown as Record<string, unknown>});
}
export type UnderWaterStore = UnderWaterType & UnderWaterActions;
export const underWaterReducer:(set:(fn: (state: UnderWaterType) => UnderWaterType) => void)=>UnderWaterActions=(set: (fn: (state: UnderWaterType) => UnderWaterType) => void) => {
return {
searchUnderWaterList: async (pageNo: number, pageSize: number, searchYear: string, part?: string, nameCd?: string, fcltCpct?: string, operationValue?: string, fcltyNm?: string) => {
const res = await fetchUnderWaterList(pageNo, pageSize, searchYear, part, nameCd, fcltCpct, operationValue, fcltyNm);
const data = res.data;
const calData = await Promise.all(data.map(async (item: UnderWaterProps) => {
item.sidoNm = item.lclgvrnmntNm.split(' ')[0]?.toString() || '';
item.sggNm = item.lclgvrnmntNm.split(' ')[1]?.toString() || '';
item.fctCpc = parseFloat(item.fctCpc.toString().replace(/,/g, ''));
const bscFctCd = item.bscFctCd;
const url2 = '/fclt/flow/' + bscFctCd + '/' + searchYear;
const res2 = await getFetch('fo', url2) as ApiResponse;
let sumChungcunDay = 0;
let chungcunSumFlow = 0;
let sumSummerChungcunDay = 0;
let sumSummerChungcunFlow = 0;
let sumWinterChungcunDay = 0;
let sumWinterChungcunFlow = 0;
res2.data.forEach((flowItem: FlowDataItem) => {
// 청천시
if(Number(flowItem.infoRnDay) ===0){
sumChungcunDay += 1;
chungcunSumFlow += Number(flowItem.inflAmnt);
if(flowItem.msrDt.substring(4,6) ==='06' || flowItem.msrDt.substring(4,6) ==='07' || flowItem.msrDt.substring(4,6) ==='08'){
sumSummerChungcunDay += 1;
sumSummerChungcunFlow += Number(flowItem.inflAmnt);
}else if(flowItem.msrDt.includes('01') || flowItem.msrDt.includes('02')){
sumWinterChungcunDay += 1;
sumWinterChungcunFlow += Number(flowItem.inflAmnt);
}
}
});
item.underWaterInputYear = Number(chungcunSumFlow==0?0:Math.round((chungcunSumFlow / sumChungcunDay) * 10) / 10) - Number(item.fctCpc * 0.6 * 0.8);
item.underWaterInputSummer = Number(sumSummerChungcunFlow==0?0:Math.round((sumSummerChungcunFlow / sumSummerChungcunDay) * 10) / 10) - Number(item.fctCpc * 0.6 * 0.8);
item.underWaterInputWinter = Number(sumWinterChungcunFlow==0?0:Math.round((sumWinterChungcunFlow / sumWinterChungcunDay) * 10) / 10) - Number(item.fctCpc * 0.6 * 0.8);
return item;
}));
const excelDownList: ExcelType[] = [];
if(pageSize>5000){
calData.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.daddr,
시설용량: item.fctCpc,
연간지하수유입량: item.underWaterInputYear,
하절기지하수유입량: item.underWaterInputSummer,
동절기지하수유입량: item.underWaterInputWinter,
});
});
}else{
data.forEach((item: UnderWaterProps) => {
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: UnderWaterType) => ({
...state,
UnderWater: pageSize<5000?{
...state.UnderWater,
underWaterList: calData,
underWaterCount: res.count,
}:{
...state.UnderWater,
excelList: excelDownList,
}
}))
},
}
}