319 lines
13 KiB
TypeScript
319 lines
13 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) 메인페이지
|
|
*/
|
|
// 시설별 강수현황
|
|
type FacilityPrecipitationProps = {
|
|
bscFctCd : string,
|
|
sido : string,
|
|
gugun : string,
|
|
bscFctNm : string,
|
|
addr : string,
|
|
fctCpc : number,
|
|
stnKo : string,
|
|
infoRnDay : number,
|
|
rainEffectDay : number,
|
|
totalYearRain : number,
|
|
rvbsn : string,
|
|
lgbsn : string,
|
|
mdmbsn : string,
|
|
rgnNm : string,
|
|
}
|
|
|
|
/*
|
|
* (2) 강수현황 팝업
|
|
*/
|
|
// 강수현황
|
|
export type PrecipitationPropsDetailProps = {
|
|
bscFctCd : string,
|
|
rainDt : string,
|
|
infoRnDay : number,
|
|
rainEffectDay : number,
|
|
rainDay : number
|
|
}
|
|
|
|
export interface ExcelType {
|
|
시설코드: string,
|
|
권역:string|'',
|
|
단위유역:string|'',
|
|
중권역:string|'',
|
|
환경청:string|'',
|
|
시도: string,
|
|
시군구: string,
|
|
시설이름: string,
|
|
주소: string,
|
|
시설용량: number,
|
|
관측소정보 : string,
|
|
강우일 : number,
|
|
강우영향일 : number,
|
|
연간총강수량 : number,
|
|
}
|
|
|
|
/**====================================
|
|
* Store - data
|
|
====================================*/
|
|
|
|
/**
|
|
* (1) 메인페이지
|
|
*/
|
|
// 검색단
|
|
const LabelArray:string[] = ['구분', '시도', '시군구','용량별', '시설명', '시설상태', '조회기간', '권역', '단위유역', '중권역', '환경청별'];
|
|
|
|
// 리스트 헤더
|
|
const upHeadList1:TableUpperProps[] = [
|
|
{ id: "bscFctCd", title: "시설코드", row: 0, rowSpan: 2},
|
|
{ id: "A", title: "행정구역", row: 0, colSpan: 2 },
|
|
{ id: "sido", title: "시도", upName:"upChangeRe", upSequnce:1, row: 1 },
|
|
{ id: "gugun", title: "시군구", upName:"upChangeRe",upSequnce:2, row: 1 },
|
|
{ id: "bscFctNm", title: "시설명", row: 0, rowSpan: 2},
|
|
{ id: "addr", title: "주소", row: 0, rowSpan: 2},
|
|
{ id: "fctCpc", title: "시설용량(m³/일)", row: 0, rowSpan: 2},
|
|
{ id: "stnKo", title: "관측소 정보", row: 0, rowSpan: 2},
|
|
{ id: "infoRnDay", title: "강우일\n(일)", row: 0, rowSpan: 2},
|
|
{ id: "rainEffectDay", title: "강우영향일\n(일)", row: 0, rowSpan: 2},
|
|
{ id: "totalYearRain", title: "연간 총 총강수량\n(mm)", row: 0, rowSpan: 2}
|
|
];
|
|
|
|
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: "addr", title: "주소", row: 0, rowSpan: 2},
|
|
{ id: "fctCpc", title: "시설용량(m³/일)", row: 0, rowSpan: 2},
|
|
{ id: "stnKo", title: "관측소 정보", row: 0, rowSpan: 2},
|
|
{ id: "infoRnDay", title: "강우일\n(일)", row: 0, rowSpan: 2},
|
|
{ id: "rainEffectDay", title: "강우영향일\n(일)", row: 0, rowSpan: 2},
|
|
{ id: "totalYearRain", title: "연간 총 총강수량\n(mm)", row: 0, rowSpan: 2}
|
|
];
|
|
|
|
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: "행정구역", upName:"upChangeRe2", row: 0, colSpan: 2},
|
|
{ id: "sido", title: "시도", upName:"upChangeRe2", upSequnce:1, row: 1},
|
|
{ id: "gugun", title: "시군구", upName:"upChangeRe2",upSequnce:2, row: 1},
|
|
{ id: "bscFctNm", title: "시설명", row: 0, rowSpan: 2},
|
|
{ id: "addr", title: "주소", row: 0, rowSpan: 2},
|
|
{ id: "fctCpc", title: "시설용량(m³/일)", row: 0, rowSpan: 2},
|
|
{ id: "stnKo", title: "관측소 정보", row: 0, rowSpan: 2},
|
|
{ id: "infoRnDay", title: "강우일\n(일)", row: 0, rowSpan: 2},
|
|
{ id: "rainEffectDay", title: "강우영향일\n(일)", row: 0, rowSpan: 2},
|
|
{ id: "totalYearRain", title: "연간 총 총강수량\n(mm)", row: 0, rowSpan: 2}
|
|
];
|
|
|
|
const facilityPrecipitation:FacilityPrecipitationProps[] = [
|
|
]
|
|
|
|
/**
|
|
* 강수현황 상세팝업
|
|
*/
|
|
// 강수현황 (헤더)
|
|
const upHeadListPrecipitationDetail:TableUpperProps[] = [
|
|
{ id: "rainDt", title: "날짜"},
|
|
{ id: "infoRnDay", title: "강수량(mm/일)"},
|
|
{ id: "rainDay", title: "강우일(일)"},
|
|
{ id: "rainEffectDay", title: "강우영향일(일)"}
|
|
]
|
|
// 강수현황 (리스트)
|
|
const gridListPrecipitationDetail:PrecipitationPropsDetailProps[] = [
|
|
]
|
|
|
|
/**====================================
|
|
* Store - api
|
|
====================================*/
|
|
|
|
const fetchFacilityPrecipitationList = async (pageNo: number, pageSize: number, searchYear: string, part?: string, nameCd?: string, fcltCpct?: string, operationValue?: string, fcltyNm?: string) => {
|
|
const tailStr = '/'+pageNo + '/' + pageSize + '/' + searchYear + (part?'/' + part:'' ) + (nameCd?'/' + nameCd:'' ) + (fcltCpct?'/' + fcltCpct:'' ) + (operationValue?'/' + operationValue:'' ) + (fcltyNm && fcltyNm !== '' ? '/' + fcltyNm : '') ;
|
|
console.log('tailStr', tailStr);
|
|
const url = '/fclt/rain' + tailStr;
|
|
const res = await getFetch('fo', url);
|
|
const tmpData:PrecipitationPropsDetailProps[] = [];
|
|
if(res!= null && res.data.length > 0){
|
|
for(let idx=0; idx<res.data.length; idx++){
|
|
for(let idx2=0; idx2<res.data[idx].rainyDayObjList.length; idx2++){
|
|
const bscFctCd = res.data[idx].rainyDayObjList[idx2].bscFctCd;
|
|
const rainDt = res.data[idx].rainyDayObjList[idx2].rainDt;
|
|
const infoRnDay = res.data[idx].rainyDayObjList[idx2].infoRnDay;
|
|
const rainDay = res.data[idx].rainyDayObjList[idx2].infoRnDay>=3?1:0;
|
|
let rainEffectDay = 0;
|
|
if(idx2 < res.data[idx].rainyDayObjList.length-2){
|
|
if(rainDay==1){
|
|
rainEffectDay = 1;
|
|
} else {
|
|
if(idx2 >= 2){
|
|
if(res.data[idx].rainyDayObjList[idx2-1].infoRnDay>=3 || res.data[idx].rainyDayObjList[idx2-2].infoRnDay>=3){
|
|
rainEffectDay = 1;
|
|
}
|
|
}
|
|
}
|
|
} else if(idx2 < res.data[idx].rainyDayObjList.length-1){
|
|
if(rainDay==1 || res.data[idx].rainyDayObjList[idx2+1].infoRnDay>=3){
|
|
rainEffectDay = 1;
|
|
}
|
|
} else {
|
|
rainEffectDay = rainDay;
|
|
}
|
|
|
|
tmpData.push({
|
|
bscFctCd : bscFctCd,
|
|
rainDt : rainDt,
|
|
infoRnDay : infoRnDay,
|
|
rainDay : rainDay,
|
|
rainEffectDay : rainEffectDay
|
|
})
|
|
}
|
|
}
|
|
|
|
res.data.map((item: FacilityPrecipitationProps) => {
|
|
const filteredList = tmpData.filter((gridItem) => {
|
|
return gridItem.bscFctCd === item.bscFctCd;
|
|
});
|
|
|
|
item.rainEffectDay = filteredList.reduce((acc, curr) => acc + curr.rainEffectDay, 0);
|
|
item.totalYearRain = filteredList.reduce((acc, curr) => acc + curr.infoRnDay, 0);
|
|
item.infoRnDay = filteredList.reduce((acc, curr) => acc + curr.rainDay, 0);
|
|
})
|
|
}
|
|
return { data: res.data, count: res.count, detailData: tmpData };
|
|
}
|
|
|
|
/**====================================
|
|
* Store - expaort
|
|
====================================*/
|
|
export type FacilityPrecipitationActions = {
|
|
searchFacilityPrecipitationList: (pageNo: number, pageSize: number, searchYear: string, part?: string, nameCd?: string, fcltCpct?: string, operationValue?: string, fcltyNm?: string) => void;
|
|
}
|
|
|
|
const dataFormSetting=(item : FacilityPrecipitationProps)=> {
|
|
DataForm({ type: 'number', column: 'fctCpc', item: item as unknown as Record<string, unknown> });
|
|
DataForm({ type: 'float1', column: 'totalYearRain', item: item as unknown as Record<string, unknown>});
|
|
};
|
|
|
|
export type FacilityPrecipitationType = {
|
|
FacilityPrecipitationSearch: {
|
|
isInit: boolean;
|
|
labelArray:string[];
|
|
},
|
|
|
|
FacilityPrecipitation : {
|
|
isInit: boolean;
|
|
upHeadList1: TableUpperProps[];
|
|
upHeadList2: TableUpperProps[];
|
|
upHeadList3: TableUpperProps[];
|
|
facilityPrecipitation: FacilityPrecipitationProps[];
|
|
excelList: ExcelType[];
|
|
facilityPrecipitationCount: number;
|
|
isLoading: boolean;
|
|
},
|
|
|
|
PrecipitationDetail : {
|
|
isInit : boolean;
|
|
upHeadListPrecipitationDetail : TableUpperProps[];
|
|
gridListPrecipitationDetail : PrecipitationPropsDetailProps[];
|
|
}
|
|
}
|
|
|
|
export const facilityPrecipitationInitState: FacilityPrecipitationType = {
|
|
FacilityPrecipitationSearch: {
|
|
isInit: false,
|
|
labelArray: LabelArray,
|
|
},
|
|
|
|
FacilityPrecipitation : {
|
|
isInit : false,
|
|
upHeadList1 : upHeadList1,
|
|
upHeadList2 : upHeadList2,
|
|
upHeadList3 : upHeadList3,
|
|
facilityPrecipitation : facilityPrecipitation,
|
|
excelList : [],
|
|
facilityPrecipitationCount : 0,
|
|
isLoading : true,
|
|
},
|
|
|
|
PrecipitationDetail : {
|
|
isInit : false,
|
|
upHeadListPrecipitationDetail : upHeadListPrecipitationDetail,
|
|
gridListPrecipitationDetail : gridListPrecipitationDetail
|
|
}
|
|
}
|
|
|
|
export type FacilityPrecipitationStore = FacilityPrecipitationType & FacilityPrecipitationActions;
|
|
|
|
export const facilityPrecipitationReducer:(set:(fn: (state: FacilityPrecipitationType) => FacilityPrecipitationType) => void)=>FacilityPrecipitationActions=(set: (fn: (state: FacilityPrecipitationType) => FacilityPrecipitationType) => void) => {
|
|
return {
|
|
searchFacilityPrecipitationList: async (pageNo: number, pageSize: number, searchYear: string, part?: string, nameCd?: string, fcltCpct?: string, operationValue?: string, fcltyNm?: string) => {
|
|
set((state: FacilityPrecipitationType) => ({
|
|
...state,
|
|
FacilityPrecipitation: {
|
|
...state.FacilityPrecipitation,
|
|
isLoading: true,
|
|
},
|
|
}));
|
|
|
|
const res = await fetchFacilityPrecipitationList(pageNo, pageSize, searchYear, part, nameCd, fcltCpct, operationValue, fcltyNm);
|
|
const data = res.data;
|
|
const excelDownList: ExcelType[] = [];
|
|
|
|
if(pageSize>5000){
|
|
data.forEach((item: FacilityPrecipitationProps) => {
|
|
dataFormSetting(item)
|
|
item.fctCpc = item.fctCpc ? parseFloat(item.fctCpc.toString().replace(/,/g, '')) : 0;
|
|
item.totalYearRain = item.totalYearRain ? parseFloat(item.totalYearRain.toString().replace(/,/g, '')) : 0;
|
|
excelDownList.push({
|
|
시설코드: item.bscFctCd,
|
|
권역: item.rvbsn,
|
|
단위유역: item.lgbsn,
|
|
중권역: item.mdmbsn,
|
|
환경청: item.rgnNm,
|
|
시도: item.sido,
|
|
시군구: item.gugun,
|
|
시설이름: item.bscFctNm,
|
|
주소: item.addr,
|
|
시설용량: item.fctCpc,
|
|
관측소정보: item.stnKo,
|
|
강우일: item.infoRnDay,
|
|
강우영향일: item.rainEffectDay,
|
|
연간총강수량: item.totalYearRain,
|
|
})
|
|
})
|
|
}else{
|
|
data.forEach((item: FacilityPrecipitationProps) => {
|
|
dataFormSetting(item)
|
|
item.fctCpc = item.fctCpc ? parseFloat(item.fctCpc.toString().replace(/,/g, '')) : 0;
|
|
item.totalYearRain = item.totalYearRain ? parseFloat(item.totalYearRain.toString().replace(/,/g, '')) : 0;
|
|
})
|
|
}
|
|
set((state:FacilityPrecipitationType) => ({
|
|
...state,
|
|
FacilityPrecipitation: pageSize<5000?{
|
|
...state.FacilityPrecipitation,
|
|
facilityPrecipitation: res.data,
|
|
facilityPrecipitationCount: res.count,
|
|
isLoading : false,
|
|
}:{
|
|
...state.FacilityPrecipitation,
|
|
excelList: excelDownList,
|
|
isLoading : false,
|
|
},
|
|
PrecipitationDetail:{
|
|
...state.PrecipitationDetail,
|
|
gridListPrecipitationDetail: res.detailData,
|
|
}
|
|
}))
|
|
}
|
|
}
|
|
} |